@@ -3,8 +3,11 @@ local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
3
3
4
4
local Class = require (" nvim-tree.classic" )
5
5
6
+ --- @alias FilterTypes " custom" | " dotfiles" | " git_ignored" | " git_clean" | " no_buffer" | " no_bookmark"
7
+
6
8
--- @class (exact ) Filters : Class
7
- --- @field config table hydrated user opts.filters
9
+ --- @field enabled boolean
10
+ --- @field states table<FilterTypes , boolean>
8
11
--- @field private explorer Explorer
9
12
--- @field private exclude_list string[] filters.exclude
10
13
--- @field private ignore_list table<string , boolean> filters.custom string table
@@ -23,14 +26,15 @@ function Filters:new(args)
23
26
self .ignore_list = {}
24
27
self .exclude_list = self .explorer .opts .filters .exclude
25
28
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 ,
29
+
30
+ self .enabled = self .explorer .opts .filters .enable
31
+ self .states = {
32
+ custom = true ,
33
+ dotfiles = self .explorer .opts .filters .dotfiles ,
34
+ git_ignored = self .explorer .opts .filters .git_ignored ,
35
+ git_clean = self .explorer .opts .filters .git_clean ,
36
+ no_buffer = self .explorer .opts .filters .no_buffer ,
37
+ no_bookmark = self .explorer .opts .filters .no_bookmark ,
34
38
}
35
39
36
40
local custom_filter = self .explorer .opts .filters .custom
@@ -71,12 +75,12 @@ local function git(self, path, project)
71
75
xy = xy or project .dirs .indirect [path ] and project .dirs .indirect [path ][1 ]
72
76
73
77
-- filter ignored; overrides clean as they are effectively dirty
74
- if self .config . filter_git_ignored and xy == " !!" then
78
+ if self .states . git_ignored and xy == " !!" then
75
79
return true
76
80
end
77
81
78
82
-- filter clean
79
- if self .config . filter_git_clean and not xy then
83
+ if self .states . git_clean and not xy then
80
84
return true
81
85
end
82
86
88
92
--- @param bufinfo table vim.fn.getbufinfo { buflisted = 1 }
89
93
--- @return boolean
90
94
local function buf (self , path , bufinfo )
91
- if not self .config . filter_no_buffer or type (bufinfo ) ~= " table" then
95
+ if not self .states . no_buffer or type (bufinfo ) ~= " table" then
92
96
return false
93
97
end
94
98
105
109
--- @param path string
106
110
--- @return boolean
107
111
local function dotfile (self , path )
108
- return self .config . filter_dotfiles and utils .path_basename (path ):sub (1 , 1 ) == " ."
112
+ return self .states . dotfiles and utils .path_basename (path ):sub (1 , 1 ) == " ."
109
113
end
110
114
111
115
--- Bookmark is present
114
118
--- @param bookmarks table<string , string | nil> path , filetype table of bookmarked files
115
119
--- @return boolean
116
120
local function bookmark (self , path , path_type , bookmarks )
117
- if not self .config . filter_no_bookmark then
121
+ if not self .states . no_bookmark then
118
122
return false
119
123
end
120
124
-- if bookmark is empty, we should see a empty filetree
149
153
--- @param path string
150
154
--- @return boolean
151
155
local function custom (self , path )
152
- if not self .config . filter_custom then
156
+ if not self .states . custom then
153
157
return false
154
158
end
155
159
@@ -191,7 +195,7 @@ function Filters:prepare(project)
191
195
bookmarks = {},
192
196
}
193
197
194
- if self .config . filter_no_buffer then
198
+ if self .states . no_buffer then
195
199
status .bufinfo = vim .fn .getbufinfo ({ buflisted = 1 })
196
200
end
197
201
211
215
--- @param status table from prepare
212
216
--- @return boolean
213
217
function Filters :should_filter (path , fs_stat , status )
214
- if not self .config . enable then
218
+ if not self .enabled then
215
219
return false
216
220
end
217
221
233
237
--- @param status table from prepare
234
238
--- @return FILTER_REASON
235
239
function Filters :should_filter_as_reason (path , fs_stat , status )
236
- if not self .config . enable then
240
+ if not self .enabled then
237
241
return FILTER_REASON .none
238
242
end
239
243
0 commit comments