From 97bea3163a3fe50359e7f6ffda747e28974a818a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 13 Dec 2023 12:00:11 +0000 Subject: feat(lsp): more annotations --- runtime/lua/vim/lsp/protocol.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index a7c3914834..b2a92cd1ee 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -891,7 +891,7 @@ end --- Creates a normalized object describing LSP server capabilities. ---@param server_capabilities table Table of capabilities supported by the server ----@return table|nil Normalized table of capabilities +---@return lsp.ServerCapabilities|nil Normalized table of capabilities function protocol.resolve_capabilities(server_capabilities) local TextDocumentSyncKind = protocol.TextDocumentSyncKind local textDocumentSync = server_capabilities.textDocumentSync -- cgit From 3767468b9615b617e252e9e9498e070087fe570f Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Mon, 11 Dec 2023 00:05:24 -0500 Subject: docs(gen_lsp.lua): re-generate vim.lsp._meta.protocol type annotations The purpose of this commit is to make diff clean and easy to read; to see the diff resulted from actual changes in gen_lsp.lua, not from the updated LSP protocol JSON data. Ran: `nvim -l scripts/gen_lsp.lua gen --methods` Based on 3.18.0 (2023-12-23) --- runtime/lua/vim/lsp/protocol.lua | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index b2a92cd1ee..df12c36396 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -934,7 +934,7 @@ end -- Generated by gen_lsp.lua, keep at end of file. --- LSP method names. --- ----@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#metaModel +---@see https://microsoft.github.io/language-server-protocol/specification/#metaModel protocol.Methods = { --- A request to resolve the incoming calls for a given `CallHierarchyItem`. --- @since 3.16.0 @@ -1021,16 +1021,14 @@ protocol.Methods = { --- `filterText`, `insertText`, and `textEdit`, must not be changed during resolve. textDocument_completion = 'textDocument/completion', --- A request to resolve the type definition locations of a symbol at a given text - --- document position. The request's parameter is of type [TextDocumentPositionParams] - --- (#TextDocumentPositionParams) the response is of type {@link Declaration} - --- or a typed array of {@link DeclarationLink} or a Thenable that resolves - --- to such. + --- document position. The request's parameter is of type {@link TextDocumentPositionParams} + --- the response is of type {@link Declaration} or a typed array of {@link DeclarationLink} + --- or a Thenable that resolves to such. textDocument_declaration = 'textDocument/declaration', --- A request to resolve the definition location of a symbol at a given text - --- document position. The request's parameter is of type [TextDocumentPosition] - --- (#TextDocumentPosition) the response is of either type {@link Definition} - --- or a typed array of {@link DefinitionLink} or a Thenable that resolves - --- to such. + --- document position. The request's parameter is of type {@link TextDocumentPosition} + --- the response is of either type {@link Definition} or a typed array of + --- {@link DefinitionLink} or a Thenable that resolves to such. textDocument_definition = 'textDocument/definition', --- The document diagnostic request definition. --- @since 3.17.0 @@ -1064,9 +1062,9 @@ protocol.Methods = { --- that resolves to such. textDocument_documentColor = 'textDocument/documentColor', --- Request to resolve a {@link DocumentHighlight} for a given - --- text document position. The request's parameter is of type [TextDocumentPosition] - --- (#TextDocumentPosition) the request response is of type [DocumentHighlight[]] - --- (#DocumentHighlight) or a Thenable that resolves to such. + --- text document position. The request's parameter is of type {@link TextDocumentPosition} + --- the request response is an array of type {@link DocumentHighlight} + --- or a Thenable that resolves to such. textDocument_documentHighlight = 'textDocument/documentHighlight', --- A request to provide document links textDocument_documentLink = 'textDocument/documentLink', @@ -1080,16 +1078,15 @@ protocol.Methods = { --- response is of type {@link FoldingRangeList} or a Thenable --- that resolves to such. textDocument_foldingRange = 'textDocument/foldingRange', - --- A request to to format a whole document. + --- A request to format a whole document. textDocument_formatting = 'textDocument/formatting', --- Request to request hover information at a given text document position. The request's --- parameter is of type {@link TextDocumentPosition} the response is of --- type {@link Hover} or a Thenable that resolves to such. textDocument_hover = 'textDocument/hover', --- A request to resolve the implementation locations of a symbol at a given text - --- document position. The request's parameter is of type [TextDocumentPositionParams] - --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a - --- Thenable that resolves to such. + --- document position. The request's parameter is of type {@link TextDocumentPositionParams} + --- the response is of type {@link Definition} or a Thenable that resolves to such. textDocument_implementation = 'textDocument/implementation', --- A request to provide inlay hints in a document. The request's parameter is of --- type {@link InlayHintsParams}, the response is of type @@ -1100,6 +1097,7 @@ protocol.Methods = { --- type {@link InlineCompletionParams}, the response is of type --- {@link InlineCompletion InlineCompletion[]} or a Thenable that resolves to such. --- @since 3.18.0 + --- @proposed textDocument_inlineCompletion = 'textDocument/inlineCompletion', --- A request to provide inline values in a document. The request's parameter is of --- type {@link InlineValueParams}, the response is of type @@ -1155,9 +1153,8 @@ protocol.Methods = { textDocument_semanticTokens_range = 'textDocument/semanticTokens/range', textDocument_signatureHelp = 'textDocument/signatureHelp', --- A request to resolve the type definition locations of a symbol at a given text - --- document position. The request's parameter is of type [TextDocumentPositionParams] - --- (#TextDocumentPositionParams) the response is of type {@link Definition} or a - --- Thenable that resolves to such. + --- document position. The request's parameter is of type {@link TextDocumentPositionParams} + --- the response is of type {@link Definition} or a Thenable that resolves to such. textDocument_typeDefinition = 'textDocument/typeDefinition', --- A document will save notification is sent from the client to the server before --- the document is actually saved. @@ -1200,14 +1197,14 @@ protocol.Methods = { --- symbol's location. --- @since 3.17.0 workspaceSymbol_resolve = 'workspaceSymbol/resolve', - --- A request sent from the server to the client to modified certain resources. + --- A request sent from the server to the client to modify certain resources. workspace_applyEdit = 'workspace/applyEdit', --- A request to refresh all code actions --- @since 3.16.0 workspace_codeLens_refresh = 'workspace/codeLens/refresh', --- The 'workspace/configuration' request is sent from the server to the client to fetch a certain --- configuration setting. - --- This pull model replaces the old push model were the client signaled configuration change via an + --- This pull model replaces the old push model where the client signaled configuration change via an --- event. If the server still needs to react to configuration changes (since the server caches the --- result of `workspace/configuration` requests) the server should register for an empty configuration --- change event and empty the cache if such an event is received. @@ -1240,9 +1237,12 @@ protocol.Methods = { --- files were renamed from within the client. --- @since 3.16.0 workspace_didRenameFiles = 'workspace/didRenameFiles', - --- A request send from the client to the server to execute a command. The request might return + --- A request sent from the client to the server to execute a command. The request might return --- a workspace edit which the client will apply to the workspace. workspace_executeCommand = 'workspace/executeCommand', + --- @since 3.18.0 + --- @proposed + workspace_foldingRange_refresh = 'workspace/foldingRange/refresh', --- @since 3.17.0 workspace_inlayHint_refresh = 'workspace/inlayHint/refresh', --- @since 3.17.0 -- cgit From 3734519e3b4ba1bf19ca772104170b0ef776be46 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 2 Jan 2024 15:47:55 +0000 Subject: feat(lua): add noref to deepcopy Problem: Currently `deepcopy` hashes every single tables it copies so it can be reused. For tables of mostly unique items that are non recursive, this hashing is unnecessarily expensive Solution: Port the `noref` argument from Vimscripts `deepcopy()`. The below benchmark demonstrates the results for two extreme cases of tables of different sizes. One table that uses the same table lots of times and one with all unique tables. | test | `noref=false` (ms) | `noref=true` (ms) | | -------------------- | ------------------ | ----------------- | | unique tables (50) | 6.59 | 2.62 | | shared tables (50) | 3.24 | 6.40 | | unique tables (2000) | 23381.48 | 2884.53 | | shared tables (2000) | 3505.54 | 14038.80 | The results are basically the inverse of each other where `noref` is much more performance on tables with unique fields, and `not noref` is more performant on tables that reuse fields. --- runtime/lua/vim/lsp/protocol.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index df12c36396..35eb0305d7 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -314,7 +314,7 @@ local constants = { } for k, v in pairs(constants) do - local tbl = vim.deepcopy(v) + local tbl = vim.deepcopy(v, true) vim.tbl_add_reverse_lookup(tbl) protocol[k] = tbl end -- cgit From cc15ba212c7992c3f3aae8b90962862572b21e83 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sun, 18 Feb 2024 14:52:16 -0800 Subject: refactor(lsp): typings for protocol constants --- runtime/lua/vim/lsp/protocol.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 35eb0305d7..82e8c4a7de 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1,6 +1,6 @@ --- Protocol for the Microsoft Language Server Protocol (mslsp) +--- @diagnostic disable: duplicate-doc-alias -local protocol = {} +-- Protocol for the Microsoft Language Server Protocol (mslsp) --[=[ ---@private @@ -20,7 +20,7 @@ function transform_schema_to_table() end --]=] -local constants = { +local protocol = { --- @enum lsp.DiagnosticSeverity DiagnosticSeverity = { -- Reports an error. @@ -313,7 +313,7 @@ local constants = { }, } -for k, v in pairs(constants) do +for k, v in pairs(protocol) do local tbl = vim.deepcopy(v, true) vim.tbl_add_reverse_lookup(tbl) protocol[k] = tbl @@ -723,7 +723,7 @@ function protocol.make_client_capabilities() codeActionLiteralSupport = { codeActionKind = { valueSet = (function() - local res = vim.tbl_values(constants.CodeActionKind) + local res = vim.tbl_values(protocol.CodeActionKind) table.sort(res) return res end)(), -- cgit From 63f9c2da9aab52fa698fcbfdbc58ffd41794d28a Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Mon, 26 Feb 2024 11:42:51 -0800 Subject: feat(lsp): support completion itemDefaults --- runtime/lua/vim/lsp/protocol.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 82e8c4a7de..fb41311961 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -764,6 +764,14 @@ function protocol.make_client_capabilities() return res end)(), }, + completionList = { + itemDefaults = { + 'editRange', + 'insertTextFormat', + 'insertTextMode', + 'data', + }, + }, -- TODO(tjdevries): Implement this contextSupport = false, -- cgit From d981670bc9acd4cfd7b0768b8bc64390b026bf98 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sun, 25 Feb 2024 12:05:35 -0800 Subject: refactor(lsp): remove outdated comment --- runtime/lua/vim/lsp/protocol.lua | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index fb41311961..4a5ab1a73d 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -2,24 +2,6 @@ -- Protocol for the Microsoft Language Server Protocol (mslsp) ---[=[ ----@private ---- Useful for interfacing with: ---- https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md -function transform_schema_comments() - nvim.command [[silent! '<,'>g/\/\*\*\|\*\/\|^$/d]] - nvim.command [[silent! '<,'>s/^\(\s*\) \* \=\(.*\)/\1--\2/]] -end ----@private -function transform_schema_to_table() - transform_schema_comments() - nvim.command [[silent! '<,'>s/: \S\+//]] - nvim.command [[silent! '<,'>s/export const //]] - nvim.command [[silent! '<,'>s/export namespace \(\S*\)\s*{/protocol.\1 = {/]] - nvim.command [[silent! '<,'>s/namespace \(\S*\)\s*{/protocol.\1 = {/]] -end ---]=] - local protocol = { --- @enum lsp.DiagnosticSeverity DiagnosticSeverity = { -- cgit From 853f647da618d2891e4ac513fb96d3c8a42fa131 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sun, 25 Feb 2024 12:45:39 -0800 Subject: fix(lsp): handle reverse lookup in capabilities --- runtime/lua/vim/lsp/protocol.lua | 52 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 4a5ab1a73d..fa614780c2 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1,5 +1,11 @@ --- @diagnostic disable: duplicate-doc-alias +local function get_value_set(t) + return vim.iter.filter(function(i) + return type(i) == 'number' + end, ipairs(t)) +end + -- Protocol for the Microsoft Language Server Protocol (mslsp) local protocol = { @@ -295,6 +301,7 @@ local protocol = { }, } +-- TODO(mariasolos): Remove this reverse lookup. for k, v in pairs(protocol) do local tbl = vim.deepcopy(v, true) vim.tbl_add_reverse_lookup(tbl) @@ -705,7 +712,10 @@ function protocol.make_client_capabilities() codeActionLiteralSupport = { codeActionKind = { valueSet = (function() - local res = vim.tbl_values(protocol.CodeActionKind) + local res = vim.iter.filter(function(value) + -- Filter out the keys that were added by the reverse lookup. + return value:match('^%l') + end, vim.tbl_values(protocol.CodeActionKind)) table.sort(res) return res end)(), @@ -736,15 +746,7 @@ function protocol.make_client_capabilities() documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText }, }, completionItemKind = { - valueSet = (function() - local res = {} - for k in ipairs(protocol.CompletionItemKind) do - if type(k) == 'number' then - table.insert(res, k) - end - end - return res - end)(), + valueSet = get_value_set(protocol.CompletionItemKind), }, completionList = { itemDefaults = { @@ -794,15 +796,7 @@ function protocol.make_client_capabilities() documentSymbol = { dynamicRegistration = false, symbolKind = { - valueSet = (function() - local res = {} - for k in ipairs(protocol.SymbolKind) do - if type(k) == 'number' then - table.insert(res, k) - end - end - return res - end)(), + valueSet = get_value_set(protocol.SymbolKind), }, hierarchicalDocumentSymbolSupport = true, }, @@ -813,15 +807,7 @@ function protocol.make_client_capabilities() publishDiagnostics = { relatedInformation = true, tagSupport = { - valueSet = (function() - local res = {} - for k in ipairs(protocol.DiagnosticTag) do - if type(k) == 'number' then - table.insert(res, k) - end - end - return res - end)(), + valueSet = get_value_set(protocol.DiagnosticTag), }, dataSupport = true, }, @@ -833,15 +819,7 @@ function protocol.make_client_capabilities() symbol = { dynamicRegistration = false, symbolKind = { - valueSet = (function() - local res = {} - for k in ipairs(protocol.SymbolKind) do - if type(k) == 'number' then - table.insert(res, k) - end - end - return res - end)(), + valueSet = get_value_set(protocol.SymbolKind), }, }, configuration = true, -- cgit From 2c8f36a3b0b6e9d8a8c0d0f9cafff9cbf8bcb520 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 29 Feb 2024 10:21:02 +0100 Subject: fix(lsp): use plain loop for non-list-like table of protocol values Fixup for #27628 Closes #27669 --- runtime/lua/vim/lsp/protocol.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index fa614780c2..7016209372 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1,9 +1,17 @@ --- @diagnostic disable: duplicate-doc-alias +-- TODO(clason) can be simplified after reverse lookup is removed +---@param t table +---@return number[] local function get_value_set(t) - return vim.iter.filter(function(i) - return type(i) == 'number' - end, ipairs(t)) + local result = {} + for _, v in pairs(t) do + if type(v) == 'number' then + table.insert(result, v) + end + end + table.sort(result) + return result end -- Protocol for the Microsoft Language Server Protocol (mslsp) -- cgit From e52c25b7617ac6401b080f76b0e227161dfef230 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sat, 2 Mar 2024 13:11:23 -0800 Subject: feat(lua): deprecate vim.tbl_add_reverse_lookup --- runtime/lua/vim/lsp/protocol.lua | 60 +++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'runtime/lua/vim/lsp/protocol.lua') diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 7016209372..599f02425e 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1,22 +1,19 @@ --- @diagnostic disable: duplicate-doc-alias --- TODO(clason) can be simplified after reverse lookup is removed ----@param t table ----@return number[] -local function get_value_set(t) - local result = {} - for _, v in pairs(t) do - if type(v) == 'number' then - table.insert(result, v) - end +---@param tbl table +local function get_value_set(tbl) + local value_set = {} + for _, v in pairs(tbl) do + table.insert(value_set, v) end - table.sort(result) - return result + table.sort(value_set) + return value_set end -- Protocol for the Microsoft Language Server Protocol (mslsp) +local protocol = {} -local protocol = { +local constants = { --- @enum lsp.DiagnosticSeverity DiagnosticSeverity = { -- Reports an error. @@ -309,11 +306,13 @@ local protocol = { }, } --- TODO(mariasolos): Remove this reverse lookup. -for k, v in pairs(protocol) do - local tbl = vim.deepcopy(v, true) - vim.tbl_add_reverse_lookup(tbl) - protocol[k] = tbl +for k1, v1 in pairs(constants) do + local tbl = vim.deepcopy(v1, true) + for _, k2 in ipairs(vim.tbl_keys(tbl)) do + local v2 = tbl[k2] + tbl[v2] = k2 + end + protocol[k1] = tbl end --[=[ @@ -719,14 +718,7 @@ function protocol.make_client_capabilities() codeActionLiteralSupport = { codeActionKind = { - valueSet = (function() - local res = vim.iter.filter(function(value) - -- Filter out the keys that were added by the reverse lookup. - return value:match('^%l') - end, vim.tbl_values(protocol.CodeActionKind)) - table.sort(res) - return res - end)(), + valueSet = get_value_set(constants.CodeActionKind), }, }, isPreferredSupport = true, @@ -751,10 +743,10 @@ function protocol.make_client_capabilities() commitCharactersSupport = false, preselectSupport = false, deprecatedSupport = false, - documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText }, + documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText }, }, completionItemKind = { - valueSet = get_value_set(protocol.CompletionItemKind), + valueSet = get_value_set(constants.CompletionItemKind), }, completionList = { itemDefaults = { @@ -783,13 +775,13 @@ function protocol.make_client_capabilities() }, hover = { dynamicRegistration = true, - contentFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText }, + contentFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText }, }, signatureHelp = { dynamicRegistration = false, signatureInformation = { activeParameterSupport = true, - documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText }, + documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText }, parameterInformation = { labelOffsetSupport = true, }, @@ -804,7 +796,7 @@ function protocol.make_client_capabilities() documentSymbol = { dynamicRegistration = false, symbolKind = { - valueSet = get_value_set(protocol.SymbolKind), + valueSet = get_value_set(constants.SymbolKind), }, hierarchicalDocumentSymbolSupport = true, }, @@ -815,7 +807,7 @@ function protocol.make_client_capabilities() publishDiagnostics = { relatedInformation = true, tagSupport = { - valueSet = get_value_set(protocol.DiagnosticTag), + valueSet = get_value_set(constants.DiagnosticTag), }, dataSupport = true, }, @@ -827,7 +819,7 @@ function protocol.make_client_capabilities() symbol = { dynamicRegistration = false, symbolKind = { - valueSet = get_value_set(protocol.SymbolKind), + valueSet = get_value_set(constants.SymbolKind), }, }, configuration = true, @@ -867,9 +859,9 @@ end --- Creates a normalized object describing LSP server capabilities. ---@param server_capabilities table Table of capabilities supported by the server ----@return lsp.ServerCapabilities|nil Normalized table of capabilities +---@return lsp.ServerCapabilities|nil : Normalized table of capabilities function protocol.resolve_capabilities(server_capabilities) - local TextDocumentSyncKind = protocol.TextDocumentSyncKind + local TextDocumentSyncKind = protocol.TextDocumentSyncKind ---@type table local textDocumentSync = server_capabilities.textDocumentSync if textDocumentSync == nil then -- Defaults if omitted. -- cgit