Skip to content

Commit 09373ef

Browse files
authored
Merge branch 'master' into issue-2859-fix-invalid-window-id
2 parents 6be9d83 + 15942df commit 09373ef

17 files changed

+338
-69
lines changed

doc/nvim-tree-lua.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
423423
root_folder_label = ":~:s?$?/..?",
424424
indent_width = 2,
425425
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
426+
hidden_display = "none",
426427
symlink_destination = true,
427428
highlight_git = "none",
428429
highlight_diagnostics = "none",
@@ -878,6 +879,49 @@ Number of spaces for an each tree nesting level. Minimum 1.
878879
A list of filenames that gets highlighted with `NvimTreeSpecialFile`.
879880
Type: `table`, Default: `{ "Cargo.toml", "Makefile", "README.md", "readme.md", }`
880881

882+
*nvim-tree.renderer.hidden_display*
883+
Show a summary of hidden files below the tree using `NvimTreeHiddenDisplay
884+
Type: `function | string`, Default: `"none"`
885+
886+
Possible string values are:
887+
- `"none"`: Doesn't inform anything about hidden files.
888+
- `"simple"`: Shows how many hidden files are in a folder.
889+
- `"all"`: Shows how many files are hidden and the number of hidden
890+
files per reason why they're hidden.
891+
892+
Example `"all"`:
893+
If a folder has 14 hidden items for various reasons, the display might
894+
show: >
895+
(14 total git: 5, dotfile: 9)
896+
<
897+
If a function is provided, it receives a table `hidden_stats` where keys are
898+
reasons and values are the count of hidden files for that reason.
899+
900+
The `hidden_stats` argument is structured as follows, where <num> is the
901+
number of hidden files related to the field: >
902+
hidden_stats = {
903+
bookmark = <num>,
904+
buf = <num>,
905+
custom = <num>,
906+
dotfile = <num>,
907+
git = <num>,
908+
live_filter = <num>,
909+
}
910+
<
911+
Example of function that can be passed: >
912+
function(hidden_stats)
913+
local total_count = 0
914+
for reason, count in pairs(hidden_stats) do
915+
total_count = total_count + count
916+
end
917+
918+
if total_count > 0 then
919+
return "(" .. tostring(total_count) .. " hidden)"
920+
end
921+
return nil
922+
end
923+
<
924+
881925
*nvim-tree.renderer.symlink_destination*
882926
Whether to show the destination of the symlink.
883927
Type: `boolean`, Default: `true`
@@ -2461,6 +2505,9 @@ Hidden: >
24612505
NvimTreeModifiedFileHL NvimTreeHiddenIcon
24622506
NvimTreeModifiedFolderHL NvimTreeHiddenFileHL
24632507
<
2508+
Hidden Display: >
2509+
NvimTreeHiddenDisplay Conceal
2510+
<
24642511
Opened: >
24652512
NvimTreeOpenedHL Special
24662513
<
@@ -2872,6 +2919,7 @@ highlight group is not, hard linking as follows: >
28722919
|nvim-tree.renderer.add_trailing|
28732920
|nvim-tree.renderer.full_name|
28742921
|nvim-tree.renderer.group_empty|
2922+
|nvim-tree.renderer.hidden_display|
28752923
|nvim-tree.renderer.highlight_bookmarks|
28762924
|nvim-tree.renderer.highlight_clipboard|
28772925
|nvim-tree.renderer.highlight_diagnostics|

lua/nvim-tree.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
398398
root_folder_label = ":~:s?$?/..?",
399399
indent_width = 2,
400400
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
401+
hidden_display = "none",
401402
symlink_destination = true,
402403
highlight_git = "none",
403404
highlight_diagnostics = "none",
@@ -647,6 +648,7 @@ local ACCEPTED_TYPES = {
647648
},
648649
},
649650
renderer = {
651+
hidden_display = { "function", "string" },
650652
group_empty = { "boolean", "function" },
651653
root_folder_label = { "function", "string", "boolean" },
652654
},
@@ -680,6 +682,7 @@ local ACCEPTED_STRINGS = {
680682
signcolumn = { "yes", "no", "auto" },
681683
},
682684
renderer = {
685+
hidden_display = { "none", "simple", "all" },
683686
highlight_git = { "none", "icon", "name", "all" },
684687
highlight_opened_files = { "none", "icon", "name", "all" },
685688
highlight_modified = { "none", "icon", "name", "all" },
@@ -837,7 +840,6 @@ function M.setup(conf)
837840
require("nvim-tree.view").setup(opts)
838841
require("nvim-tree.lib").setup(opts)
839842
require("nvim-tree.renderer").setup(opts)
840-
require("nvim-tree.live-filter").setup(opts)
841843
require("nvim-tree.marks").setup(opts)
842844
require("nvim-tree.buffers").setup(opts)
843845
require("nvim-tree.help").setup(opts)

lua/nvim-tree/api.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local actions = require "nvim-tree.actions"
66
local appearance_diagnostics = require "nvim-tree.appearance.diagnostics"
77
local events = require "nvim-tree.events"
88
local help = require "nvim-tree.help"
9-
local live_filter = require "nvim-tree.live-filter"
109
local marks_navigation = require "nvim-tree.marks.navigation"
1110
local marks_bulk_delete = require "nvim-tree.marks.bulk-delete"
1211
local marks_bulk_trash = require "nvim-tree.marks.bulk-trash"
@@ -265,8 +264,8 @@ Api.git.reload = wrap(actions.reloaders.reload_git)
265264
Api.events.subscribe = events.subscribe
266265
Api.events.Event = events.Event
267266

268-
Api.live_filter.start = wrap(live_filter.start_filtering)
269-
Api.live_filter.clear = wrap(live_filter.clear_filter)
267+
Api.live_filter.start = wrap_explorer_member("live_filter", "start_filtering")
268+
Api.live_filter.clear = wrap_explorer_member("live_filter", "clear_filter")
270269

271270
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))
272271
Api.marks.list = wrap_explorer_member("marks", "get_marks")

lua/nvim-tree/appearance/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ M.HIGHLIGHT_GROUPS = {
1414
-- Standard
1515
{ group = "NvimTreeNormal", link = "Normal" },
1616
{ group = "NvimTreeNormalFloat", link = "NormalFloat" },
17+
{ group = "NvimTreeNormalFloatBorder", link = "FloatBorder" },
1718
{ group = "NvimTreeNormalNC", link = "NvimTreeNormal" },
1819

1920
{ group = "NvimTreeLineNr", link = "LineNr" },
@@ -81,6 +82,9 @@ M.HIGHLIGHT_GROUPS = {
8182
{ group = "NvimTreeHiddenFileHL", link = "NvimTreeHiddenIcon" },
8283
{ group = "NvimTreeHiddenFolderHL", link = "NvimTreeHiddenFileHL" },
8384

85+
-- Hidden Display
86+
{ group = "NvimTreeHiddenDisplay", link = "Conceal" },
87+
8488
-- Opened
8589
{ group = "NvimTreeOpenedHL", link = "Special" },
8690

lua/nvim-tree/core.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local events = require "nvim-tree.events"
22
local explorer = require "nvim-tree.explorer"
3-
local live_filter = require "nvim-tree.live-filter"
43
local view = require "nvim-tree.view"
54
local log = require "nvim-tree.log"
65

@@ -45,7 +44,7 @@ function M.get_nodes_starting_line()
4544
if view.is_root_folder_visible(M.get_cwd()) then
4645
offset = offset + 1
4746
end
48-
if live_filter.filter then
47+
if TreeExplorer and TreeExplorer.live_filter.filter then
4948
return offset + 1
5049
end
5150
return offset

lua/nvim-tree/enum.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ M.ICON_PLACEMENT = {
1919
right_align = 4,
2020
}
2121

22+
---Reason for filter in filter.lua
23+
---@enum FILTER_REASON
24+
M.FILTER_REASON = {
25+
none = 0, -- It's not filtered
26+
git = 1,
27+
buf = 2,
28+
dotfile = 4,
29+
custom = 8,
30+
bookmark = 16,
31+
}
32+
2233
return M

lua/nvim-tree/explorer/explore.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ local utils = require "nvim-tree.utils"
22
local builders = require "nvim-tree.explorer.node-builders"
33
local explorer_node = require "nvim-tree.explorer.node"
44
local git = require "nvim-tree.git"
5-
local live_filter = require "nvim-tree.live-filter"
65
local log = require "nvim-tree.log"
76

7+
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
88
local Watcher = require "nvim-tree.watcher"
99

1010
local M = {}
@@ -17,7 +17,17 @@ local M = {}
1717
local function populate_children(handle, cwd, node, git_status, parent)
1818
local node_ignored = explorer_node.is_git_ignored(node)
1919
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
20+
2021
local filter_status = parent.filters:prepare(git_status)
22+
23+
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
24+
git = 0,
25+
buf = 0,
26+
dotfile = 0,
27+
custom = 0,
28+
bookmark = 0,
29+
})
30+
2131
while true do
2232
local name, t = vim.loop.fs_scandir_next(handle)
2333
if not name then
@@ -29,8 +39,8 @@ local function populate_children(handle, cwd, node, git_status, parent)
2939

3040
---@type uv.fs_stat.result|nil
3141
local stat = vim.loop.fs_stat(abs)
32-
33-
if not parent.filters:should_filter(abs, stat, filter_status) and not nodes_by_path[abs] and Watcher.is_fs_event_capable(abs) then
42+
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
43+
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] and Watcher.is_fs_event_capable(abs) then
3444
local child = nil
3545
if t == "directory" and vim.loop.fs_access(abs, "R") then
3646
child = builders.folder(node, abs, name, stat)
@@ -47,6 +57,12 @@ local function populate_children(handle, cwd, node, git_status, parent)
4757
nodes_by_path[child.absolute_path] = true
4858
explorer_node.update_git_status(child, node_ignored, git_status)
4959
end
60+
else
61+
for reason, value in pairs(FILTER_REASON) do
62+
if filter_reason == value then
63+
node.hidden_stats[reason] = node.hidden_stats[reason] + 1
64+
end
65+
end
5066
end
5167

5268
log.profile_end(profile)
@@ -82,7 +98,7 @@ function M.explore(node, status, parent)
8298
end
8399

84100
parent.sorters:sort(node.nodes)
85-
live_filter.apply_filter(node)
101+
parent.live_filter:apply_filter(node)
86102

87103
log.profile_end(profile)
88104
return node.nodes

lua/nvim-tree/explorer/filters.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local utils = require "nvim-tree.utils"
2+
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
23

34
---@class Filters to handle all opts.filters and related API
45
---@field config table hydrated user opts.filters
@@ -223,4 +224,33 @@ function Filters:should_filter(path, fs_stat, status)
223224
or bookmark(self, path, fs_stat and fs_stat.type, status.bookmarks)
224225
end
225226

227+
--- Check if the given path should be filtered, and provide the reason why it was
228+
---@param path string Absolute path
229+
---@param fs_stat uv.fs_stat.result|nil fs_stat of file
230+
---@param status table from prepare
231+
---@return FILTER_REASON
232+
function Filters:should_filter_as_reason(path, fs_stat, status)
233+
if not self.config.enable then
234+
return FILTER_REASON.none
235+
end
236+
237+
if is_excluded(self, path) then
238+
return FILTER_REASON.none
239+
end
240+
241+
if git(self, path, status.git_status) then
242+
return FILTER_REASON.git
243+
elseif buf(self, path, status.bufinfo) then
244+
return FILTER_REASON.buf
245+
elseif dotfile(self, path) then
246+
return FILTER_REASON.dotfile
247+
elseif custom(self, path) then
248+
return FILTER_REASON.custom
249+
elseif bookmark(self, path, fs_stat and fs_stat.type, status.bookmarks) then
250+
return FILTER_REASON.bookmark
251+
else
252+
return FILTER_REASON.none
253+
end
254+
end
255+
226256
return Filters

lua/nvim-tree/explorer/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local watch = require "nvim-tree.explorer.watch"
44
local explorer_node = require "nvim-tree.explorer.node"
55
local Filters = require "nvim-tree.explorer.filters"
66
local Marks = require "nvim-tree.marks"
7+
local LiveFilter = require "nvim-tree.explorer.live-filter"
78
local Sorters = require "nvim-tree.explorer.sorters"
89

910
local M = {}
@@ -15,6 +16,9 @@ M.reload = require("nvim-tree.explorer.reload").reload
1516
---@field absolute_path string
1617
---@field nodes Node[]
1718
---@field open boolean
19+
---@field filters Filters
20+
---@field live_filter LiveFilter
21+
---@field sorters Sorter
1822
---@field marks Marks
1923

2024
local Explorer = {}
@@ -45,6 +49,7 @@ function Explorer.new(path)
4549
}, Explorer)
4650
explorer.watcher = watch.create_watcher(explorer)
4751
explorer.filters = Filters:new(M.config, explorer)
52+
explorer.live_filter = LiveFilter:new(M.config, explorer)
4853
explorer:_load(explorer)
4954
return explorer
5055
end

0 commit comments

Comments
 (0)