aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua2
-rw-r--r--runtime/lua/vim/lsp/handlers.lua47
-rw-r--r--runtime/lua/vim/lsp/util.lua27
-rw-r--r--runtime/lua/vim/treesitter.lua3
-rw-r--r--runtime/lua/vim/treesitter/health.lua34
5 files changed, 93 insertions, 20 deletions
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 eacbd90077..525ec4ce5b 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -245,9 +245,22 @@ 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)
- util.focusable_float(method, function()
+--- |lsp-handler| for the method "textDocument/hover"
+--- <pre>
+--- vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
+--- vim.lsp.handlers.hover, {
+--- -- Use a sharp border with `FloatBorder` highlights
+--- border = "single"
+--- }
+--- )
+--- </pre>
+---@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 {}
+ local bufnr, winnr = util.focusable_float(method, function()
if not (result and result.contents) then
-- return { 'No information available' }
return
@@ -259,13 +272,17 @@ M['textDocument/hover'] = function(_, method, result)
return
end
local bufnr, winnr = util.fancy_floating_markdown(markdown_lines, {
- pad_left = 1; pad_right = 1;
+ border = config.border
})
util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
return bufnr, winnr
end)
+ return bufnr, winnr
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)
@@ -303,8 +320,21 @@ 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"
+--- <pre>
+--- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
+--- vim.lsp.handlers.signature_help, {
+--- -- Use a sharp border with `FloatBorder` highlights
+--- border = "single"
+--- }
+--- )
+--- </pre>
+---@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 <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp handler
-- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore
if not (result and result.signatures and result.signatures[1]) then
@@ -319,11 +349,14 @@ M['textDocument/signatureHelp'] = function(_, method, result, _, bufnr)
end
local syntax = api.nvim_buf_get_option(bufnr, 'syntax')
local p_bufnr, _ = util.focusable_preview(method, function()
- return lines, util.try_trim_markdown_code_blocks(lines)
+ return lines, util.try_trim_markdown_code_blocks(lines), config
end)
api.nvim_buf_set_option(p_bufnr, 'syntax', syntax)
end
+--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
+M['textDocument/signatureHelp'] = M.signature_help
+
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
M['textDocument/documentHighlight'] = function(_, _, result, _, bufnr, _)
if not result then return end
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index ec1131ae1f..a070cb5306 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -875,6 +875,16 @@ function M.make_floating_popup_options(width, height, opts)
row = row + (opts.offset_y or 0),
style = 'minimal',
width = width,
+ border = opts.border or {
+ {"", "NormalFloat"},
+ {"", "NormalFloat"},
+ {"", "NormalFloat"},
+ {" ", "NormalFloat"},
+ {"", "NormalFloat"},
+ {"", "NormalFloat"},
+ {"", "NormalFloat"},
+ {" ", "NormalFloat"}
+ },
}
end
@@ -981,27 +991,20 @@ function M.focusable_preview(unique_name, fn)
end)
end
---- Trims empty lines from input and pad left and right with spaces
+--- Trims empty lines from input and pad top and bottom with empty lines
---
---@param contents table of lines to trim and pad
---@param opts dictionary with optional fields
---- - pad_left number of columns to pad contents at left (default 1)
---- - pad_right number of columns to pad contents at right (default 1)
--- - pad_top number of lines to pad contents at top (default 0)
--- - pad_bottom number of lines to pad contents at bottom (default 0)
---@return contents table of trimmed and padded lines
-function M._trim_and_pad(contents, opts)
+function M._trim(contents, opts)
validate {
contents = { contents, 't' };
opts = { opts, 't', true };
}
opts = opts or {}
- local left_padding = (" "):rep(opts.pad_left or 1)
- local right_padding = (" "):rep(opts.pad_right or 1)
contents = M.trim_empty_lines(contents)
- for i, line in ipairs(contents) do
- contents[i] = string.format('%s%s%s', left_padding, line:gsub("\r", ""), right_padding)
- end
if opts.pad_top then
for _ = 1, opts.pad_top do
table.insert(contents, 1, "")
@@ -1078,8 +1081,8 @@ function M.fancy_floating_markdown(contents, opts)
end
end
end
- -- Clean up and add padding
- stripped = M._trim_and_pad(stripped, opts)
+ -- Clean up
+ stripped = M._trim(stripped, opts)
-- Compute size of float needed to show (wrapped) lines
opts.wrap_at = opts.wrap_at or (vim.wo["wrap"] and api.nvim_win_get_width(0))
@@ -1235,7 +1238,7 @@ function M.open_floating_preview(contents, syntax, opts)
opts = opts or {}
-- Clean up input: trim empty lines from the end, pad
- contents = M._trim_and_pad(contents, opts)
+ contents = M._trim(contents, opts)
-- Compute size of float needed to show (wrapped) lines
opts.wrap_at = opts.wrap_at or (vim.wo["wrap"] and api.nvim_win_get_width(0))
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index cac0ab864b..f223c7b8c8 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -17,6 +17,9 @@ setmetatable(M, {
if k == "highlighter" then
t[k] = require'vim.treesitter.highlighter'
return t[k]
+ elseif k == "language" then
+ t[k] = require"vim.treesitter.language"
+ return t[k]
end
end
})
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
new file mode 100644
index 0000000000..dd0b11a6c7
--- /dev/null
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -0,0 +1,34 @@
+local M = {}
+local ts = vim.treesitter
+
+function M.list_parsers()
+ return vim.api.nvim_get_runtime_file('parser/*', true)
+end
+
+function M.check_health()
+ local report_info = vim.fn['health#report_info']
+ local report_ok = vim.fn['health#report_ok']
+ local report_error = vim.fn['health#report_error']
+ local parsers = M.list_parsers()
+
+ report_info(string.format("Runtime ABI version : %d", ts.language_version))
+
+ for _, parser in pairs(parsers) do
+ local parsername = vim.fn.fnamemodify(parser, ":t:r")
+
+ local is_loadable, ret = pcall(ts.language.require_language, parsername)
+
+ if not is_loadable then
+ report_error(string.format("Impossible to load parser for %s: %s", parsername, ret))
+ elseif ret then
+ local lang = ts.language.inspect_language(parsername)
+ report_ok(string.format("Loaded parser for %s: ABI version %d",
+ parsername, lang._abi_version))
+ else
+ report_error(string.format("Unable to load parser for %s", parsername))
+ end
+ end
+end
+
+return M
+