aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2023-11-21 17:46:19 +0100
committerGitHub <noreply@github.com>2023-11-21 17:46:19 +0100
commit7e97c773e3ba78fcddbb2a0b9b0d572c8210c83e (patch)
treed3bf28c5f8010b5ab9d99e7e8a1d633fb24e48b2
parente89071522cb0b6d56fd4e7d7776851e73fb807c3 (diff)
downloadrneovim-7e97c773e3ba78fcddbb2a0b9b0d572c8210c83e.tar.gz
rneovim-7e97c773e3ba78fcddbb2a0b9b0d572c8210c83e.tar.bz2
rneovim-7e97c773e3ba78fcddbb2a0b9b0d572c8210c83e.zip
perf(lsp): use async fs_stat for file watching on linux (#26123)
-rw-r--r--runtime/lua/vim/_watch.lua51
1 files changed, 26 insertions, 25 deletions
diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua
index 7870e1e867..43fce3bf7f 100644
--- a/runtime/lua/vim/_watch.lua
+++ b/runtime/lua/vim/_watch.lua
@@ -132,35 +132,36 @@ local function recurse_watch(path, opts, callback)
end
end
for fullpath, events_list in pairs(filechanges) do
- local stat = uv.fs_stat(fullpath)
- ---@type vim._watch.FileChangeType
- local change_type
- if stat then
- change_type = FileChangeType.Created
- for _, event in ipairs(events_list) do
- if event.change then
- change_type = FileChangeType.Changed
+ uv.fs_stat(fullpath, function(_, stat)
+ ---@type vim._watch.FileChangeType
+ local change_type
+ if stat then
+ change_type = FileChangeType.Created
+ for _, event in ipairs(events_list) do
+ if event.change then
+ change_type = FileChangeType.Changed
+ end
end
- end
- if stat.type == 'directory' then
- local handle = handles[fullpath]
- if not handle then
- handle = assert(uv.new_fs_event())
- handles[fullpath] = handle
- handle:start(fullpath, uvflags, create_on_change(fullpath))
+ if stat.type == 'directory' then
+ local handle = handles[fullpath]
+ if not handle then
+ handle = assert(uv.new_fs_event())
+ handles[fullpath] = handle
+ handle:start(fullpath, uvflags, create_on_change(fullpath))
+ end
end
- end
- else
- local handle = handles[fullpath]
- if handle then
- if not handle:is_closing() then
- handle:close()
+ else
+ local handle = handles[fullpath]
+ if handle then
+ if not handle:is_closing() then
+ handle:close()
+ end
+ handles[fullpath] = nil
end
- handles[fullpath] = nil
+ change_type = FileChangeType.Deleted
end
- change_type = FileChangeType.Deleted
- end
- callback(fullpath, change_type)
+ callback(fullpath, change_type)
+ end)
end
end
local root_handle = assert(uv.new_fs_event())