From 66339e06412daf95431452ff731e61462c25c0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maria=20Jos=C3=A9=20Solano?= Date: Sat, 26 Apr 2025 18:24:39 -0700 Subject: [PATCH] feat(lsp): generate method to client capability map --- runtime/lua/vim/lsp/client.lua | 2 +- runtime/lua/vim/lsp/protocol.lua | 80 +++++++++++++++++++++++++++++++- src/gen/gen_lsp.lua | 24 +++++++++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index d2f9395b85..6764718d22 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -1069,7 +1069,7 @@ function Client:supports_method(method, bufnr) --- @diagnostic disable-next-line:no-unknown bufnr = bufnr.bufnr end - local required_capability = lsp.protocol._request_name_to_capability[method] + local required_capability = lsp.protocol._request_name_to_server_capability[method] -- if we don't know about the method, assume that the client supports it. if not required_capability then return true diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 64f09d2037..50730b2971 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -1092,10 +1092,88 @@ protocol.Methods = { workspace_workspaceFolders = 'workspace/workspaceFolders', } +-- stylua: ignore start +-- Generated by gen_lsp.lua, keep at end of file. +--- Maps method names to the required client capability +protocol._request_name_to_client_capability = { + ['codeAction/resolve'] = { 'textDocument', 'codeAction', 'resolveSupport' }, + ['codeLens/resolve'] = { 'textDocument', 'codeLens', 'resolveSupport' }, + ['completionItem/resolve'] = { 'textDocument', 'completion', 'completionItem', 'resolveSupport' }, + ['documentLink/resolve'] = { 'textDocument', 'documentLink' }, + ['inlayHint/resolve'] = { 'textDocument', 'inlayHint', 'resolveSupport' }, + ['textDocument/codeAction'] = { 'textDocument', 'codeAction' }, + ['textDocument/codeLens'] = { 'textDocument', 'codeLens' }, + ['textDocument/completion'] = { 'textDocument', 'completion' }, + ['textDocument/declaration'] = { 'textDocument', 'declaration' }, + ['textDocument/definition'] = { 'textDocument', 'definition' }, + ['textDocument/diagnostic'] = { 'textDocument', 'diagnostic' }, + ['textDocument/didChange'] = { 'textDocument', 'synchronization' }, + ['textDocument/didClose'] = { 'textDocument', 'synchronization' }, + ['textDocument/didOpen'] = { 'textDocument', 'synchronization' }, + ['textDocument/didSave'] = { 'textDocument', 'synchronization', 'didSave' }, + ['textDocument/documentColor'] = { 'textDocument', 'colorProvider' }, + ['textDocument/documentHighlight'] = { 'textDocument', 'documentHighlight' }, + ['textDocument/documentLink'] = { 'textDocument', 'documentLink' }, + ['textDocument/documentSymbol'] = { 'textDocument', 'documentSymbol' }, + ['textDocument/foldingRange'] = { 'textDocument', 'foldingRange' }, + ['textDocument/formatting'] = { 'textDocument', 'formatting' }, + ['textDocument/hover'] = { 'textDocument', 'hover' }, + ['textDocument/implementation'] = { 'textDocument', 'implementation' }, + ['textDocument/inlayHint'] = { 'textDocument', 'inlayHint' }, + ['textDocument/inlineCompletion'] = { 'textDocument', 'inlineCompletion' }, + ['textDocument/inlineValue'] = { 'textDocument', 'inlineValue' }, + ['textDocument/linkedEditingRange'] = { 'textDocument', 'linkedEditingRange' }, + ['textDocument/moniker'] = { 'textDocument', 'moniker' }, + ['textDocument/onTypeFormatting'] = { 'textDocument', 'onTypeFormatting' }, + ['textDocument/prepareCallHierarchy'] = { 'textDocument', 'callHierarchy' }, + ['textDocument/prepareRename'] = { 'textDocument', 'rename', 'prepareSupport' }, + ['textDocument/prepareTypeHierarchy'] = { 'textDocument', 'typeHierarchy' }, + ['textDocument/publishDiagnostics'] = { 'textDocument', 'publishDiagnostics' }, + ['textDocument/rangeFormatting'] = { 'textDocument', 'rangeFormatting' }, + ['textDocument/rangesFormatting'] = { 'textDocument', 'rangeFormatting', 'rangesSupport' }, + ['textDocument/references'] = { 'textDocument', 'references' }, + ['textDocument/rename'] = { 'textDocument', 'rename' }, + ['textDocument/selectionRange'] = { 'textDocument', 'selectionRange' }, + ['textDocument/semanticTokens/full'] = { 'textDocument', 'semanticTokens' }, + ['textDocument/semanticTokens/full/delta'] = { 'textDocument', 'semanticTokens', 'requests', 'full', 'delta' }, + ['textDocument/semanticTokens/range'] = { 'textDocument', 'semanticTokens', 'requests', 'range' }, + ['textDocument/signatureHelp'] = { 'textDocument', 'signatureHelp' }, + ['textDocument/typeDefinition'] = { 'textDocument', 'typeDefinition' }, + ['textDocument/willSave'] = { 'textDocument', 'synchronization', 'willSave' }, + ['textDocument/willSaveWaitUntil'] = { 'textDocument', 'synchronization', 'willSaveWaitUntil' }, + ['window/showDocument'] = { 'window', 'showDocument', 'support' }, + ['window/showMessage'] = { 'window', 'showMessage' }, + ['window/showMessageRequest'] = { 'window', 'showMessage' }, + ['window/workDoneProgress/create'] = { 'window', 'workDoneProgress' }, + ['workspaceSymbol/resolve'] = { 'workspace', 'symbol', 'resolveSupport' }, + ['workspace/applyEdit'] = { 'workspace', 'applyEdit' }, + ['workspace/codeLens/refresh'] = { 'workspace', 'codeLens' }, + ['workspace/configuration'] = { 'workspace', 'configuration' }, + ['workspace/diagnostic'] = { 'workspace', 'diagnostics' }, + ['workspace/diagnostic/refresh'] = { 'workspace', 'diagnostics', 'refreshSupport' }, + ['workspace/didChangeConfiguration'] = { 'workspace', 'didChangeConfiguration' }, + ['workspace/didChangeWatchedFiles'] = { 'workspace', 'didChangeWatchedFiles' }, + ['workspace/didCreateFiles'] = { 'workspace', 'fileOperations', 'didCreate' }, + ['workspace/didDeleteFiles'] = { 'workspace', 'fileOperations', 'didDelete' }, + ['workspace/didRenameFiles'] = { 'workspace', 'fileOperations', 'didRename' }, + ['workspace/executeCommand'] = { 'workspace', 'executeCommand' }, + ['workspace/foldingRange/refresh'] = { 'workspace', 'foldingRange', 'refreshSupport' }, + ['workspace/inlayHint/refresh'] = { 'workspace', 'inlayHint', 'refreshSupport' }, + ['workspace/inlineValue/refresh'] = { 'workspace', 'inlineValue', 'refreshSupport' }, + ['workspace/semanticTokens/refresh'] = { 'workspace', 'semanticTokens', 'refreshSupport' }, + ['workspace/symbol'] = { 'workspace', 'symbol' }, + ['workspace/textDocumentContent'] = { 'workspace', 'textDocumentContent' }, + ['workspace/willCreateFiles'] = { 'workspace', 'fileOperations', 'willCreate' }, + ['workspace/willDeleteFiles'] = { 'workspace', 'fileOperations', 'willDelete' }, + ['workspace/willRenameFiles'] = { 'workspace', 'fileOperations', 'willRename' }, + ['workspace/workspaceFolders'] = { 'workspace', 'workspaceFolders' }, +} +-- stylua: ignore end + -- stylua: ignore start -- Generated by gen_lsp.lua, keep at end of file. --- Maps method names to the required server capability -protocol._request_name_to_capability = { +protocol._request_name_to_server_capability = { ['codeAction/resolve'] = { 'codeActionProvider', 'resolveProvider' }, ['codeLens/resolve'] = { 'codeLensProvider', 'resolveProvider' }, ['completionItem/resolve'] = { 'completionProvider', 'resolveProvider' }, diff --git a/src/gen/gen_lsp.lua b/src/gen/gen_lsp.lua index f23649c344..9d82a7a7cc 100755 --- a/src/gen/gen_lsp.lua +++ b/src/gen/gen_lsp.lua @@ -7,7 +7,7 @@ Generates lua-ls annotations for lsp. Also updates types in runtime/lua/vim/lsp/protocol.lua Usage: - src/gen/gen_lsp.lua [options] + nvim -l src/gen/gen_lsp.lua [options] Options: --version LSP version to use (default: 3.18) @@ -198,12 +198,32 @@ local function write_to_vim_protocol(protocol) end do -- capabilities + vim.list_extend(output, { + '', + '-- stylua: ignore start', + '-- Generated by gen_lsp.lua, keep at end of file.', + '--- Maps method names to the required client capability', + 'protocol._request_name_to_client_capability = {', + }) + + for _, item in ipairs(all) do + if item.clientCapability then + output[#output + 1] = (" ['%s'] = { %s },"):format( + item.method, + "'" .. item.clientCapability:gsub('%.', "', '") .. "'" + ) + end + end + + output[#output + 1] = '}' + output[#output + 1] = '-- stylua: ignore end' + vim.list_extend(output, { '', '-- stylua: ignore start', '-- Generated by gen_lsp.lua, keep at end of file.', '--- Maps method names to the required server capability', - 'protocol._request_name_to_capability = {', + 'protocol._request_name_to_server_capability = {', }) for _, item in ipairs(all) do