Skip to content

filtered subfolder Events not torn down #2468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alex-courtis opened this issue Oct 14, 2023 · 3 comments · Fixed by #2537
Closed

filtered subfolder Events not torn down #2468

alex-courtis opened this issue Oct 14, 2023 · 3 comments · Fixed by #2537
Labels
bug Something isn't working PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated reproduced Issue confirmed

Comments

@alex-courtis
Copy link
Member

Description

Event:destroy not called for subfolders of an ignored folder.

Neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1696795921

Operating system and version

Linux 6.5.7-arch1-1

nvim-tree version

4054fc4

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {}
end

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {}
end

Steps to reproduce

: ; mkdir -p i/1 i/2 i/3
: ; mkdir -p n/1 n/2 n/3
: ; touch i/1/a i/2/a i/3/a
: ; git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /home/alex/src/nvim-tree/r/gitignored.watchers/.git/
: ; echo "i" > .gitignore

Expected behavior

Toggle git ignored filter.
Expand i
Toggle filter again

Watcher:destroy and Event:destroy called for directories under i

Actual behavior

Only Watcher:destroy called for i/[123]. Both are called for i

[2023-10-15 10:27:32] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers' nil
[2023-10-15 10:27:32] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers'
[2023-10-15 10:27:32] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers'
[2023-10-15 10:27:32] [watcher] git start
[2023-10-15 10:27:32] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/.git' { "FETCH_HEAD", "HEAD", "HEAD.lock", "config", "index" }
[2023-10-15 10:27:32] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/.git'
[2023-10-15 10:27:32] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/.git'
[2023-10-15 10:27:32] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n' nil
[2023-10-15 10:27:32] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n'
[2023-10-15 10:27:32] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/n'



[2023-10-15 10:27:39] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/1' nil
[2023-10-15 10:27:39] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/1'
[2023-10-15 10:27:39] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/n/1'
[2023-10-15 10:27:39] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/2' nil
[2023-10-15 10:27:39] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/2'
[2023-10-15 10:27:39] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/n/2'
[2023-10-15 10:27:39] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/3' nil
[2023-10-15 10:27:39] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/n/3'
[2023-10-15 10:27:39] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/n/3'



[2023-10-15 10:27:43] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i' nil
[2023-10-15 10:27:43] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i'
[2023-10-15 10:27:43] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/i'


[2023-10-15 10:27:47] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/1' nil
[2023-10-15 10:27:47] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/1'
[2023-10-15 10:27:47] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/i/1'
[2023-10-15 10:27:47] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/2' nil
[2023-10-15 10:27:47] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/2'
[2023-10-15 10:27:47] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/i/2'
[2023-10-15 10:27:47] [watcher] Watcher:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/3' nil
[2023-10-15 10:27:47] [watcher] Event:new '/home/alex/src/nvim-tree/r/gitignored.watchers/i/3'
[2023-10-15 10:27:47] [watcher] Event:start '/home/alex/src/nvim-tree/r/gitignored.watchers/i/3'


[2023-10-15 10:27:53] [watcher] Watcher:destroy '/home/alex/src/nvim-tree/r/gitignored.watchers/i'
[2023-10-15 10:27:53] [watcher] Event:destroy '/home/alex/src/nvim-tree/r/gitignored.watchers/i'
@alex-courtis alex-courtis added the bug Something isn't working label Oct 14, 2023
@alex-courtis
Copy link
Member Author

This is a one time resource leak. Watchers created for the i subdirectories will use the existing Event

@GZLiew
Copy link

GZLiew commented Nov 4, 2023

@alex-courtis can you give me a few clues ? I would like to make a PR to fix this

@alex-courtis
Copy link
Member Author

Thanks for looking into this one @GZLiew

Resource leaks are serious business! It seems we are not destroying all the child nodes and their watchers.

Watcher is destroying the Event correctly in all cases.

reload is destroying the parent node correctly:

explorer_node.node_destroy(n)

Possibility: reload recursively destroy all child nodes.

@alex-courtis alex-courtis added the PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated label Nov 5, 2023
Akmadan23 added a commit that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated reproduced Issue confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants