summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTristan Knight <admin@snappeh.com>2026-04-24 23:48:23 +0100
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2026-04-24 23:19:16 +0000
commitaedbae4ab64041c389744c417dea6d4d3e86005f (patch)
treeedf552a9bbcb9da7eb7f2a325cba4a78945f2b06
parente5d6d2e769cc28fa7fa3e1d7e08e997282acd082 (diff)
fix(lsp): handle self-mapped methods in supports_method #39383
Problem: The LSP client incorrectly checks for server capabilities when determining support for self-mapped methods (e.g., 'shutdown'), which do not have corresponding capabilities in the server's response. This leads to false negatives when checking if such methods are supported. This was handled correctly for dynamic registrations, but not for static. Methods such as 'shutdown', do not have a related server capability and should be assumed to be supported. Solution: Update the `supports_method` logic to always return true for self-mapped methods. (cherry picked from commit f83d0b9653a8a548093645a9397f9f293b91c127)
-rw-r--r--runtime/lua/vim/lsp/client.lua17
-rw-r--r--test/functional/plugin/lsp_spec.lua4
2 files changed, 17 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
index c027f6df47..957364d019 100644
--- a/runtime/lua/vim/lsp/client.lua
+++ b/runtime/lua/vim/lsp/client.lua
@@ -1204,7 +1204,15 @@ function Client:supports_method(method, bufnr)
bufnr = bufnr.bufnr
end
local required_capability = lsp.protocol._request_name_to_server_capability[method]
- if required_capability and vim.tbl_get(self.server_capabilities, unpack(required_capability)) then
+ local is_self_mapping = required_capability
+ and #required_capability == 1
+ and required_capability[1] == method
+
+ if
+ not is_self_mapping
+ and required_capability
+ and vim.tbl_get(self.server_capabilities, unpack(required_capability))
+ then
return true
end
@@ -1229,9 +1237,10 @@ function Client:supports_method(method, bufnr)
return false
end
- -- 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
+ -- 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.
+ return required_capability == nil or is_self_mapping
end
--- Executes callback fn for all registrations for a given LSP method.
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index cd6629b378..4c04793079 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -998,6 +998,10 @@ describe('LSP', function()
eq(true, client:supports_method('textDocument/hover'))
eq(false, client:supports_method('textDocument/definition'))
+ -- Self-mapped methods do not have a related server capability and should be assumed
+ -- to be supported.
+ eq(true, client:supports_method('shutdown'))
+
-- unknown methods are assumed to be supported.
eq(true, client:supports_method('unknown-method'))
end,