-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow bindings for hover actions #395
Labels
enhancement
New feature or request
Comments
Hey 👋 Sure, I could probably add some |
here's what I'm using, I updated it to support Source and Documentation, and also go to definition if it's available instead It makes a great local function open_lsp_browser_link(link_type)
-- First, try to go to definition
local definition_found = false
vim.lsp.buf.definition {
on_list = function()
definition_found = true
vim.lsp.buf.definition()
end,
}
-- We can get here before the on_list function is called which is
-- because I don't know how to run the definition call synchronously, just
-- check this variable again a bit later :shrug:
local function make_hover_request(retry)
-- If definition is found, we're done
if definition_found then return end
-- If no definition, proceed with hover request
local params = vim.lsp.util.make_position_params()
vim.lsp.buf_request(0, "textDocument/hover", params, function(err, result, _, _)
if err or not result or not result.contents then
if not retry then print "No hover information available" end
return
end
local markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
local uri
for _, line in ipairs(markdown_lines) do
if vim.startswith(line, "[" .. link_type .. "]") then
uri = string.match(line, "%[" .. link_type .. "%]%((.+)%)")
if uri then
if uri then
local OS = require "haskell-tools.os"
OS.open_browser(uri)
print("Opening " .. link_type .. " in browser")
end
return
end
end
end
if not retry then
-- If we didn't find the link, try once more
vim.defer_fn(function() make_hover_request(true) end, 100)
else
print("Could not find " .. link_type .. " link")
end
end)
end
make_hover_request(false)
end |
mrcjkb
added a commit
that referenced
this issue
Sep 20, 2024
🤖 I have created a release *beep* *boop* --- ## [4.1.0](4.0.1...v4.1.0) (2024-09-20) ### Features * **lsp:** `<Plug>` mappings for hover actions ([#398](#398)) ([f32ba45](f32ba45)), closes [#395](#395) ### Bug Fixes * **lsp:** disable hover actions if luajit is not available ([24865bf](24865bf)) * nil error when trying to invoke some subcommands ([e7a5bdb](e7a5bdb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature description
Is it possible to add support for automatically executing the hover actions in a hover meny (for example to have a keybinding to open source or documentation in browser)?
(It's definitely possible with send_keys or whatever
KK/Open documentation in browser<CR><CR>
, but hardly elegant)The text was updated successfully, but these errors were encountered: