From a8ffa6e323d89d88a4582ba10c2cc04814909614 Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Fri, 20 Mar 2026 08:48:19 +0000 Subject: [PATCH] fix(lsp): guard dynamic capability attachment #38382 Problem: The capability attach path for client/registerCapability can initialize a capability even when the capability was only registered in specific buffers Solution: Check supports_method() before attaching capabilities from the dynamic registration handler so unsupported registrations are ignored. AI-assisted: OpenCode --- runtime/lua/vim/lsp/handlers.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index a75079c9ba..f8c1db9607 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -157,7 +157,10 @@ RSC['client/registerCapability'] = function(_, params, ctx) for _, Cap in pairs(vim.lsp._capability.all) do if reg.method == Cap.method then for bufnr in pairs(client.attached_buffers) do - if vim.lsp._capability.is_enabled(Cap.name, { bufnr = bufnr, client_id = client.id }) then + if + client:supports_method(Cap.method, bufnr) + and vim.lsp._capability.is_enabled(Cap.name, { bufnr = bufnr, client_id = client.id }) + then local capability = Cap.active[bufnr] or Cap:new(bufnr) if not capability.client_state[client.id] then capability:on_attach(client.id)