@@ -202,11 +202,14 @@ local function setup_autocommands(opts)
202
202
end ,
203
203
})
204
204
205
- local has_watchers = opts .filesystem_watchers .enable
206
-
207
- if opts .auto_reload_on_write and not has_watchers then
208
- create_nvim_tree_autocmd (" BufWritePost" , { callback = reloaders .reload_explorer })
209
- end
205
+ create_nvim_tree_autocmd (" BufWritePost" , {
206
+ callback = function ()
207
+ if opts .auto_reload_on_write and not opts .filesystem_watchers .enable then
208
+ log .line (" dev" , " BufWritePost reloading" )
209
+ reloaders .reload_explorer ()
210
+ end
211
+ end ,
212
+ })
210
213
211
214
create_nvim_tree_autocmd (" BufReadPost" , {
212
215
callback = function (data )
@@ -236,12 +239,14 @@ local function setup_autocommands(opts)
236
239
end ,
237
240
})
238
241
239
- if not has_watchers and opts .git .enable then
240
- create_nvim_tree_autocmd (" User" , {
241
- pattern = { " FugitiveChanged" , " NeogitStatusRefreshed" },
242
- callback = reloaders .reload_git ,
243
- })
244
- end
242
+ create_nvim_tree_autocmd (" User" , {
243
+ pattern = { " FugitiveChanged" , " NeogitStatusRefreshed" },
244
+ callback = function ()
245
+ if not opts .filesystem_watchers .enable and opts .git .enable then
246
+ reloaders .reload_git ()
247
+ end
248
+ end ,
249
+ })
245
250
246
251
if opts .tab .sync .open then
247
252
create_nvim_tree_autocmd (" TabEnter" , { callback = vim .schedule_wrap (M .tab_enter ) })
@@ -277,16 +282,16 @@ local function setup_autocommands(opts)
277
282
create_nvim_tree_autocmd ({ " BufEnter" , " BufNewFile" }, { callback = M .open_on_directory })
278
283
end
279
284
280
- if opts . reload_on_bufenter and not has_watchers then
281
- create_nvim_tree_autocmd ( " BufEnter " , {
282
- pattern = " NvimTree_* " ,
283
- callback = function ()
285
+ create_nvim_tree_autocmd ( " BufEnter " , {
286
+ pattern = " NvimTree_* " ,
287
+ callback = function ()
288
+ if opts . reload_on_bufenter and not opts . filesystem_watchers . enable then
284
289
if utils .is_nvim_tree_buf (0 ) then
285
290
reloaders .reload_explorer ()
286
291
end
287
- end ,
288
- })
289
- end
292
+ end
293
+ end ,
294
+ })
290
295
291
296
if opts .view .centralize_selection then
292
297
create_nvim_tree_autocmd (" BufEnter" , {
@@ -655,6 +660,16 @@ local function validate_options(conf)
655
660
end
656
661
end
657
662
663
+ function M .purge_all_state ()
664
+ require (" nvim-tree.watcher" ).purge_watchers ()
665
+ view .close_all_tabs ()
666
+ view .abandon_all_windows ()
667
+ if core .get_explorer () ~= nil then
668
+ git .purge_state ()
669
+ TreeExplorer = nil
670
+ end
671
+ end
672
+
658
673
function M .setup (conf )
659
674
if vim .fn .has " nvim-0.8" == 0 then
660
675
vim .notify_once (" nvim-tree.lua requires Neovim 0.8 or higher" , vim .log .levels .WARN )
@@ -703,6 +718,7 @@ function M.setup(conf)
703
718
require (" nvim-tree.marks" ).setup (opts )
704
719
require (" nvim-tree.modified" ).setup (opts )
705
720
require (" nvim-tree.help" ).setup (opts )
721
+ require (" nvim-tree.watcher" ).setup (opts )
706
722
if M .config .renderer .icons .show .file and pcall (require , " nvim-web-devicons" ) then
707
723
require (" nvim-web-devicons" ).setup ()
708
724
end
@@ -714,13 +730,7 @@ function M.setup(conf)
714
730
commands .setup ()
715
731
else
716
732
-- subsequent calls to setup
717
- require (" nvim-tree.watcher" ).purge_watchers ()
718
- view .close_all_tabs ()
719
- view .abandon_all_windows ()
720
- if core .get_explorer () ~= nil then
721
- git .purge_state ()
722
- TreeExplorer = nil
723
- end
733
+ M .purge_all_state ()
724
734
end
725
735
726
736
vim .g .NvimTreeSetup = 1
0 commit comments