fix(lsp): handle reverse lookup in capabilities

This commit is contained in:
Maria José Solano 2024-02-25 12:45:39 -08:00 committed by Lewis Russell
parent d981670bc9
commit 853f647da6

View File

@ -1,5 +1,11 @@
--- @diagnostic disable: duplicate-doc-alias --- @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) -- Protocol for the Microsoft Language Server Protocol (mslsp)
local protocol = { local protocol = {
@ -295,6 +301,7 @@ local protocol = {
}, },
} }
-- TODO(mariasolos): Remove this reverse lookup.
for k, v in pairs(protocol) do for k, v in pairs(protocol) do
local tbl = vim.deepcopy(v, true) local tbl = vim.deepcopy(v, true)
vim.tbl_add_reverse_lookup(tbl) vim.tbl_add_reverse_lookup(tbl)
@ -705,7 +712,10 @@ function protocol.make_client_capabilities()
codeActionLiteralSupport = { codeActionLiteralSupport = {
codeActionKind = { codeActionKind = {
valueSet = (function() 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) table.sort(res)
return res return res
end)(), end)(),
@ -736,15 +746,7 @@ function protocol.make_client_capabilities()
documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText }, documentationFormat = { protocol.MarkupKind.Markdown, protocol.MarkupKind.PlainText },
}, },
completionItemKind = { completionItemKind = {
valueSet = (function() valueSet = get_value_set(protocol.CompletionItemKind),
local res = {}
for k in ipairs(protocol.CompletionItemKind) do
if type(k) == 'number' then
table.insert(res, k)
end
end
return res
end)(),
}, },
completionList = { completionList = {
itemDefaults = { itemDefaults = {
@ -794,15 +796,7 @@ function protocol.make_client_capabilities()
documentSymbol = { documentSymbol = {
dynamicRegistration = false, dynamicRegistration = false,
symbolKind = { symbolKind = {
valueSet = (function() valueSet = get_value_set(protocol.SymbolKind),
local res = {}
for k in ipairs(protocol.SymbolKind) do
if type(k) == 'number' then
table.insert(res, k)
end
end
return res
end)(),
}, },
hierarchicalDocumentSymbolSupport = true, hierarchicalDocumentSymbolSupport = true,
}, },
@ -813,15 +807,7 @@ function protocol.make_client_capabilities()
publishDiagnostics = { publishDiagnostics = {
relatedInformation = true, relatedInformation = true,
tagSupport = { tagSupport = {
valueSet = (function() valueSet = get_value_set(protocol.DiagnosticTag),
local res = {}
for k in ipairs(protocol.DiagnosticTag) do
if type(k) == 'number' then
table.insert(res, k)
end
end
return res
end)(),
}, },
dataSupport = true, dataSupport = true,
}, },
@ -833,15 +819,7 @@ function protocol.make_client_capabilities()
symbol = { symbol = {
dynamicRegistration = false, dynamicRegistration = false,
symbolKind = { symbolKind = {
valueSet = (function() valueSet = get_value_set(protocol.SymbolKind),
local res = {}
for k in ipairs(protocol.SymbolKind) do
if type(k) == 'number' then
table.insert(res, k)
end
end
return res
end)(),
}, },
}, },
configuration = true, configuration = true,