mirror of
https://github.com/neovim/neovim.git
synced 2026-07-16 14:11:28 +00:00
fix(lsp): dynamic registration for off-spec method #39544
Problem: LSP clients previously did not handle dynamic registration for off-spec methods Solution: Update the client logic to assume support for dynamic registration when the method is unknown. Adjust the registration provider fallback and enhance tests to verify correct behaviour for unknown methods and their registration options. This improves compatibility with servers using custom dynamic registrations. AI-assisted: OpenCode
This commit is contained in:
@@ -963,6 +963,10 @@ function Client:_supports_registration(method)
|
||||
end
|
||||
local provider = self:_registration_provider(method)
|
||||
local capability_path = lsp.protocol._provider_to_client_registration[provider]
|
||||
if not capability_path then
|
||||
-- If we don't know about the method, assume the client supports dynamic registration for it.
|
||||
return true
|
||||
end
|
||||
local capability = vim.tbl_get(self.capabilities, unpack(capability_path))
|
||||
return type(capability) == 'table' and capability.dynamicRegistration
|
||||
end
|
||||
@@ -971,7 +975,7 @@ end
|
||||
--- @param method vim.lsp.protocol.Method | vim.lsp.protocol.Method.Registration
|
||||
function Client:_registration_provider(method)
|
||||
local capability_path = lsp.protocol._request_name_to_server_capability[method]
|
||||
return capability_path and capability_path[1]
|
||||
return capability_path and capability_path[1] or method
|
||||
end
|
||||
|
||||
--- @private
|
||||
@@ -1265,6 +1269,10 @@ function Client:supports_method(method, bufnr)
|
||||
return false
|
||||
end
|
||||
|
||||
if required_capability == nil and next(self.registrations[method] or {}) ~= nil then
|
||||
return false
|
||||
end
|
||||
|
||||
-- If we don't know about the method, or if it is a self-mapping(method=required_capability)
|
||||
-- assume that the client supports it.
|
||||
-- This needs to be at the end, so that dynamic_capabilities are checked first.
|
||||
@@ -1295,9 +1303,7 @@ function Client:_provider_foreach(method, fn)
|
||||
local required_capability = lsp.protocol._request_name_to_server_capability[method]
|
||||
local dynamic_regs = self:_get_registrations(provider)
|
||||
local has_subcap = required_capability and #required_capability > 1
|
||||
if not provider then
|
||||
return
|
||||
elseif not dynamic_regs then
|
||||
if not dynamic_regs then
|
||||
-- First check static capabilities
|
||||
local static_reg = vim.tbl_get(self.server_capabilities, provider)
|
||||
if static_reg then
|
||||
|
||||
Reference in New Issue
Block a user