commit c2fc867843d95dd0bdd15f91e3113dcf5ed88415
parent c1d21492a66c8bc3cdb390b5f4cb24ad16516853
Author: Justin M. Keyes <justinkz@gmail.com>
Date: Sun, 27 Apr 2025 04:34:05 -0700
Merge #33660 from MariaSolOs/supports-dynamic
Diffstat:
3 files changed, 104 insertions(+), 5 deletions(-)
diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
@@ -840,7 +840,8 @@ end
--- Get options for a method that is registered dynamically.
--- @param method vim.lsp.protocol.Method
function Client:_supports_registration(method)
- local capability = vim.tbl_get(self.capabilities, unpack(vim.split(method, '/')))
+ local capability_path = lsp.protocol._request_name_to_client_capability[method]
+ local capability = vim.tbl_get(self.capabilities, unpack(capability_path))
return type(capability) == 'table' and capability.dynamicRegistration
end
@@ -1069,7 +1070,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
@@ -1094,8 +1094,86 @@ protocol.Methods = {
-- 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
@@ -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 <version> LSP version to use (default: 3.18)
@@ -202,8 +202,28 @@ local function write_to_vim_protocol(protocol)
'',
'-- 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