From 853f647da618d2891e4ac513fb96d3c8a42fa131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Sun, 25 Feb 2024 12:45:39 -0800 Subject: [PATCH] fix(lsp): handle reverse lookup in capabilities --- runtime/lua/vim/lsp/protocol.lua | 52 +++++++++----------------------- 1 file changed, 15 insertions(+), 37 deletions(-) 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,