|
1 | 1 | local utils = require("nvim-tree.utils")
|
2 | 2 | local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
|
3 | 3 |
|
4 |
| ----@class Filters to handle all opts.filters and related API |
| 4 | +local Class = require("nvim-tree.classic") |
| 5 | + |
| 6 | +---@class (exact) Filters: Class |
5 | 7 | ---@field config table hydrated user opts.filters
|
6 | 8 | ---@field private explorer Explorer
|
7 | 9 | ---@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 |
9 | 11 | ---@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, |
30 | 34 | }
|
31 | 35 |
|
32 |
| - local custom_filter = opts.filters.custom |
| 36 | + local custom_filter = self.explorer.opts.filters.custom |
33 | 37 | if type(custom_filter) == "function" then
|
34 |
| - o.custom_function = custom_filter |
| 38 | + self.custom_function = custom_filter |
35 | 39 | else
|
36 | 40 | if custom_filter and #custom_filter > 0 then
|
37 | 41 | for _, filter_name in pairs(custom_filter) do
|
38 |
| - o.ignore_list[filter_name] = true |
| 42 | + self.ignore_list[filter_name] = true |
39 | 43 | end
|
40 | 44 | end
|
41 | 45 | end
|
42 |
| - setmetatable(o, self) |
43 |
| - self.__index = self |
44 |
| - return o |
45 | 46 | end
|
46 | 47 |
|
47 | 48 | ---@param path string
|
|
0 commit comments