nvim-tree.lua icon indicating copy to clipboard operation
nvim-tree.lua copied to clipboard

Enhance filters.exclude For More Granularity

Open sarmong opened this issue 2 years ago • 8 comments

Description

I have the following line

  filters = {
    dotfiles = true,
    exclude = { ".config", ".local" },
  },

And now gitignore files are always shown, and using I to toggle them doesn't work.

If I remove the line with exclude, all works fine.

Neovim version

NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Operating system and version

Arch Linux , kernel - 5.17.1-arch1-1

nvim-tree version

commit 618ea256137a28ea467bf82e4f2ab0b059dc3e0d

Steps to reproduce

  1. Create a folder with .gitignore and a couple of files
  2. Gitignore file1
  3. nvim -nu /tmp/nvt-min.lua
  4. :NvimTreeToggle
  5. Observe the gitignored file being show
  6. Press I - gitignored file still shown

Expected behavior

  1. Gitignored files are not shown by default
  2. Gitignored files are toggled with I

Actual behavior

No response

Minimal config

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",
			"kyazdani42/nvim-tree.lua",
			"kyazdani42/nvim-web-devicons",
		},
		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({
		filters = {
			dotfiles = true,
			exclude = { ".config", ".local" },
		},
	})
end

sarmong avatar Apr 09 '22 09:04 sarmong

P.S. This used to work on commit 6eebc10ed8f97aae29a2ef9561ce2d922c668639

sarmong avatar Apr 09 '22 10:04 sarmong

works just fine on my end. Would you mind changing .config and .local with .config$ and .local$ ?

kyazdani42 avatar Apr 09 '22 13:04 kyazdani42

maybe this was broken for you in https://github.com/kyazdani42/nvim-tree.lua/commit/00fd8aefe016ff2665e4479627ec977b411133d1 ?

kyazdani42 avatar Apr 09 '22 13:04 kyazdani42

maybe this was broken for you in 00fd8ae ?

~~I probably should have added filters.custom_regex instead of filters.custom.~~

~~We could do that now... @kyazdani42 ?~~

Edit: that regex change only affects filters.custom, not filters.exclude.

Cannot replicate at 618ea25: file1 is hidden until I

alex-courtis avatar Apr 10 '22 03:04 alex-courtis

I've looked deeper and here's where the problem is. If you add do echo "folder/.config/file3" >>.gitignore and create this directories and file, the file will never be toggled.

I might be a bit confused by how exclude works. I though tit should only affect the toggle_dotfiles action, but it also affects the toggle_git_ignored aciton.

I expected the gitignored files inside the excluded directory to still be togglable with I

sarmong avatar Apr 10 '22 09:04 sarmong

I see. I can replicate with config/file3 and .config/file3

filters.exclude overrides each of the filtering mechanisms: I, U, H: git.ignore, filters.custom and filters.dotfiles.

That is working as intended:

  - |filters.exclude|: list of directories or files to exclude from filtering
    (will always be shown)
      type: `{string}`
      default: `{}`

There is ambiguity in that it does not explicitly state that git.ignore is excluded. I think we should clarify the documentation, along with adding the default key bindings/action names for each filter option.

alex-courtis avatar Apr 11 '22 00:04 alex-courtis

Raised https://github.com/kyazdani42/nvim-tree.lua/pull/1168

A quick review would be great @sarmong

alex-courtis avatar Apr 16 '22 01:04 alex-courtis

@alex-courtis . thanks, the explanation makes it clearer.

However, I think it might be worth it to change the behaviour to account for the situation I have.

I can implement it in the future, so maybe we can keep the issue open

sarmong avatar Apr 17 '22 10:04 sarmong

This appears to be complete with the three filters: dotfiles, custom, exclude as well as git.ignore.

The three mappings control these:

I toggle_git_ignored toggle visibility of files/folders hidden via |git.ignore| option H toggle_dotfiles toggle visibility of dotfiles via |filters.dotfiles| option U toggle_custom toggle visibility of files/folders hidden via |filters.custom| option

alex-courtis avatar Oct 23 '22 04:10 alex-courtis