Skip to content

Commit db3294e

Browse files
committed
Don't use file watcher to watch temp file
1 parent fb33d62 commit db3294e

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

lua/live-command/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ local create_autocmds = function()
350350

351351
vim.api.nvim_create_autocmd("CmdlineEnter", {
352352
group = id,
353-
callback = remote.on_cmdline_enter,
353+
callback = function()
354+
remote.sync(chan_id)
355+
end,
354356
})
355357

356358
-- We need to be able to tell when the command was cancelled so the buffer lines are refetched next time.

lua/live-command/remote.lua

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,6 @@ local tmp_file_watcher
55
local uv = vim.loop
66
local dirty = true
77

8-
local watch_tmp_file = function(chan_id)
9-
tmp_file_watcher = uv.new_fs_event()
10-
tmp_file_watcher:start(
11-
tmp_file,
12-
{},
13-
vim.schedule_wrap(function(_, fname, status)
14-
if dirty then
15-
-- Open the current file in the remote Nvim instance
16-
vim.rpcrequest(
17-
chan_id,
18-
"nvim_exec",
19-
-- Store the current sequence number that can be reverted back to
20-
("e! %s | lua vim.g._seq_cur = vim.fn.undotree().seq_cur"):format(tmp_file),
21-
false
22-
)
23-
dirty = false
24-
end
25-
end)
26-
)
27-
end
28-
298
-- Starts a new Nvim instance and connects to it via RPC
309
M.init_rpc = function(on_chan_id)
3110
-- Avoid an infinite loop
@@ -58,33 +37,34 @@ M.init_rpc = function(on_chan_id)
5837
)
5938
assert(handle)
6039

61-
for i = 0, 100 do
40+
for _ = 0, 100 do
6241
local ok, chan_id
6342
ok, chan_id = pcall(vim.fn.sockconnect, "pipe", server_address, { rpc = true })
6443
if ok then
6544
on_chan_id(chan_id)
66-
watch_tmp_file(chan_id)
6745
return
6846
end
6947
vim.wait(10)
7048
end
7149
vim.notify("[live-command.nvim] failed to connect to remote Neovim instance after 1000 ms", vim.log.levels.ERROR)
7250
end
7351

74-
M.shutdown = function()
75-
if tmp_file_watcher then
76-
tmp_file_watcher:stop()
77-
end
78-
end
79-
8052
M.on_text_changed = function()
8153
dirty = true
8254
end
8355

84-
M.on_cmdline_enter = function()
56+
M.sync = function(chan_id)
8557
if dirty then
8658
-- Synchronize buffers by writing out the current buffer contents to a temporary file
87-
vim.cmd("keepalt w! " .. tmp_file)
59+
vim.cmd("silent keepalt w! " .. tmp_file)
60+
vim.rpcrequest(
61+
chan_id,
62+
"nvim_exec",
63+
-- Store the current sequence number that can be reverted back to
64+
("e! %s | lua vim.g._seq_cur = vim.fn.undotree().seq_cur"):format(tmp_file),
65+
false
66+
)
67+
dirty = false
8868
end
8969
end
9070

0 commit comments

Comments
 (0)