diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2022-04-30 02:22:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-30 11:22:30 +0200 |
commit | c618b314c6a266806edf692122b16ba9ff7a8e10 (patch) | |
tree | 8e78db8393fc2a567fd3515c73a60f6041a2a6bb /runtime/lua/vim/lsp | |
parent | df09e03cf74337675751c3240069a26aec75fa3b (diff) | |
download | rneovim-c618b314c6a266806edf692122b16ba9ff7a8e10.tar.gz rneovim-c618b314c6a266806edf692122b16ba9ff7a8e10.tar.bz2 rneovim-c618b314c6a266806edf692122b16ba9ff7a8e10.zip |
chore(lsp): remove capabilities sanitization (#17814)
* feat(lsp)!: remove capabilities sanitization
Users must now access client.server_capabilities which matches the same
structure as the protocol.
https://microsoft.github.io/language-server-protocol/specification
client.resolved_capabilities is no longer used to gate capabilities, and
will be removed in a future release.
BREAKING CHANGE
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 5 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 46 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/rpc.lua | 2 |
4 files changed, 47 insertions, 8 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 00919c6b04..62de8d7321 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -224,7 +224,7 @@ function M.formatting_seq_sync(options, timeout_ms, order) -- loop through the clients and make synchronous formatting requests for _, client in pairs(clients) do - if client.resolved_capabilities.document_formatting then + if vim.tbl_get(client.server_capabilities, "documentFormattingProvider") then local params = util.make_formatting_params(options) local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, vim.api.nvim_get_current_buf()) if result and result.result then @@ -545,8 +545,7 @@ local function on_code_action_results(results, ctx, options) local action = action_tuple[2] if not action.edit and client - and type(client.resolved_capabilities.code_action) == 'table' - and client.resolved_capabilities.code_action.resolveProvider then + and vim.tbl_get(client.server_capabilities, "codeActionProvider", "resolveProvider") then client.request('codeAction/resolve', action, function(err, resolved_action) if err then diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 978e44b6f8..dbe985700e 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -379,7 +379,7 @@ function M.signature_help(_, result, ctx, config) return end local client = vim.lsp.get_client_by_id(ctx.client_id) - local triggers = client.resolved_capabilities.signature_help_trigger_characters + local triggers = vim.tbl_get(client.server_capabilities, "signatureHelpProvider", "triggerCharacters") local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype') local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers) lines = util.trim_empty_lines(lines) diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 2cd728ea36..8f50863360 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1,7 +1,5 @@ -- Protocol for the Microsoft Language Server Protocol (mslsp) -local if_nil = vim.F.if_nil - local protocol = {} --[=[ @@ -777,10 +775,50 @@ function protocol.make_client_capabilities() } end +local if_nil = vim.F.if_nil --- Creates a normalized object describing LSP server capabilities. ---@param server_capabilities table Table of capabilities supported by the server ---@return table Normalized table of capabilities function protocol.resolve_capabilities(server_capabilities) + local TextDocumentSyncKind = protocol.TextDocumentSyncKind + local textDocumentSync = server_capabilities.textDocumentSync + if textDocumentSync == nil then + -- Defaults if omitted. + server_capabilities.textDocumentSync = { + openClose = false, + change = TextDocumentSyncKind.None, + willSave = false, + willSaveWaitUntil = false, + save = { + includeText = false, + } + } + elseif type(textDocumentSync) == 'number' then + -- Backwards compatibility + if not TextDocumentSyncKind[textDocumentSync] then + return nil, "Invalid server TextDocumentSyncKind for textDocumentSync" + end + server_capabilities.textDocumentSync = { + openClose = true, + change = textDocumentSync, + willSave = false, + willSaveWaitUntil = false, + save = { + includeText = false, + } + } + elseif type(textDocumentSync) ~= 'table' then + return nil, string.format("Invalid type for textDocumentSync: %q", type(textDocumentSync)) + end + return server_capabilities +end + +---@private +--- Creates a normalized object describing LSP server capabilities. +-- @deprecated access resolved_capabilities instead +---@param server_capabilities table Table of capabilities supported by the server +---@return table Normalized table of capabilities +function protocol._resolve_capabilities_compat(server_capabilities) local general_properties = {} local text_document_sync_properties do @@ -931,12 +969,14 @@ function protocol.resolve_capabilities(server_capabilities) error("The server sent invalid signatureHelpProvider") end - return vim.tbl_extend("error" + local capabilities = vim.tbl_extend("error" , text_document_sync_properties , signature_help_properties , workspace_properties , general_properties ) + + return capabilities end return protocol diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua index 1ecac50df4..6d0a78fba8 100644 --- a/runtime/lua/vim/lsp/rpc.lua +++ b/runtime/lua/vim/lsp/rpc.lua @@ -385,7 +385,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params) ---@param method (string) The invoked LSP method ---@param params (table) Parameters for the invoked LSP method ---@param callback (function) Callback to invoke - ---@param notify_reply_callback (function) Callback to invoke as soon as a request is no longer pending + ---@param notify_reply_callback (function|nil) Callback to invoke as soon as a request is no longer pending ---@returns (bool, number) `(true, message_id)` if request could be sent, `false` if not local function request(method, params, callback, notify_reply_callback) validate { |