forked from nickjvandyke/opencode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreload.lua
More file actions
28 lines (25 loc) · 820 Bytes
/
reload.lua
File metadata and controls
28 lines (25 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local M = {}
function M.setup()
if not vim.o.autoread then
-- Unfortunately autoread is kinda necessary, for :checktime.
-- Alternatively we could :edit! but that would lose any unsaved changes.
vim.notify(
"Please enable vim.opt.autoread to use opencode.nvim auto_reload, or disable opts.auto_reload",
vim.log.levels.WARN,
{ title = "opencode" }
)
return
end
vim.api.nvim_create_autocmd("User", {
group = vim.api.nvim_create_augroup("OpencodeAutoReload", { clear = true }),
pattern = "OpencodeEvent",
callback = function(args)
if args.data.type == "file.edited" then
-- :checktime checks all buffers - no need to check event's file
vim.cmd("checktime")
end
end,
desc = "Reload buffers edited by opencode",
})
end
return M