Skip to content

fix(#1723): find-file refresh containing folder prior to searching #1730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local renderer = require "nvim-tree.renderer"
local core = require "nvim-tree.core"
local reload = require "nvim-tree.explorer.reload"
local Iterator = require "nvim-tree.iterators.node-iterator"

local M = {}
Expand All @@ -28,6 +29,8 @@ function M.fn(fname)

local absolute_paths_searched = {}

reload.refresh_path(vim.fn.fnamemodify(fname, ":h"))

local found = Iterator.builder(core.get_explorer().nodes)
:matcher(function(node)
return node.absolute_path == fname_real or node.link_to == fname_real
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local utils = require "nvim-tree.utils"
local events = require "nvim-tree.events"
local lib = require "nvim-tree.lib"
local core = require "nvim-tree.core"
local watch = require "nvim-tree.explorer.watch"
local reload = require "nvim-tree.explorer.reload"
local notify = require "nvim-tree.notify"

local M = {}
Expand Down Expand Up @@ -111,7 +111,7 @@ function M.fn(node)
-- synchronous call required so that we may focus the file now
node = node.nodes ~= nil and node or node.parent
if node then
watch.refresh_path(node.absolute_path)
reload.refresh_path(node.absolute_path)
end
end
utils.focus_file(utils.path_remove_trailing(new_file_path))
Expand Down
28 changes: 28 additions & 0 deletions lua/nvim-tree/explorer/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local filters = require "nvim-tree.explorer.filters"
local sorters = require "nvim-tree.explorer.sorters"
local live_filter = require "nvim-tree.live-filter"
local notify = require "nvim-tree.notify"
local git = require "nvim-tree.git"

local M = {}

Expand Down Expand Up @@ -118,6 +119,33 @@ function M.reload(node, status)
return node.nodes
end

local function reload_and_get_git_project(path)
local project_root = git.get_project_root(path)
git.reload_project(project_root, path)
return project_root, git.get_project(project_root) or {}
end

local function update_parent_statuses(node, project, root)
while project and node and node.absolute_path ~= root do
require("nvim-tree.explorer.common").update_git_status(node, false, project)
node = node.parent
end
end

function M.refresh_path(path)
local n = utils.get_node_from_path(path)
if not n then
return
end

local node = utils.get_parent_of_group(n)
local project_root, project = reload_and_get_git_project(path)
M.reload(node, project)
update_parent_statuses(node, project, project_root)

require("nvim-tree.renderer").draw()
end

function M.setup(opts)
M.config = opts.renderer
end
Expand Down
32 changes: 2 additions & 30 deletions lua/nvim-tree/explorer/watch.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local git = require "nvim-tree.git"
local Watcher = require("nvim-tree.watcher").Watcher

local M = {}

local function reload_and_get_git_project(path)
local project_root = git.get_project_root(path)
git.reload_project(project_root, path)
return project_root, git.get_project(project_root) or {}
end

local function update_parent_statuses(node, project, root)
while project and node and node.absolute_path ~= root do
require("nvim-tree.explorer.common").update_git_status(node, false, project)
node = node.parent
end
end

local function is_git(path)
return vim.fn.fnamemodify(path, ":t") == ".git"
end
Expand Down Expand Up @@ -46,21 +32,6 @@ local function is_folder_ignored(path)
return false
end

function M.refresh_path(path)
log.line("watcher", "node event executing '%s'", path)
local n = utils.get_node_from_path(path)
if not n then
return
end

local node = utils.get_parent_of_group(n)
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.renderer").draw()
end

function M.create_watcher(absolute_path)
if not M.enabled then
return nil
Expand All @@ -72,7 +43,8 @@ function M.create_watcher(absolute_path)
local function callback(watcher)
log.line("watcher", "node event scheduled %s", watcher.context)
utils.debounce(watcher.context, M.debounce_delay, function()
M.refresh_path(watcher._path)
log.line("watcher", "node event executing '%s'", watcher._path)
require("nvim-tree.explorer.reload").refresh_path(watcher._path)
end)
end

Expand Down