(examples/filetree.lua) integrate file-watcher
Some checks failed
NeoVim tests / plenary-tests (push) Failing after 7s
Some checks failed
NeoVim tests / plenary-tests (push) Failing after 7s
This commit is contained in:
parent
e8d19e85c3
commit
d03807afba
@ -44,11 +44,7 @@ end
|
||||
|
||||
--- Normalizes the given path to an absolute path.
|
||||
--- @param path string
|
||||
function H.normalize(path)
|
||||
path = vim.fs.normalize(path)
|
||||
if path:sub(1, 1) ~= '/' then path = vim.fs.joinpath(vim.uv.cwd(), path) end
|
||||
return vim.fs.normalize(path)
|
||||
end
|
||||
function H.normalize(path) return vim.fs.abspath(vim.fs.normalize(path)) end
|
||||
|
||||
--- Computes the relative path from `base` to `path`.
|
||||
--- @param path string
|
||||
@ -155,19 +151,35 @@ local function _render_in_buffer(opts)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- --
|
||||
-- -- TODO: :help watch-file
|
||||
-- --
|
||||
-- local watcher = vim.uv.new_fs_event()
|
||||
-- if watcher ~= nil then
|
||||
-- watcher:start(root_path, { recursive = true }, function(err, fname, status)
|
||||
-- -- TODO: more efficient update:
|
||||
-- s_tree_inf:set(H.get_tree(root_path))
|
||||
--
|
||||
-- -- TODO: proper disposal
|
||||
-- watcher:stop()
|
||||
-- end)
|
||||
-- end
|
||||
-- :help watch-file
|
||||
--
|
||||
local watcher = vim.uv.new_fs_event()
|
||||
if watcher ~= nil then
|
||||
--- @diagnostic disable-next-line: unused-local
|
||||
watcher:start(opts.root_path, { recursive = true }, function(_err, fname, _status)
|
||||
fname = H.normalize(fname)
|
||||
|
||||
local dir_path = vim.fs.dirname(fname)
|
||||
local dir = s_tree_inf:get().path_to_node[dir_path]
|
||||
if not dir then return end
|
||||
|
||||
s_tree_inf:schedule_update(function(tree_inf)
|
||||
H.populate_dir_children(dir, tree_inf.path_to_node)
|
||||
return tree_inf
|
||||
end)
|
||||
end)
|
||||
end
|
||||
vim.api.nvim_create_autocmd('WinClosed', {
|
||||
once = true,
|
||||
pattern = tostring(winnr),
|
||||
callback = function()
|
||||
if watcher == nil then return end
|
||||
|
||||
watcher:stop()
|
||||
watcher = nil
|
||||
end,
|
||||
})
|
||||
|
||||
local controller = {}
|
||||
|
||||
@ -411,8 +423,8 @@ function M.show(opts)
|
||||
callback = M.hide,
|
||||
})
|
||||
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
vim.wo[0][0].number = false
|
||||
vim.wo[0][0].relativenumber = false
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user