Skip to content

Commit

Permalink
Filter uses classic, tidy opts
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 8, 2024
1 parent 2c172cf commit 67cc06e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
57 changes: 29 additions & 28 deletions lua/nvim-tree/explorer/filters.lua
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
local utils = require("nvim-tree.utils")
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON

---@class Filters to handle all opts.filters and related API
local Class = require("nvim-tree.classic")

---@class (exact) Filters: Class
---@field config table hydrated user opts.filters
---@field private explorer Explorer
---@field private exclude_list string[] filters.exclude
---@field private ignore_list string[] filters.custom string table
---@field private ignore_list table<string, boolean> filters.custom string table
---@field private custom_function (fun(absolute_path: string): boolean)|nil filters.custom function
local Filters = {}

---@param opts table user options
---@param explorer Explorer
---@return Filters
function Filters:new(opts, explorer)
local o = {
explorer = explorer,
ignore_list = {},
exclude_list = opts.filters.exclude,
custom_function = nil,
config = {
enable = opts.filters.enable,
filter_custom = true,
filter_dotfiles = opts.filters.dotfiles,
filter_git_ignored = opts.filters.git_ignored,
filter_git_clean = opts.filters.git_clean,
filter_no_buffer = opts.filters.no_buffer,
filter_no_bookmark = opts.filters.no_bookmark,
},
local Filters = Class:extend()

---@class Filters
---@overload fun(args: FiltersArgs): Filters

---@class (exact) FiltersArgs
---@field explorer Explorer

---@param args FiltersArgs
function Filters:new(args)
self.explorer = args.explorer
self.ignore_list = {}
self.exclude_list = self.explorer.opts.filters.exclude
self.custom_function = nil
self.config = {
enable = self.explorer.opts.filters.enable,
filter_custom = true,
filter_dotfiles = self.explorer.opts.filters.dotfiles,
filter_git_ignored = self.explorer.opts.filters.git_ignored,
filter_git_clean = self.explorer.opts.filters.git_clean,
filter_no_buffer = self.explorer.opts.filters.no_buffer,
filter_no_bookmark = self.explorer.opts.filters.no_bookmark,
}

local custom_filter = opts.filters.custom
local custom_filter = self.explorer.opts.filters.custom
if type(custom_filter) == "function" then
o.custom_function = custom_filter
self.custom_function = custom_filter
else
if custom_filter and #custom_filter > 0 then
for _, filter_name in pairs(custom_filter) do
o.ignore_list[filter_name] = true
self.ignore_list[filter_name] = true
end
end
end
setmetatable(o, self)
self.__index = self
return o
end

---@param path string
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Explorer:new(args)

self.sorters = Sorter(config)
self.renderer = Renderer({ explorer = self })
self.filters = Filters:new(config, self)
self.filters = Filters({ explorer = self })
self.live_filter = LiveFilter({ explorer = self })
self.marks = Marks:new(config, self)
self.clipboard = Clipboard:new(config, self)
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/explorer/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ local LiveFilter = Class:extend()
---@param args LiveFilterArgs
function LiveFilter:new(args)
self.explorer = args.explorer
self.prefix = args.explorer.opts.live_filter.prefix
self.always_show_folders = args.explorer.opts.live_filter.always_show_folders
self.prefix = self.explorer.opts.live_filter.prefix
self.always_show_folders = self.explorer.opts.live_filter.always_show_folders
self.filter = nil
end

Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Builder:new(args)
DecoratorOpened({ explorer = args.explorer }),
DecoratorGit({ explorer = args.explorer })
}
self.hidden_display = Builder:setup_hidden_display_function(args.explorer.opts)
self.hidden_display = Builder:setup_hidden_display_function(self.explorer.opts)
end

---Insert ranged highlight groups into self.highlights
Expand Down

0 comments on commit 67cc06e

Please sign in to comment.