From b87505e11656163ddf0dbbc16b7d224815873964 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 11:24:44 +0000 Subject: refactor(watch): general tidy up - Rename watch.poll to watch.watchdirs - Unify how include and exclude is applied - Improve type hints --- runtime/lua/vim/lsp/_watchfiles.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/_watchfiles.lua') diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index 6ca60b78cd..220052be5f 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -7,7 +7,11 @@ local lpeg = vim.lpeg local M = {} -M._watchfunc = (vim.fn.has('win32') == 1 or vim.fn.has('mac') == 1) and watch.watch or watch.poll +if vim.fn.has('win32') == 1 or vim.fn.has('mac') == 1 then + M._watchfunc = watch.watch +else + M._watchfunc = watch.watchdirs +end ---@type table> client id -> registration id -> cancel function local cancels = vim.defaulttable() @@ -164,3 +168,4 @@ function M.unregister(unreg, ctx) end return M + -- cgit From 816b56f878f0291c00a9018d5057b7b2b00f1891 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 13:05:33 +0000 Subject: fix(lsp): cancel watchers when closing a client --- runtime/lua/vim/lsp/_watchfiles.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'runtime/lua/vim/lsp/_watchfiles.lua') diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index 220052be5f..c66a76feae 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -167,5 +167,14 @@ function M.unregister(unreg, ctx) end end +--- @param client_id integer +function M.cancel(client_id) + for _, reg_cancels in pairs(cancels[client_id]) do + for _, cancel in pairs(reg_cancels) do + cancel() + end + end +end + return M -- cgit From 4ff3217bbd8747d2d44680a825ac29097faf9c4b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 7 Feb 2024 11:28:35 +0000 Subject: feat(lsp): add fswatch watchfunc backend Problem: vim._watch.watchdirs has terrible performance. Solution: - On linux use fswatch as a watcher backend if available. - Add File watcher section to health:vim.lsp. Warn if watchfunc is libuv-poll. --- runtime/lua/vim/lsp/_watchfiles.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp/_watchfiles.lua') diff --git a/runtime/lua/vim/lsp/_watchfiles.lua b/runtime/lua/vim/lsp/_watchfiles.lua index c66a76feae..49328fbe9b 100644 --- a/runtime/lua/vim/lsp/_watchfiles.lua +++ b/runtime/lua/vim/lsp/_watchfiles.lua @@ -9,6 +9,8 @@ local M = {} if vim.fn.has('win32') == 1 or vim.fn.has('mac') == 1 then M._watchfunc = watch.watch +elseif vim.fn.executable('fswatch') == 1 then + M._watchfunc = watch.fswatch else M._watchfunc = watch.watchdirs end @@ -177,4 +179,3 @@ function M.cancel(client_id) end return M - -- cgit