Skip to content

Commit

Permalink
fix: add custom hover handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuhr committed Feb 19, 2023
1 parent f7efab2 commit f29a9f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/otter/keeper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local extensions = require 'otter.tools.extensions'
local api = vim.api
local ts = vim.treesitter
local parsers = require 'nvim-treesitter.parsers'
local handlers = require'otter.tools.handlers'


M._otters_attached = {}
Expand Down Expand Up @@ -178,7 +179,15 @@ M.send_request = function(main_nr, request, filter)
-- otherwise apply the filter to the one response
response = filter(response)
end
vim.lsp.handlers[request](err, response, method, ...)
if request == 'textDocument/hover' or request == 'textDocument/signatureHelp' then
local default_handler = vim.lsp.handlers[request]
-- can I somehow get the config out of the default_handler
-- if it has been modified with vim.lsp.with(...)?
local config = {}
handlers.hover(err, response, method, config)
else
vim.lsp.handlers[request](err, response, method, ...)
end
end
end
)
Expand Down
22 changes: 22 additions & 0 deletions lua/otter/tools/handlers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local util = require('vim.lsp.util')

local M = {}
function M.hover(_, result, ctx, config)
config = config or {}
config.focus_id = ctx.method
-- don't ignore hover responses from other buffers
if not (result and result.contents) then
vim.notify('No information available')
return
end
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
markdown_lines = util.trim_empty_lines(markdown_lines)
if vim.tbl_isempty(markdown_lines) then
vim.notify('No information available')
return
end
return util.open_floating_preview(markdown_lines, 'markdown', config)
end

return M

0 comments on commit f29a9f3

Please sign in to comment.