[Backport release-0.9] fix(lsp): don't register didChangeWatchedFiles when capability not set (#23690)

fix(lsp): don't register didChangeWatchedFiles when capability not set

Some LSP servers (tailwindcss, rome) are known to request registration
for `workspace/didChangeWatchedFiles` even when the corresponding client
capability does not advertise support. This change adds an extra check
in the `client/registerCapability` handler not to start a watch unless
the client capability is set appropriately.

(cherry picked from commit 78510add5b)

Co-authored-by: Jon Huhn <huhnjon@gmail.com>
This commit is contained in:
github-actions[bot]
2023-05-20 08:01:52 +02:00
committed by GitHub
parent d5ac60c093
commit 2be8c29406
2 changed files with 90 additions and 1 deletions

View File

@@ -193,7 +193,12 @@ local to_lsp_change_type = {
function M.register(reg, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
if not client.workspace_folders then
if
-- Ill-behaved servers may not honor the client capability and try to register
-- anyway, so ignore requests when the user has opted out of the feature.
not client.config.capabilities.workspace.didChangeWatchedFiles.dynamicRegistration
or not client.workspace_folders
then
return
end
local watch_regs = {}