fix(lsp): correct capability checks for dynamic registration (#36932)

Refactor capability checks in Client:_supports_registration and
Client:supports_method to properly handle dynamicRegistration and unknown
methods. Now, dynamic capabilities are checked before assuming support for
unknown methods, ensuring more accurate LSP feature detection.
This commit is contained in:
Tristan Knight
2025-12-15 18:23:57 +00:00
committed by GitHub
parent 46220afef8
commit 8165427b4d
2 changed files with 88 additions and 8 deletions

View File

@@ -912,7 +912,8 @@ end
--- @param method vim.lsp.protocol.Method | vim.lsp.protocol.Method.Registration
function Client:_supports_registration(method)
local capability_path = lsp.protocol._request_name_to_client_capability[method] or {}
local capability = vim.tbl_get(self.capabilities, unpack(capability_path))
-- dynamicRegistration is at the second level, even in deeply nested capabilities
local capability = vim.tbl_get(self.capabilities, capability_path[1], capability_path[2])
return type(capability) == 'table' and capability.dynamicRegistration
end
@@ -1161,11 +1162,7 @@ function Client:supports_method(method, bufnr)
bufnr = bufnr.bufnr
end
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
end
if vim.tbl_get(self.server_capabilities, unpack(required_capability)) then
if required_capability and vim.tbl_get(self.server_capabilities, unpack(required_capability)) then
return true
end
@@ -1180,7 +1177,9 @@ function Client:supports_method(method, bufnr)
return self:_get_registration(method, bufnr) ~= nil
end
end
return false
-- if we don't know about the method, assume that the client supports it.
-- This needs to be at the end, so that dynamic_capabilities are checked first
return required_capability == nil
end
--- @private