Skip to content

Commit 67cc06e

Browse files
committed
Filter uses classic, tidy opts
1 parent 2c172cf commit 67cc06e

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

lua/nvim-tree/explorer/filters.lua

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
local utils = require("nvim-tree.utils")
22
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
33

4-
---@class Filters to handle all opts.filters and related API
4+
local Class = require("nvim-tree.classic")
5+
6+
---@class (exact) Filters: Class
57
---@field config table hydrated user opts.filters
68
---@field private explorer Explorer
79
---@field private exclude_list string[] filters.exclude
8-
---@field private ignore_list string[] filters.custom string table
10+
---@field private ignore_list table<string, boolean> filters.custom string table
911
---@field private custom_function (fun(absolute_path: string): boolean)|nil filters.custom function
10-
local Filters = {}
11-
12-
---@param opts table user options
13-
---@param explorer Explorer
14-
---@return Filters
15-
function Filters:new(opts, explorer)
16-
local o = {
17-
explorer = explorer,
18-
ignore_list = {},
19-
exclude_list = opts.filters.exclude,
20-
custom_function = nil,
21-
config = {
22-
enable = opts.filters.enable,
23-
filter_custom = true,
24-
filter_dotfiles = opts.filters.dotfiles,
25-
filter_git_ignored = opts.filters.git_ignored,
26-
filter_git_clean = opts.filters.git_clean,
27-
filter_no_buffer = opts.filters.no_buffer,
28-
filter_no_bookmark = opts.filters.no_bookmark,
29-
},
12+
local Filters = Class:extend()
13+
14+
---@class Filters
15+
---@overload fun(args: FiltersArgs): Filters
16+
17+
---@class (exact) FiltersArgs
18+
---@field explorer Explorer
19+
20+
---@param args FiltersArgs
21+
function Filters:new(args)
22+
self.explorer = args.explorer
23+
self.ignore_list = {}
24+
self.exclude_list = self.explorer.opts.filters.exclude
25+
self.custom_function = nil
26+
self.config = {
27+
enable = self.explorer.opts.filters.enable,
28+
filter_custom = true,
29+
filter_dotfiles = self.explorer.opts.filters.dotfiles,
30+
filter_git_ignored = self.explorer.opts.filters.git_ignored,
31+
filter_git_clean = self.explorer.opts.filters.git_clean,
32+
filter_no_buffer = self.explorer.opts.filters.no_buffer,
33+
filter_no_bookmark = self.explorer.opts.filters.no_bookmark,
3034
}
3135

32-
local custom_filter = opts.filters.custom
36+
local custom_filter = self.explorer.opts.filters.custom
3337
if type(custom_filter) == "function" then
34-
o.custom_function = custom_filter
38+
self.custom_function = custom_filter
3539
else
3640
if custom_filter and #custom_filter > 0 then
3741
for _, filter_name in pairs(custom_filter) do
38-
o.ignore_list[filter_name] = true
42+
self.ignore_list[filter_name] = true
3943
end
4044
end
4145
end
42-
setmetatable(o, self)
43-
self.__index = self
44-
return o
4546
end
4647

4748
---@param path string

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Explorer:new(args)
5959

6060
self.sorters = Sorter(config)
6161
self.renderer = Renderer({ explorer = self })
62-
self.filters = Filters:new(config, self)
62+
self.filters = Filters({ explorer = self })
6363
self.live_filter = LiveFilter({ explorer = self })
6464
self.marks = Marks:new(config, self)
6565
self.clipboard = Clipboard:new(config, self)

lua/nvim-tree/explorer/live-filter.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ local LiveFilter = Class:extend()
2121
---@param args LiveFilterArgs
2222
function LiveFilter:new(args)
2323
self.explorer = args.explorer
24-
self.prefix = args.explorer.opts.live_filter.prefix
25-
self.always_show_folders = args.explorer.opts.live_filter.always_show_folders
24+
self.prefix = self.explorer.opts.live_filter.prefix
25+
self.always_show_folders = self.explorer.opts.live_filter.always_show_folders
2626
self.filter = nil
2727
end
2828

lua/nvim-tree/renderer/builder.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function Builder:new(args)
7171
DecoratorOpened({ explorer = args.explorer }),
7272
DecoratorGit({ explorer = args.explorer })
7373
}
74-
self.hidden_display = Builder:setup_hidden_display_function(args.explorer.opts)
74+
self.hidden_display = Builder:setup_hidden_display_function(self.explorer.opts)
7575
end
7676

7777
---Insert ranged highlight groups into self.highlights

0 commit comments

Comments
 (0)