From 5732aa706c639b3d775573d91d1139f24624629c Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Sat, 25 Feb 2023 03:07:18 -0600 Subject: feat(lsp): implement workspace/didChangeWatchedFiles (#21293) --- test/functional/lua/watch_spec.lua | 195 +++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 test/functional/lua/watch_spec.lua (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua new file mode 100644 index 0000000000..19bb411ce6 --- /dev/null +++ b/test/functional/lua/watch_spec.lua @@ -0,0 +1,195 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local clear = helpers.clear +local is_os = helpers.is_os +local lfs = require('lfs') + +describe('vim._watch', function() + before_each(function() + clear() + end) + + describe('watch', function() + it('detects file changes', function() + local root_dir = helpers.tmpname() + os.remove(root_dir) + lfs.mkdir(root_dir) + + local result = exec_lua( + [[ + local root_dir = ... + + local events = {} + + local expected_events = 0 + local function wait_for_events() + assert(vim.wait(100, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) + end + + local stop = vim._watch.watch(root_dir, {}, function(path, change_type) + table.insert(events, { path = path, change_type = change_type }) + end) + + -- Only BSD seems to need some extra time for the watch to be ready to respond to events + if vim.fn.has('bsd') then + vim.wait(50) + end + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + expected_events = expected_events + 1 + wait_for_events() + + watched:close() + os.remove(watched_path) + + expected_events = expected_events + 1 + wait_for_events() + + stop() + -- No events should come through anymore + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + vim.wait(50) + + watched:close() + os.remove(watched_path) + + vim.wait(50) + + return events + ]], + root_dir + ) + + local expected = { + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir .. '/file', + }, + { + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, + } + + -- kqueue only reports events on the watched path itself, so creating a file within a + -- watched directory results in a "rename" libuv event on the directory. + if is_os('bsd') then + expected = { + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, + } + end + + eq(expected, result) + end) + end) + + describe('poll', function() + it('detects file changes', function() + local root_dir = helpers.tmpname() + os.remove(root_dir) + lfs.mkdir(root_dir) + + local result = exec_lua( + [[ + local root_dir = ... + + local events = {} + + local poll_interval_ms = 1000 + local poll_wait_ms = poll_interval_ms+200 + + local expected_events = 0 + local function wait_for_events() + assert(vim.wait(poll_wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) + end + + local stop = vim._watch.poll(root_dir, { interval = poll_interval_ms }, function(path, change_type) + table.insert(events, { path = path, change_type = change_type }) + end) + + -- polling generates Created events for the existing entries when it starts. + expected_events = expected_events + 1 + wait_for_events() + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + expected_events = expected_events + 2 + wait_for_events() + + watched:close() + os.remove(watched_path) + + expected_events = expected_events + 2 + wait_for_events() + + stop() + -- No events should come through anymore + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + vim.wait(poll_wait_ms) + + watched:close() + os.remove(watched_path) + + return events + ]], + root_dir + ) + + eq(5, #result) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, result[1]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir .. '/file', + }, result[2]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[3]) + -- The file delete and corresponding directory change events do not happen in any + -- particular order, so allow either + if result[4].path == root_dir then + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[4]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, result[5]) + else + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, result[4]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[5]) + end + end) + end) +end) -- cgit From f0f27e9aef7c237dd55fbb5c2cd47c2f42d01742 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Sat, 25 Feb 2023 11:17:28 +0100 Subject: Revert "feat(lsp): implement workspace/didChangeWatchedFiles (#21293)" This reverts commit 5732aa706c639b3d775573d91d1139f24624629c. Causes editor to freeze in projects with many watcher registrations --- test/functional/lua/watch_spec.lua | 195 ------------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 test/functional/lua/watch_spec.lua (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua deleted file mode 100644 index 19bb411ce6..0000000000 --- a/test/functional/lua/watch_spec.lua +++ /dev/null @@ -1,195 +0,0 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local clear = helpers.clear -local is_os = helpers.is_os -local lfs = require('lfs') - -describe('vim._watch', function() - before_each(function() - clear() - end) - - describe('watch', function() - it('detects file changes', function() - local root_dir = helpers.tmpname() - os.remove(root_dir) - lfs.mkdir(root_dir) - - local result = exec_lua( - [[ - local root_dir = ... - - local events = {} - - local expected_events = 0 - local function wait_for_events() - assert(vim.wait(100, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) - end - - local stop = vim._watch.watch(root_dir, {}, function(path, change_type) - table.insert(events, { path = path, change_type = change_type }) - end) - - -- Only BSD seems to need some extra time for the watch to be ready to respond to events - if vim.fn.has('bsd') then - vim.wait(50) - end - - local watched_path = root_dir .. '/file' - local watched, err = io.open(watched_path, 'w') - assert(not err, err) - - expected_events = expected_events + 1 - wait_for_events() - - watched:close() - os.remove(watched_path) - - expected_events = expected_events + 1 - wait_for_events() - - stop() - -- No events should come through anymore - - local watched_path = root_dir .. '/file' - local watched, err = io.open(watched_path, 'w') - assert(not err, err) - - vim.wait(50) - - watched:close() - os.remove(watched_path) - - vim.wait(50) - - return events - ]], - root_dir - ) - - local expected = { - { - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir .. '/file', - }, - { - change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), - path = root_dir .. '/file', - }, - } - - -- kqueue only reports events on the watched path itself, so creating a file within a - -- watched directory results in a "rename" libuv event on the directory. - if is_os('bsd') then - expected = { - { - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir, - }, - { - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir, - }, - } - end - - eq(expected, result) - end) - end) - - describe('poll', function() - it('detects file changes', function() - local root_dir = helpers.tmpname() - os.remove(root_dir) - lfs.mkdir(root_dir) - - local result = exec_lua( - [[ - local root_dir = ... - - local events = {} - - local poll_interval_ms = 1000 - local poll_wait_ms = poll_interval_ms+200 - - local expected_events = 0 - local function wait_for_events() - assert(vim.wait(poll_wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) - end - - local stop = vim._watch.poll(root_dir, { interval = poll_interval_ms }, function(path, change_type) - table.insert(events, { path = path, change_type = change_type }) - end) - - -- polling generates Created events for the existing entries when it starts. - expected_events = expected_events + 1 - wait_for_events() - - local watched_path = root_dir .. '/file' - local watched, err = io.open(watched_path, 'w') - assert(not err, err) - - expected_events = expected_events + 2 - wait_for_events() - - watched:close() - os.remove(watched_path) - - expected_events = expected_events + 2 - wait_for_events() - - stop() - -- No events should come through anymore - - local watched_path = root_dir .. '/file' - local watched, err = io.open(watched_path, 'w') - assert(not err, err) - - vim.wait(poll_wait_ms) - - watched:close() - os.remove(watched_path) - - return events - ]], - root_dir - ) - - eq(5, #result) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir, - }, result[1]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir .. '/file', - }, result[2]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[3]) - -- The file delete and corresponding directory change events do not happen in any - -- particular order, so allow either - if result[4].path == root_dir then - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[4]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), - path = root_dir .. '/file', - }, result[5]) - else - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), - path = root_dir .. '/file', - }, result[4]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[5]) - end - end) - end) -end) -- cgit From ac69ba5fa0081026f2c5e6e29d5788802479b7b9 Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Sun, 5 Mar 2023 00:52:27 -0600 Subject: feat(lsp): implement workspace/didChangeWatchedFiles (#22405) --- test/functional/lua/watch_spec.lua | 195 +++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 test/functional/lua/watch_spec.lua (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua new file mode 100644 index 0000000000..19bb411ce6 --- /dev/null +++ b/test/functional/lua/watch_spec.lua @@ -0,0 +1,195 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local clear = helpers.clear +local is_os = helpers.is_os +local lfs = require('lfs') + +describe('vim._watch', function() + before_each(function() + clear() + end) + + describe('watch', function() + it('detects file changes', function() + local root_dir = helpers.tmpname() + os.remove(root_dir) + lfs.mkdir(root_dir) + + local result = exec_lua( + [[ + local root_dir = ... + + local events = {} + + local expected_events = 0 + local function wait_for_events() + assert(vim.wait(100, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) + end + + local stop = vim._watch.watch(root_dir, {}, function(path, change_type) + table.insert(events, { path = path, change_type = change_type }) + end) + + -- Only BSD seems to need some extra time for the watch to be ready to respond to events + if vim.fn.has('bsd') then + vim.wait(50) + end + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + expected_events = expected_events + 1 + wait_for_events() + + watched:close() + os.remove(watched_path) + + expected_events = expected_events + 1 + wait_for_events() + + stop() + -- No events should come through anymore + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + vim.wait(50) + + watched:close() + os.remove(watched_path) + + vim.wait(50) + + return events + ]], + root_dir + ) + + local expected = { + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir .. '/file', + }, + { + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, + } + + -- kqueue only reports events on the watched path itself, so creating a file within a + -- watched directory results in a "rename" libuv event on the directory. + if is_os('bsd') then + expected = { + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, + { + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, + } + end + + eq(expected, result) + end) + end) + + describe('poll', function() + it('detects file changes', function() + local root_dir = helpers.tmpname() + os.remove(root_dir) + lfs.mkdir(root_dir) + + local result = exec_lua( + [[ + local root_dir = ... + + local events = {} + + local poll_interval_ms = 1000 + local poll_wait_ms = poll_interval_ms+200 + + local expected_events = 0 + local function wait_for_events() + assert(vim.wait(poll_wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) + end + + local stop = vim._watch.poll(root_dir, { interval = poll_interval_ms }, function(path, change_type) + table.insert(events, { path = path, change_type = change_type }) + end) + + -- polling generates Created events for the existing entries when it starts. + expected_events = expected_events + 1 + wait_for_events() + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + expected_events = expected_events + 2 + wait_for_events() + + watched:close() + os.remove(watched_path) + + expected_events = expected_events + 2 + wait_for_events() + + stop() + -- No events should come through anymore + + local watched_path = root_dir .. '/file' + local watched, err = io.open(watched_path, 'w') + assert(not err, err) + + vim.wait(poll_wait_ms) + + watched:close() + os.remove(watched_path) + + return events + ]], + root_dir + ) + + eq(5, #result) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir, + }, result[1]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), + path = root_dir .. '/file', + }, result[2]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[3]) + -- The file delete and corresponding directory change events do not happen in any + -- particular order, so allow either + if result[4].path == root_dir then + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[4]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, result[5]) + else + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), + path = root_dir .. '/file', + }, result[4]) + eq({ + change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), + path = root_dir, + }, result[5]) + end + end) + end) +end) -- cgit From 6a6191174afd7604b82fcc04b9a27b8d51133c9f Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Sun, 26 Mar 2023 04:41:27 -0500 Subject: test: fix flaky watchfiles tests (#22637) --- test/functional/lua/watch_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index 19bb411ce6..554480c2b3 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -126,6 +126,8 @@ describe('vim._watch', function() expected_events = expected_events + 1 wait_for_events() + vim.wait(100) + local watched_path = root_dir .. '/file' local watched, err = io.open(watched_path, 'w') assert(not err, err) -- cgit From 743860de40502227b3f0ed64317eb937d24d4a36 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:59:06 +0200 Subject: test: replace lfs with luv and vim.fs test: replace lfs with luv luv already pretty much does everything lfs does, so this duplication of dependencies isn't needed. --- test/functional/lua/watch_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index 554480c2b3..bbcfd27cde 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -3,7 +3,7 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local clear = helpers.clear local is_os = helpers.is_os -local lfs = require('lfs') +local mkdir = helpers.mkdir describe('vim._watch', function() before_each(function() @@ -14,7 +14,7 @@ describe('vim._watch', function() it('detects file changes', function() local root_dir = helpers.tmpname() os.remove(root_dir) - lfs.mkdir(root_dir) + mkdir(root_dir) local result = exec_lua( [[ @@ -102,7 +102,7 @@ describe('vim._watch', function() it('detects file changes', function() local root_dir = helpers.tmpname() os.remove(root_dir) - lfs.mkdir(root_dir) + mkdir(root_dir) local result = exec_lua( [[ -- cgit From 6cc76011ca28ff61f1c2f8de6d895d4c6d0a1ad8 Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Mon, 17 Apr 2023 11:50:05 -0500 Subject: fix(watchfiles): skip Created events when poll starts (#23139) --- test/functional/lua/watch_spec.lua | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index bbcfd27cde..ad8678c17a 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -122,10 +122,6 @@ describe('vim._watch', function() table.insert(events, { path = path, change_type = change_type }) end) - -- polling generates Created events for the existing entries when it starts. - expected_events = expected_events + 1 - wait_for_events() - vim.wait(100) local watched_path = root_dir .. '/file' @@ -158,39 +154,35 @@ describe('vim._watch', function() root_dir ) - eq(5, #result) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir, - }, result[1]) + eq(4, #result) eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), path = root_dir .. '/file', - }, result[2]) + }, result[1]) eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), path = root_dir, - }, result[3]) + }, result[2]) -- The file delete and corresponding directory change events do not happen in any -- particular order, so allow either - if result[4].path == root_dir then + if result[3].path == root_dir then eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), path = root_dir, - }, result[4]) + }, result[3]) eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), path = root_dir .. '/file', - }, result[5]) + }, result[4]) else eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), path = root_dir .. '/file', - }, result[4]) + }, result[3]) eq({ change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), path = root_dir, - }, result[5]) + }, result[4]) end end) end) -- cgit From 79a5b89d66db74560e751561542064674e980146 Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Wed, 14 Jun 2023 05:40:11 -0500 Subject: perf(lsp): reduce polling handles for workspace/didChangeWatchedFiles (#23500) Co-authored-by: Lewis Russell --- test/functional/lua/watch_spec.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index ad8678c17a..f041f4f1b6 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -107,6 +107,7 @@ describe('vim._watch', function() local result = exec_lua( [[ local root_dir = ... + local lpeg = vim.lpeg local events = {} @@ -118,7 +119,13 @@ describe('vim._watch', function() assert(vim.wait(poll_wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) end - local stop = vim._watch.poll(root_dir, { interval = poll_interval_ms }, function(path, change_type) + local incl = lpeg.P(root_dir) * lpeg.P("/file")^-1 + local excl = lpeg.P(root_dir..'/file.unwatched') + local stop = vim._watch.poll(root_dir, { + interval = poll_interval_ms, + include_pattern = incl, + exclude_pattern = excl, + }, function(path, change_type) table.insert(events, { path = path, change_type = change_type }) end) @@ -127,12 +134,17 @@ describe('vim._watch', function() local watched_path = root_dir .. '/file' local watched, err = io.open(watched_path, 'w') assert(not err, err) + local unwatched_path = root_dir .. '/file.unwatched' + local unwatched, err = io.open(unwatched_path, 'w') + assert(not err, err) expected_events = expected_events + 2 wait_for_events() watched:close() os.remove(watched_path) + unwatched:close() + os.remove(unwatched_path) expected_events = expected_events + 2 wait_for_events() -- cgit From f660b794808ac809ee8cafe82ddd824840bc8e2c Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 16 Jul 2023 14:50:10 +0200 Subject: test(fs): get tmpdir robustly #23021 Problem: helpers.tmpname() may create a local file, depending on circumstances. Solution: Only use helpers.tmpname() for its parent directory (the "temp root"). Use fs_mkdtemp() to actually get a unique name. --- test/functional/lua/watch_spec.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index f041f4f1b6..d802a955fa 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -3,7 +3,6 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local clear = helpers.clear local is_os = helpers.is_os -local mkdir = helpers.mkdir describe('vim._watch', function() before_each(function() @@ -12,9 +11,7 @@ describe('vim._watch', function() describe('watch', function() it('detects file changes', function() - local root_dir = helpers.tmpname() - os.remove(root_dir) - mkdir(root_dir) + local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( [[ @@ -100,9 +97,7 @@ describe('vim._watch', function() describe('poll', function() it('detects file changes', function() - local root_dir = helpers.tmpname() - os.remove(root_dir) - mkdir(root_dir) + local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( [[ -- cgit From 98b22867c33a45aaaf057afbeda8acb0216494e3 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:27:55 +0200 Subject: test(fs): vim.loop was renamed to vim.uv (#24376) test(fs): vim.loop has been replaced with vim.uv --- test/functional/lua/watch_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index d802a955fa..ee31975063 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -11,7 +11,7 @@ describe('vim._watch', function() describe('watch', function() it('detects file changes', function() - local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') + local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( [[ @@ -97,7 +97,7 @@ describe('vim._watch', function() describe('poll', function() it('detects file changes', function() - local root_dir = vim.loop.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') + local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( [[ -- cgit From 4e33ef747ca4b26f67c43e73f3105b174e9ef5b6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 17:45:40 +0100 Subject: test: skip failing test on freebsd The watch_file test started failing on bsd after 3ca967387c49c754561c3b11a574797504d40f38. --- test/functional/lua/watch_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index ee31975063..0542522140 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -3,6 +3,7 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local clear = helpers.clear local is_os = helpers.is_os +local skip = helpers.skip describe('vim._watch', function() before_each(function() @@ -11,6 +12,7 @@ describe('vim._watch', function() describe('watch', function() it('detects file changes', function() + skip(is_os('bsd'), "Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38") local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( -- cgit From de28a0f84c577e264f37cd001b03d640db7d5ef9 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sun, 19 Nov 2023 14:25:32 +0100 Subject: perf(lsp): replace file polling on linux with per dir watcher (#26108) Should help with https://github.com/neovim/neovim/issues/23291 On linux `new_fs_event` doesn't support recursive watching, but we can still use it to watch folders. The downside of this approach is that we may end up sending some false `Deleted` events. For example, if you save a file named `foo` there will be a intermediate `foo~` due to the save mechanism of neovim. The events we get from vim.uv in that case are: - rename: foo~ - rename: foo~ - rename: foo - rename: foo - change: foo - change: foo The mechanism in this PR uses a debounce to reduce this to: - deleted: foo~ - changed: foo `foo~` will be the false positive. I suspect that for the LSP case this is good enough. If not, we may need to follow up on this and keep a table in memory that tracks available files. --- test/functional/lua/watch_spec.lua | 59 ++++++++++++-------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index 0542522140..711719addb 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -108,26 +108,24 @@ describe('vim._watch', function() local events = {} - local poll_interval_ms = 1000 - local poll_wait_ms = poll_interval_ms+200 + local debounce = 100 + local wait_ms = debounce + 200 local expected_events = 0 local function wait_for_events() - assert(vim.wait(poll_wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) + assert(vim.wait(wait_ms, function() return #events == expected_events end), 'Timed out waiting for expected number of events. Current events seen so far: ' .. vim.inspect(events)) end local incl = lpeg.P(root_dir) * lpeg.P("/file")^-1 local excl = lpeg.P(root_dir..'/file.unwatched') local stop = vim._watch.poll(root_dir, { - interval = poll_interval_ms, + debounce = debounce, include_pattern = incl, exclude_pattern = excl, }, function(path, change_type) table.insert(events, { path = path, change_type = change_type }) end) - vim.wait(100) - local watched_path = root_dir .. '/file' local watched, err = io.open(watched_path, 'w') assert(not err, err) @@ -135,7 +133,7 @@ describe('vim._watch', function() local unwatched, err = io.open(unwatched_path, 'w') assert(not err, err) - expected_events = expected_events + 2 + expected_events = expected_events + 1 wait_for_events() watched:close() @@ -143,7 +141,7 @@ describe('vim._watch', function() unwatched:close() os.remove(unwatched_path) - expected_events = expected_events + 2 + expected_events = expected_events + 1 wait_for_events() stop() @@ -153,8 +151,6 @@ describe('vim._watch', function() local watched, err = io.open(watched_path, 'w') assert(not err, err) - vim.wait(poll_wait_ms) - watched:close() os.remove(watched_path) @@ -163,36 +159,19 @@ describe('vim._watch', function() root_dir ) - eq(4, #result) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Created]]), - path = root_dir .. '/file', - }, result[1]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[2]) - -- The file delete and corresponding directory change events do not happen in any - -- particular order, so allow either - if result[3].path == root_dir then - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[3]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), - path = root_dir .. '/file', - }, result[4]) - else - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Deleted]]), - path = root_dir .. '/file', - }, result[3]) - eq({ - change_type = exec_lua([[return vim._watch.FileChangeType.Changed]]), - path = root_dir, - }, result[4]) - end + local created = exec_lua([[return vim._watch.FileChangeType.Created]]) + local deleted = exec_lua([[return vim._watch.FileChangeType.Deleted]]) + local expected = { + { + change_type = created, + path = root_dir .. "/file", + }, + { + change_type = deleted, + path = root_dir .. "/file", + } + } + eq(expected, result) end) end) end) -- cgit From 7ca2d64e8bbfb73f33cf82a2f9c03808bfea3d95 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sun, 19 Nov 2023 18:37:49 +0100 Subject: test: skip failing watch file tests on freebsd (#26110) Quick fix as follow up to https://github.com/neovim/neovim/pull/26108 kqueue only reports events on a watched folder itself, not for files created or deleted within. So the approach the PR took doesn't work on FreeBSD. We'll either need to bring back polling for it, combine watching with manual file tracking, or disable LSP file watching on FreeBSD --- test/functional/lua/watch_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/lua/watch_spec.lua') diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index 711719addb..cdcef08a1a 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -99,6 +99,7 @@ describe('vim._watch', function() describe('poll', function() it('detects file changes', function() + skip(is_os('bsd'), "bsd only reports rename on folders if file inside change") local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( -- cgit