1
1
local uv = vim .loop
2
2
3
- local log = require " nvim-tree.log"
4
- local utils = require " nvim-tree.utils"
5
3
local git_utils = require " nvim-tree.git.utils"
6
4
local Runner = require " nvim-tree.git.runner"
7
- local Watcher = require (" nvim-tree.watcher" ).Watcher
8
- local Iterator = require " nvim-tree.iterators.node-iterator"
9
5
10
6
local M = {
11
7
config = {},
@@ -83,40 +79,6 @@ function M.get_project_root(cwd)
83
79
return M .cwd_to_project_root [cwd ]
84
80
end
85
81
86
- local function reload_tree_at (project_root )
87
- if not M .config .git .enable then
88
- return nil
89
- end
90
-
91
- log .line (" watcher" , " git event executing '%s'" , project_root )
92
- local root_node = utils .get_node_from_path (project_root )
93
- if not root_node then
94
- return
95
- end
96
-
97
- M .reload_project (project_root )
98
- local project = M .get_project (project_root )
99
-
100
- local project_files = project .files and project .files or {}
101
- local project_dirs = project .dirs and project .dirs or {}
102
-
103
- Iterator .builder (root_node .nodes )
104
- :hidden ()
105
- :applier (function (node )
106
- local parent_ignored = node .parent .git_status == " !!"
107
- node .git_status = project_dirs [node .absolute_path ] or project_files [node .absolute_path ]
108
- if not node .git_status and parent_ignored then
109
- node .git_status = " !!"
110
- end
111
- end )
112
- :recursor (function (node )
113
- return node .nodes and # node .nodes > 0 and node .nodes
114
- end )
115
- :iterate ()
116
-
117
- require (" nvim-tree.renderer" ).draw ()
118
- end
119
-
120
82
function M .load_project_status (cwd )
121
83
if not M .config .git .enable then
122
84
return {}
@@ -140,26 +102,9 @@ function M.load_project_status(cwd)
140
102
timeout = M .config .git .timeout ,
141
103
}
142
104
143
- local watcher = nil
144
- if M .config .filesystem_watchers .enable then
145
- log .line (" watcher" , " git start" )
146
-
147
- local callback = function (w )
148
- log .line (" watcher" , " git event scheduled '%s'" , w .project_root )
149
- utils .debounce (" git:watcher:" .. w .project_root , M .config .filesystem_watchers .debounce_delay , function ()
150
- reload_tree_at (w .project_root )
151
- end )
152
- end
153
-
154
- watcher = Watcher :new (utils .path_join { project_root , " .git" }, callback , {
155
- project_root = project_root ,
156
- })
157
- end
158
-
159
105
M .projects [project_root ] = {
160
106
files = git_status ,
161
107
dirs = git_utils .file_status_to_dir_status (git_status , project_root ),
162
- watcher = watcher ,
163
108
}
164
109
return M .projects [project_root ]
165
110
end
171
116
172
117
function M .setup (opts )
173
118
M .config .git = opts .git
174
- M .config .filesystem_watchers = opts .filesystem_watchers
175
119
end
176
120
177
121
return M
0 commit comments