nvim-tree / nvim-tree/nvim-tree.lua
Customizable filter composition logic
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 8.6k
- Forks
- 639
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 2
Description
When using the git_clean and no_buffer filters together, I think it would be more useful to show files that are either dirty or open in a buffer. The current behavior is to only show files that are both dirty and open in a buffer.
Can this functionality be implemented utilising API?
Not currently, the filter logic is not exposed in the public API.
Describe the solution you'd like
Exposing the various filter functions to the public api in a way that they could be composed in the custom filter would be my preferred solution. Something like this would be nice:
require('nvim-tree').setup({
filters = {
no_buffer = false,
git_clean = false,
custom = function (path)
local filter_api = require('nvim-tree.api.filter')
-- return true only when *both* git_clean and no_buffer would filter the path. These
-- functions should not check the enabled/disabled state of the function so that the
-- custom filter can have precedence while still using their result.
return filter_api.git_clean(path) and filter_api.no_buffer(path)
end
}
})
Describe alternatives you've considered
I've implemented the behavior I want in my config with a couple janky runtime patches to nvim-tree's internal filter API:
local filters = require('nvim-tree.explorer.filters')
local enum = require('nvim-tree.enum')
local should_filter = filters.should_filter
local should_filter_as_reason = filters.should_filter_as_reason
filters.should_filter = function (self, path, fs_stat, status)
if self.state.no_buffer and not self:buf(path, status.bufinfo) then
return false
end
if self.state.git_clean and not self:git(path, status.project) then
return false
end
return should_filter(self, path, fs_stat, status)
end
filters.should_filter_as_reason = function (self, path, fs_stat, status)
if not should_filter(self, path, fs_stat, status) then
return enum.FILTER_REASON.none
end
return should_filter_as_reason(self, path, fs_stat, status)
end
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with nvim-tree.explorer.filters and enum, focusing on the existing should_filter and should_filter_as_reason paths shown in the issue. Review how the public API could expose filter functions without their enabled-state checks; done means custom filters can compose git_clean and no_buffer with predictable precedence and preserve filter reasons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100