From 1d33a817517eb6cd3844b045def38eecb253f3c5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 13 Jun 2026 01:40:05 +0200 Subject: test(autoread): cleanup - Merged into the main "reloads on external change" test. - Reduce duplication. - Wall-clock down from ~4.4s to ~1.4s (dropped 3s debounce test). --- runtime/lua/vim/_meta/options.gen.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/_meta/options.gen.lua b/runtime/lua/vim/_meta/options.gen.lua index 5bc33d2ede..2b8c298972 100644 --- a/runtime/lua/vim/_meta/options.gen.lua +++ b/runtime/lua/vim/_meta/options.gen.lua @@ -168,12 +168,13 @@ vim.o.ai = vim.o.autoindent vim.bo.autoindent = vim.o.autoindent vim.bo.ai = vim.bo.autoindent ---- When a file has been detected to have been changed outside of Vim and ---- it has not been changed inside of Vim, automatically read it again. ---- When the file has been deleted this is not done, so you have the text ---- from before it was deleted. When it appears again then it is read. ---- Nvim uses file system watchers to detect changes in real-time for all ---- loaded buffers; see `timestamp` for details. +--- When a file was changed outside of Nvim, automatically read it again. +--- Skipped if the file was deleted, so you have the text from before it +--- was deleted. If the file appears again then it is read. `timestamp` +--- +--- This is partially driven by OS filewatcher events `uv_fs_event_t`, so +--- even the current buffer may be updated. +--- --- If this option has a local value, use this command to switch back to --- using the global value: --- -- cgit From aeea633deb2cb7c7f20c508310db00b628ad24bd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 13 Jun 2026 11:15:23 +0200 Subject: test(autoread): make "debounce" test actually valid --- runtime/lua/nvim/autoread.lua | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/nvim/autoread.lua b/runtime/lua/nvim/autoread.lua index fc36d84218..229e2f6d26 100644 --- a/runtime/lua/nvim/autoread.lua +++ b/runtime/lua/nvim/autoread.lua @@ -14,7 +14,21 @@ local watchers = {} --- @type table bufnr -> debounce timer local timers = {} -local DEBOUNCE_MS = 100 +local debounce_ms = 100 + +--- @private +--- Test-only: override the debounce window so tests can run faster. +--- @param ms integer +function M._set_debounce(ms) + debounce_ms = ms +end + +--- @private +--- @param bufnr integer +--- @return boolean +function M._is_watching(bufnr) + return watchers[bufnr] ~= nil +end --- Returns the effective 'autoread' value for a buffer. --- 'autoread' is global-local: vim.bo[bufnr].autoread is nil when not set locally, @@ -84,7 +98,7 @@ local function ensure_watcher(bufnr) local cancel = watch.watch(name, {}, function(_, change_type) -- Debounce: restart the same timer on each event, so only the last -- event in a rapid series (e.g. truncate + write) triggers checktime. - timer:start(DEBOUNCE_MS, 0, function() + timer:start(debounce_ms, 0, function() vim.schedule(function() if not vim.api.nvim_buf_is_loaded(bufnr) or not buf_autoread(bufnr) then return @@ -102,13 +116,6 @@ local function ensure_watcher(bufnr) watchers[bufnr] = cancel end ---- @private ---- @param bufnr integer ---- @return boolean -function M._is_watching(bufnr) - return watchers[bufnr] ~= nil -end - function M.enable() local group = vim.api.nvim_create_augroup('nvim.autoread', { clear = true }) -- cgit