aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_watch.lua
diff options
context:
space:
mode:
authorJon Huhn <nojnhuh@users.noreply.github.com>2023-04-17 11:50:05 -0500
committerGitHub <noreply@github.com>2023-04-17 18:50:05 +0200
commit6cc76011ca28ff61f1c2f8de6d895d4c6d0a1ad8 (patch)
treeebe99396340915a3243375d55a75d841113e1b8e /runtime/lua/vim/_watch.lua
parent9e5f9c25d9955f8c0ab7de874cf3a40fc077458b (diff)
downloadrneovim-6cc76011ca28ff61f1c2f8de6d895d4c6d0a1ad8.tar.gz
rneovim-6cc76011ca28ff61f1c2f8de6d895d4c6d0a1ad8.tar.bz2
rneovim-6cc76011ca28ff61f1c2f8de6d895d4c6d0a1ad8.zip
fix(watchfiles): skip Created events when poll starts (#23139)
Diffstat (limited to 'runtime/lua/vim/_watch.lua')
-rw-r--r--runtime/lua/vim/_watch.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua
index dba1522ec8..dbffd726a2 100644
--- a/runtime/lua/vim/_watch.lua
+++ b/runtime/lua/vim/_watch.lua
@@ -88,6 +88,9 @@ local default_poll_interval_ms = 2000
--- be invoked recursively)
--- - children (table|nil)
--- A mapping of directory entry name to its recursive watches
+-- - started (boolean|nil)
+-- Whether or not the watcher has first been initialized. Used
+-- to prevent a flood of Created events on startup.
local function poll_internal(path, opts, callback, watches)
path = vim.fs.normalize(path)
local interval = opts and opts.interval or default_poll_interval_ms
@@ -112,7 +115,9 @@ local function poll_internal(path, opts, callback, watches)
end)
)
assert(not start_err, start_err)
- callback(path, M.FileChangeType.Created)
+ if watches.started then
+ callback(path, M.FileChangeType.Created)
+ end
end
watches.cancel = function()
@@ -132,6 +137,7 @@ local function poll_internal(path, opts, callback, watches)
if not watches.children[name] then
watches.children[name] = {
is_dir = ftype == 'directory',
+ started = watches.started,
}
poll_internal(filepath_join(path, name), opts, callback, watches.children[name])
end
@@ -150,6 +156,8 @@ local function poll_internal(path, opts, callback, watches)
watches.children = newchildren
end
+ watches.started = true
+
return watches.cancel
end