aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/_watchfiles.lua
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2023-08-04 07:10:54 +0100
committerGitHub <noreply@github.com>2023-08-04 08:10:54 +0200
commitcc87dda31a5b5637ade7ddcfe5199f2df5fd47df (patch)
treeb89c503ad28d59898c6b14ed1be7ba9bc6e747e7 /runtime/lua/vim/lsp/_watchfiles.lua
parent3d3ec27d51e1608306c9bd78425e3138f293ae69 (diff)
downloadrneovim-cc87dda31a5b5637ade7ddcfe5199f2df5fd47df.tar.gz
rneovim-cc87dda31a5b5637ade7ddcfe5199f2df5fd47df.tar.bz2
rneovim-cc87dda31a5b5637ade7ddcfe5199f2df5fd47df.zip
fix(lsp): do not assume client capability exists in watchfiles check (#24550)
PR #23689 assumes `client.config.capabilities.workspace.didChangeWatchedFiles` exists when checking `dynamicRegistration`, but thats's true only if it was passed to `vim.lsp.start{_client}`. This caused #23806 (still an issue in v0.9.1; needs manual backport), but #23681 fixed it by defaulting `config.capabilities` to `make_client_capabilities` if not passed to `vim.lsp.start{_client}`. However, the bug resurfaces on HEAD if you provide a non-nil `capabilities` to `vim.lsp.start{_client}` with missing fields (e.g: not made via `make_client_capabilities`). From what I see, the spec says such missing fields should be interpreted as an absence of the capability (including those indicated by missing sub-fields): https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities Also, suggest `vim.empty_dict()` for an empty dict in `:h vim.lsp.start_client()` (`{[vim.type_idx]=vim.types.dictionary}` no longer works anyway, probably since the cjson switch).
Diffstat (limited to 'runtime/lua/vim/lsp/_watchfiles.lua')
-rw-r--r--runtime/lua/vim/lsp/_watchfiles.lua15
1 files changed, 9 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua
index c271dc6e14..5dbd4a7199 100644
--- a/runtime/lua/vim/lsp/_watchfiles.lua
+++ b/runtime/lua/vim/lsp/_watchfiles.lua
@@ -121,12 +121,15 @@ M._poll_exclude_pattern = parse('**/.git/{objects,subtree-cache}/**')
function M.register(reg, ctx)
local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
- 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
+ -- 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.
+ local has_capability = vim.tbl_get(
+ client.config.capabilities or {},
+ 'workspace',
+ 'didChangeWatchedFiles',
+ 'dynamicRegistration'
+ )
+ if not has_capability or not client.workspace_folders then
return
end
local watch_regs = {} --- @type table<string,{pattern:userdata,kind:integer}>