Skip to content

Commit 5a83629

Browse files
author
Damien MEHALA
committed
watcher improvements
1 parent d6e10e5 commit 5a83629

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

lua/nvim-tree/explorer/watch.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ local Watcher = require("nvim-tree.watcher").Watcher
44

55
local M = {}
66

7-
local IGNORED_PATHS = {
7+
M.ignore_dirs = {
88
-- disable watchers on kernel filesystems
99
-- which have a lot of unwanted events
1010
"/sys",
1111
"/proc",
1212
"/dev",
1313
}
1414

15-
local function is_folder_ignored(path)
16-
for _, folder in ipairs(IGNORED_PATHS) do
17-
if vim.startswith(path, folder) then
18-
return true
19-
end
20-
end
15+
function M.ignore_dir(path)
16+
table.insert(M.ignore_dirs, path)
17+
end
2118

19+
local function is_folder_ignored(path)
2220
for _, ignore_dir in ipairs(M.ignore_dirs) do
2321
if vim.fn.match(path, ignore_dir) ~= -1 then
2422
return true
@@ -69,7 +67,7 @@ end
6967
function M.setup(opts)
7068
M.enabled = opts.filesystem_watchers.enable
7169
M.debounce_delay = opts.filesystem_watchers.debounce_delay
72-
M.ignore_dirs = opts.filesystem_watchers.ignore_dirs
70+
M.ignore_dirs = vim.tbl_extend("force", M.ignore_dirs, opts.filesystem_watchers.ignore_dirs)
7371
M.uid = 0
7472
end
7573

lua/nvim-tree/git/init.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local log = require "nvim-tree.log"
22
local utils = require "nvim-tree.utils"
33
local git_utils = require "nvim-tree.git.utils"
44
local Runner = require "nvim-tree.git.runner"
5+
local Watch = require "nvim-tree.explorer.watch"
56
local Watcher = require("nvim-tree.watcher").Watcher
67
local Iterator = require "nvim-tree.iterators.node-iterator"
78
local explorer_node = require "nvim-tree.explorer.node"
@@ -143,12 +144,13 @@ function M.load_project_status(cwd)
143144
timeout = M.config.git.timeout,
144145
}
145146

146-
local git_directory = git_utils.get_git_directory(project_root)
147-
148147
local watcher = nil
148+
149149
if M.config.filesystem_watchers.enable then
150150
log.line("watcher", "git start")
151151

152+
local git_directory = git_utils.get_git_directory(project_root)
153+
152154
if git_directory == nil then
153155
log.line("watcher", "could not found the location of .git folder")
154156
else
@@ -162,9 +164,10 @@ function M.load_project_status(cwd)
162164
end)
163165
end
164166

165-
-- Add $GIT_DIR to the list of directory to ignore
166-
local base_gitdir = utils.path_basename(git_directory)
167-
table.insert(M.config.filesystem_watchers.ignore_dirs, base_gitdir)
167+
-- Add GIT_DIR to the list of directory to ignore
168+
-- local base_gitdir = utils.path_basename(git_directory)
169+
-- Watch.ignore_dir(base_gitdir)
170+
Watch.ignore_dir(git_directory)
168171

169172
watcher = Watcher:new(git_directory, WATCHED_FILES, callback, {
170173
project_root = project_root,

0 commit comments

Comments
 (0)