From ed9db632a89ff2712c48e32774d68a715553510f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 5 Nov 2022 10:24:25 +1100 Subject: [PATCH] feat(watcher): add filesystem_watchers.ignore_dirs (#1705) --- doc/nvim-tree-lua.txt | 7 +++++++ lua/nvim-tree.lua | 1 + lua/nvim-tree/explorer/watch.lua | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 00f2d133..79ee7177 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -308,6 +308,7 @@ Subsequent calls to setup will replace the previous configuration. filesystem_watchers = { enable = true, debounce_delay = 50, + ignore_dirs = {}, }, git = { enable = true, @@ -604,6 +605,12 @@ performance. Idle milliseconds between filesystem change and action. Type: `number`, Default: `50` (ms) + *nvim-tree.filesystem_watchers.ignore_dirs* + List of vim regex for absolute directory paths that will not be watched. + Backslashes must be escaped e.g. `"my-project/\\.build$"`. See |string-match|. + Useful when path is not in `.gitignore` or git integration is disabled. + Type: {string}, Default: `{}` + *nvim-tree.on_attach* Function ran when creating the nvim-tree buffer. This can be used to attach keybindings to the tree buffer. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 28c2edaf..664389ae 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -589,6 +589,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS filesystem_watchers = { enable = true, debounce_delay = 50, + ignore_dirs = {}, }, git = { enable = true, diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index 342b4c1f..449b9a50 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -36,6 +36,13 @@ local function is_folder_ignored(path) return true end end + + for _, ignore_dir in ipairs(M.ignore_dirs) do + if vim.fn.match(path, ignore_dir) ~= -1 then + return true + end + end + return false end @@ -78,6 +85,7 @@ end function M.setup(opts) M.enabled = opts.filesystem_watchers.enable M.debounce_delay = opts.filesystem_watchers.debounce_delay + M.ignore_dirs = opts.filesystem_watchers.ignore_dirs M.uid = 0 end