aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2026-06-13 17:37:08 -0400
committerGitHub <noreply@github.com>2026-06-13 17:37:08 -0400
commit37239e724e9362c11fcd6c4e0af73bf74ff1c295 (patch)
treea11ad1e7dee3249d71dd9e875f74bf0f3d4cc20e /runtime/lua
parente36659c82f6d51631cf6a88a92ff2b467a078b18 (diff)
parentaeea633deb2cb7c7f20c508310db00b628ad24bd (diff)
downloadrneovim-37239e724e9362c11fcd6c4e0af73bf74ff1c295.tar.gz
rneovim-37239e724e9362c11fcd6c4e0af73bf74ff1c295.tar.bz2
rneovim-37239e724e9362c11fcd6c4e0af73bf74ff1c295.zip
Merge #40220 from justinmk/fixautoread
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/nvim/autoread.lua25
-rw-r--r--runtime/lua/vim/_meta/options.gen.lua13
2 files changed, 23 insertions, 15 deletions
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<integer, uv.uv_timer_t> 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 })
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:
---