diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 4e82c46fef..bd7ef9cfdc 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -1147,7 +1147,7 @@ function M.show_line_diagnostics(opts, bufnr, line_nr, client_id) end end - local popup_bufnr, winnr = util.open_floating_preview(lines, 'plaintext') + local popup_bufnr, winnr = util.open_floating_preview(lines, 'plaintext', opts) for i, hi in ipairs(highlights) do local prefixlen, hiname = unpack(hi) -- Start highlight after the prefix diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index f52b76fa05..e0bb267e27 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -245,8 +245,30 @@ M['textDocument/completion'] = function(_, _, result) vim.fn.complete(textMatch+1, matches) end ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover -M['textDocument/hover'] = function(_, method, result) +--- |lsp-handler| for the method "textDocument/hover" +---
+--- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
+--- vim.lsp.handlers.hover, {
+--- -- Use a sharp border with `FloatBorder` highlights
+--- border = {
+--- {"┌", "FloatBorder"},
+--- {"─", "FloatBorder"},
+--- {"┐", "FloatBorder"},
+--- {"│", "FloatBorder"},
+--- {"┘", "FloatBorder"},
+--- {"─", "FloatBorder"},
+--- {"└", "FloatBorder"},
+--- {"│", "FloatBorder"}
+--- }
+--- }
+--- )
+---
+---@param config table Configuration table.
+--- - border: (default=nil)
+--- - Add borders to the floating window
+--- - See |vim.api.nvim_open_win()|
+function M.hover(_, method, result, _, _, config)
+ config = config or {}
util.focusable_float(method, function()
if not (result and result.contents) then
-- return { 'No information available' }
@@ -258,12 +280,17 @@ M['textDocument/hover'] = function(_, method, result)
-- return { 'No information available' }
return
end
- local bufnr, winnr = util.fancy_floating_markdown(markdown_lines)
+ local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, {
+ border = config.border
+ })
util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
return bufnr, winnr
end)
end
+--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
+M['textDocument/hover'] = M.hover
+
--@private
--- Jumps to a location. Used as a handler for multiple LSP methods.
--@param _ (not used)
@@ -301,8 +328,30 @@ M['textDocument/typeDefinition'] = location_handler
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
M['textDocument/implementation'] = location_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
-M['textDocument/signatureHelp'] = function(_, method, result, _, bufnr)
+--- |lsp-handler| for the method "textDocument/signatureHelp"
+---
+--- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
+--- vim.lsp.handlers.signature_help, {
+--- -- Use a sharp border with `FloatBorder` highlights
+--- border = {
+--- {"┌", "FloatBorder"},
+--- {"─", "FloatBorder"},
+--- {"┐", "FloatBorder"},
+--- {"│", "FloatBorder"},
+--- {"┘", "FloatBorder"},
+--- {"─", "FloatBorder"},
+--- {"└", "FloatBorder"},
+--- {"│", "FloatBorder"}
+--- }
+--- }
+--- )
+---
+---@param config table Configuration table.
+--- - border: (default=nil)
+--- - Add borders to the floating window
+--- - See |vim.api.nvim_open_win()|
+function M.signature_help(_, method, result, _, bufnr, config)
+ config = config or {}
-- When use `autocmd CompleteDone