fix(#1731): watcher refreshes node rather than the first node matching absolute path, profile refresh
This commit is contained in:
@@ -111,9 +111,10 @@ function M.fn(node)
|
|||||||
-- synchronous call required so that we may focus the file now
|
-- synchronous call required so that we may focus the file now
|
||||||
node = node.nodes ~= nil and node or node.parent
|
node = node.nodes ~= nil and node or node.parent
|
||||||
if node then
|
if node then
|
||||||
watch.refresh_path(node.absolute_path)
|
watch.refresh_node(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- TODO #1731 #1716 this gets upset by watcher add new file to linked directories above
|
||||||
utils.focus_file(utils.path_remove_trailing(new_file_path))
|
utils.focus_file(utils.path_remove_trailing(new_file_path))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ function Explorer.new(cwd)
|
|||||||
local explorer = setmetatable({
|
local explorer = setmetatable({
|
||||||
absolute_path = cwd,
|
absolute_path = cwd,
|
||||||
nodes = {},
|
nodes = {},
|
||||||
watcher = watch.create_watcher(cwd),
|
|
||||||
open = true,
|
open = true,
|
||||||
}, Explorer)
|
}, Explorer)
|
||||||
|
explorer.watcher = watch.create_watcher(explorer)
|
||||||
explorer:_load(explorer)
|
explorer:_load(explorer)
|
||||||
return explorer
|
return explorer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function M.folder(parent, absolute_path, name)
|
|||||||
local handle = vim.loop.fs_scandir(absolute_path)
|
local handle = vim.loop.fs_scandir(absolute_path)
|
||||||
local has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
local has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
||||||
|
|
||||||
return {
|
local node = {
|
||||||
type = "directory",
|
type = "directory",
|
||||||
absolute_path = absolute_path,
|
absolute_path = absolute_path,
|
||||||
fs_stat = vim.loop.fs_stat(absolute_path),
|
fs_stat = vim.loop.fs_stat(absolute_path),
|
||||||
@@ -20,8 +20,11 @@ function M.folder(parent, absolute_path, name)
|
|||||||
nodes = {},
|
nodes = {},
|
||||||
open = false,
|
open = false,
|
||||||
parent = parent,
|
parent = parent,
|
||||||
watcher = watch.create_watcher(absolute_path),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.watcher = watch.create_watcher(node)
|
||||||
|
|
||||||
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.is_executable(parent, absolute_path, ext)
|
function M.is_executable(parent, absolute_path, ext)
|
||||||
@@ -63,16 +66,18 @@ end
|
|||||||
function M.link(parent, absolute_path, name)
|
function M.link(parent, absolute_path, name)
|
||||||
--- I dont know if this is needed, because in my understanding, there isn't hard links in windows, but just to be sure i changed it.
|
--- I dont know if this is needed, because in my understanding, there isn't hard links in windows, but just to be sure i changed it.
|
||||||
local link_to = vim.loop.fs_realpath(absolute_path)
|
local link_to = vim.loop.fs_realpath(absolute_path)
|
||||||
local open, nodes, has_children, watcher
|
local open, nodes, has_children
|
||||||
if (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory" then
|
|
||||||
|
local is_dir_link = (link_to ~= nil) and vim.loop.fs_stat(link_to).type == "directory"
|
||||||
|
|
||||||
|
if is_dir_link then
|
||||||
local handle = vim.loop.fs_scandir(link_to)
|
local handle = vim.loop.fs_scandir(link_to)
|
||||||
has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
has_children = handle and vim.loop.fs_scandir_next(handle) ~= nil
|
||||||
open = false
|
open = false
|
||||||
nodes = {}
|
nodes = {}
|
||||||
watcher = watch.create_watcher(link_to)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
local node = {
|
||||||
type = "link",
|
type = "link",
|
||||||
absolute_path = absolute_path,
|
absolute_path = absolute_path,
|
||||||
fs_stat = vim.loop.fs_stat(absolute_path),
|
fs_stat = vim.loop.fs_stat(absolute_path),
|
||||||
@@ -83,8 +88,13 @@ function M.link(parent, absolute_path, name)
|
|||||||
nodes = nodes,
|
nodes = nodes,
|
||||||
open = open,
|
open = open,
|
||||||
parent = parent,
|
parent = parent,
|
||||||
watcher = watcher,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_dir_link then
|
||||||
|
node.watcher = watch.create_watcher(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local filters = require "nvim-tree.explorer.filters"
|
|||||||
local sorters = require "nvim-tree.explorer.sorters"
|
local sorters = require "nvim-tree.explorer.sorters"
|
||||||
local live_filter = require "nvim-tree.live-filter"
|
local live_filter = require "nvim-tree.live-filter"
|
||||||
local notify = require "nvim-tree.notify"
|
local notify = require "nvim-tree.notify"
|
||||||
|
local log = require "nvim-tree.log"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ function M.reload(node, status)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ps = log.profile_start("reload %s", cwd)
|
||||||
|
|
||||||
if node.group_next then
|
if node.group_next then
|
||||||
node.nodes = { node.group_next }
|
node.nodes = { node.group_next }
|
||||||
node.group_next = nil
|
node.group_next = nil
|
||||||
@@ -110,11 +113,13 @@ function M.reload(node, status)
|
|||||||
node.group_next = child_folder_only
|
node.group_next = child_folder_only
|
||||||
local ns = M.reload(child_folder_only, status)
|
local ns = M.reload(child_folder_only, status)
|
||||||
node.nodes = ns or {}
|
node.nodes = ns or {}
|
||||||
|
log.profile_end(ps, "reload %s", cwd)
|
||||||
return ns
|
return ns
|
||||||
end
|
end
|
||||||
|
|
||||||
sorters.merge_sort(node.nodes, sorters.node_comparator)
|
sorters.merge_sort(node.nodes, sorters.node_comparator)
|
||||||
live_filter.apply_filter(node)
|
live_filter.apply_filter(node)
|
||||||
|
log.profile_end(ps, "reload %s", cwd)
|
||||||
return node.nodes
|
return node.nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -46,39 +46,57 @@ local function is_folder_ignored(path)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.refresh_path(path)
|
function M.refresh_node(node)
|
||||||
log.line("watcher", "node event executing '%s'", path)
|
if type(node) ~= "table" then
|
||||||
local n = utils.get_node_from_path(path)
|
|
||||||
if not n then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = utils.get_parent_of_group(n)
|
if node.link_to then
|
||||||
|
log.line("watcher", "node event executing refresh '%s' -> '%s'", node.link_to, node.absolute_path)
|
||||||
|
else
|
||||||
|
log.line("watcher", "node event executing refresh '%s'", node.absolute_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
local path = node.absolute_path
|
||||||
|
|
||||||
|
local parent_node = utils.get_parent_of_group(node)
|
||||||
|
|
||||||
local project_root, project = reload_and_get_git_project(path)
|
local project_root, project = reload_and_get_git_project(path)
|
||||||
require("nvim-tree.explorer.reload").reload(node, project)
|
|
||||||
update_parent_statuses(node, project, project_root)
|
require("nvim-tree.explorer.reload").reload(parent_node, project)
|
||||||
|
|
||||||
|
update_parent_statuses(parent_node, project, project_root)
|
||||||
|
|
||||||
require("nvim-tree.renderer").draw()
|
require("nvim-tree.renderer").draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_watcher(absolute_path)
|
function M.create_watcher(node)
|
||||||
if not M.enabled then
|
if not M.enabled or type(node) ~= "table" then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if is_git(absolute_path) or is_folder_ignored(absolute_path) then
|
|
||||||
|
local path
|
||||||
|
if node.type == "link" then
|
||||||
|
path = node.link_to
|
||||||
|
else
|
||||||
|
path = node.absolute_path
|
||||||
|
end
|
||||||
|
|
||||||
|
if is_git(path) or is_folder_ignored(path) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function callback(watcher)
|
local function callback(watcher)
|
||||||
log.line("watcher", "node event scheduled %s", watcher.context)
|
log.line("watcher", "node event scheduled refresh %s", watcher.context)
|
||||||
utils.debounce(watcher.context, M.debounce_delay, function()
|
utils.debounce(watcher.context, M.debounce_delay, function()
|
||||||
M.refresh_path(watcher._path)
|
M.refresh_node(node)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.uid = M.uid + 1
|
M.uid = M.uid + 1
|
||||||
return Watcher:new(absolute_path, nil, callback, {
|
return Watcher:new(path, nil, callback, {
|
||||||
context = "explorer:watch:" .. absolute_path .. ":" .. M.uid,
|
context = "explorer:watch:" .. path .. ":" .. M.uid,
|
||||||
|
node = node,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user