nvim-tree/nvim-tree.lua

filesystem_watchers.ignore_dirs Handle Windows Paths, Add /.zig-cache To Defaults

Opened this issue · 3 comments

Description

nvim-tree.lua spawns infinite watchers when the .zig-cache/tmp folder creates a temporary file during a build process. nvim-tree.lua locks the files and prevents zig from deleting it.

I assume this a windows only issue because windows locks files when they are open.

nvim-tree.log spits out this line 1933 times per second and nvim.exe grows in memory about 10-20 megabytes per second.

[2025-08-07 17:54:56] [watcher] event_cb 'M:\ComputerScience\GitLocal\c-engine\.zig-cache\tmp\2c5da8ef08bfc59e' 'M:\ComputerScience\GitLocal\c-engine\.zig-cache\tmp\2c5da8ef08bfc59e'
[2025-08-07 17:54:56] [watcher] node event scheduled refresh explorer:watch:M:\ComputerScience\GitLocal\c-engine\.zig-cache\tmp\2c5da8ef08bfc59e

Solution

add /.zig-cache to default ignore_dirs for watcher

filesystem_watchers = {
enable = true,
debounce_delay = 50,
ignore_dirs = {
"/.ccls-cache",
"/build",
"/node_modules",
"/target",
},
},

Neovim version

NVIM v0.11.3
Build type: Release
LuaJIT 2.1.1741730670

Operating system and version

Windows 10

Windows variant

Powershell

nvim-tree version

nvim-tree-v1.13.0

Clean room replication

uneccesary

Steps to reproduce

  1. make sure ./zig-cache is not filtered or ignored
  2. nvim
  3. zig build

Expected behavior

No response

Actual behavior

No response

That's quite reasonable, as there is little value in watching those files which are not under version control.

This is the same use case as the others.

I'd be most grateful for your raising a Pull Request to add this:

It appears on windows it doesn't resolve the forward slash into the correct directory so I was required to remove them.

     filesystem_watchers = {
        enable = true,
        debounce_delay = 50,
        ignore_dirs = {
          ".ccls-cache",
          "build",
          "node_modules",
          "target",
          ".zig-cache",
          "zig-out",
        },
      },

I added some logging to show below. Is the forward slash required in linux or could it just be removed from the defaults?

---@param path string
---@return boolean
local function is_folder_ignored(path)
  for _, folder in ipairs(IGNORED_PATHS) do
    if vim.startswith(path, folder) then
      return true
    end
  end

  if type(M.config.filesystem_watchers.ignore_dirs) == "table" then
    for _, ignore_dir in ipairs(M.config.filesystem_watchers.ignore_dirs) do
      log.line("watcher","path:%s  -  ignore_dir:%s - matches:%s", path, ignore_dir, vim.fn.match(path, ignore_dir)) 
      if vim.fn.match(path, ignore_dir) ~= -1 then
        return true
      end
    end
  elseif type(M.config.filesystem_watchers.ignore_dirs) == "function" then
     
    return M.config.filesystem_watchers.ignore_dirs(path)
  end

  return false
end

Notice that the node_modules folder does not match with /node_modules

[2025-08-10 03:54:32] [profile] START populate_children M:\ComputerScience\GitLocal\c-engine\node_modules
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:/.ccls-cache - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:/build - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:/node_modules - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:/target - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:.zig-cache - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\node_modules  -  ignore_dir:zig-out - matches:-1
[2025-08-10 03:54:32] [watcher] Watcher:create 'M:\ComputerScience\GitLocal\c-engine\node_modules' nil
[2025-08-10 03:54:32] [watcher] Event:create 'M:\ComputerScience\GitLocal\c-engine\node_modules'
[2025-08-10 03:54:32] [watcher] Event:start 'M:\ComputerScience\GitLocal\c-engine\node_modules'
[2025-08-10 03:54:32] [profile] END   populate_children M:\ComputerScience\GitLocal\c-engine\node_modules 1ms

[2025-08-10 03:54:32] [profile] START populate_children M:\ComputerScience\GitLocal\c-engine\.zig-cache
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\.zig-cache  -  ignore_dir:/.ccls-cache - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\.zig-cache  -  ignore_dir:/build - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\.zig-cache  -  ignore_dir:/node_modules - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\.zig-cache  -  ignore_dir:/target - matches:-1
[2025-08-10 03:54:32] [watcher] path:M:\ComputerScience\GitLocal\c-engine\.zig-cache  -  ignore_dir:.zig-cache - matches:37
[2025-08-10 03:54:32] [profile] END   populate_children M:\ComputerScience\GitLocal\c-engine\.zig-cache 1ms

It appears on windows it doesn't resolve the forward slash into the correct directory so I was required to remove them.

The forward slash is used by convention to indicate the directory start, so that we ignore, say .../build.out but not .../ci.build/

It's a regex match and won't match windows paths. Why doesn't it? nvim-tree devs don't have access to or expertise with windows and wouldn't have been able to build or test it.

I'd be most grateful if you could handle windows paths in a normalised manner, to enable the defaults to function. It looks like you have a good understanding of the codebase :)

Similar windows path handlers: utils.path_relative utils.escape_special_characters