Skip to content

Commit ed05d38

Browse files
authored
fix(lsp): don't monitor files if workspace_folders is nil (neovim#22531)
Fixes: Error SERVER_REQUEST_HANDLER_ERROR: "...di/dev/neovim/neovim/runtime/lua/vim/lsp/_watchfiles.lua :200: bad argument #1 to 'ipairs' (table expected, got nil)" Language servers can be started without root_dir or workspace_folders.
1 parent ac69ba5 commit ed05d38

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

runtime/lua/vim/lsp/_watchfiles.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ end
168168

169169
M._watchfunc = (vim.fn.has('win32') == 1 or vim.fn.has('mac') == 1) and watch.watch or watch.poll
170170

171-
---@type table<number, table<number, function()>> client id -> registration id -> cancel function
171+
---@type table<number, table<number, function[]>> client id -> registration id -> cancel function
172172
local cancels = vim.defaulttable()
173173

174174
local queue_timeout_ms = 100
175-
---@type table<number, uv_timer_t> client id -> libuv timer which will send queued changes at its timeout
175+
---@type table<number, uv.uv_timer_t> client id -> libuv timer which will send queued changes at its timeout
176176
local queue_timers = {}
177177
---@type table<number, lsp.FileEvent[]> client id -> set of queued changes to send in a single LSP notification
178178
local change_queues = {}
@@ -193,6 +193,9 @@ local to_lsp_change_type = {
193193
function M.register(reg, ctx)
194194
local client_id = ctx.client_id
195195
local client = vim.lsp.get_client_by_id(client_id)
196+
if not client.workspace_folders then
197+
return
198+
end
196199
local watch_regs = {}
197200
for _, w in ipairs(reg.registerOptions.watchers) do
198201
local glob_patterns = {}

0 commit comments

Comments
 (0)