Skip to content

Commit f6f50cd

Browse files
committed
Merge remote-tracking branch 'origin/master' into live-filter-multiinstace
2 parents 0f2cda6 + e25eb7f commit f6f50cd

File tree

14 files changed

+258
-10
lines changed

14 files changed

+258
-10
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 & 0 deletions
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" },

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/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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local explorer_node = require "nvim-tree.explorer.node"
44
local git = require "nvim-tree.git"
55
local log = require "nvim-tree.log"
66

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

910
local M = {}
@@ -16,7 +17,17 @@ local M = {}
1617
local function populate_children(handle, cwd, node, git_status, parent)
1718
local node_ignored = explorer_node.is_git_ignored(node)
1819
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
20+
1921
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+
2031
while true do
2132
local name, t = vim.loop.fs_scandir_next(handle)
2233
if not name then
@@ -28,8 +39,8 @@ local function populate_children(handle, cwd, node, git_status, parent)
2839

2940
---@type uv.fs_stat.result|nil
3041
local stat = vim.loop.fs_stat(abs)
31-
32-
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
3344
local child = nil
3445
if t == "directory" and vim.loop.fs_access(abs, "R") then
3546
child = builders.folder(node, abs, name, stat)
@@ -46,6 +57,12 @@ local function populate_children(handle, cwd, node, git_status, parent)
4657
nodes_by_path[child.absolute_path] = true
4758
explorer_node.update_git_status(child, node_ignored, git_status)
4859
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
4966
end
5067

5168
log.profile_end(profile)

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/live-filter.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ local function reset_filter(self, node_)
3535
return
3636
end
3737

38+
node_.hidden_stats = vim.tbl_deep_extend("force", node_.hidden_stats or {}, {
39+
live_filter = 0,
40+
})
41+
3842
Iterator.builder(node_.nodes)
3943
:hidden()
4044
:applier(function(node)
4145
node.hidden = false
46+
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
47+
live_filter = 0,
48+
})
4249
end)
4350
:iterate()
4451
end
@@ -95,6 +102,10 @@ function LiveFilter:apply_filter(node_)
95102
local filtered_nodes = 0
96103
local nodes = node.group_next and { node.group_next } or node.nodes
97104

105+
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
106+
live_filter = 0,
107+
})
108+
98109
if nodes then
99110
for _, n in pairs(nodes) do
100111
iterate(n)
@@ -104,6 +115,8 @@ function LiveFilter:apply_filter(node_)
104115
end
105116
end
106117

118+
node.hidden_stats.live_filter = filtered_nodes
119+
107120
local has_nodes = nodes and (self.always_show_folders or #nodes > filtered_nodes)
108121
local ok, is_match = pcall(matches, self, node)
109122
node.hidden = not (has_nodes or (ok and is_match))

lua/nvim-tree/explorer/reload.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local explorer_node = require "nvim-tree.explorer.node"
44
local git = require "nvim-tree.git"
55
local log = require "nvim-tree.log"
66

7+
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
78
local NodeIterator = require "nvim-tree.iterators.node-iterator"
89
local Watcher = require "nvim-tree.watcher"
910

@@ -91,6 +92,16 @@ function M.reload(node, git_status)
9192
local node_ignored = explorer_node.is_git_ignored(node)
9293
---@type table<string, Node>
9394
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
95+
96+
-- To reset we must 'zero' everything that we use
97+
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
98+
git = 0,
99+
buf = 0,
100+
dotfile = 0,
101+
custom = 0,
102+
bookmark = 0,
103+
})
104+
94105
while true do
95106
local name, t = vim.loop.fs_scandir_next(handle)
96107
if not name then
@@ -101,7 +112,8 @@ function M.reload(node, git_status)
101112
---@type uv.fs_stat.result|nil
102113
local stat = vim.loop.fs_stat(abs)
103114

104-
if not explorer.filters:should_filter(abs, stat, filter_status) then
115+
local filter_reason = explorer.filters:should_filter_as_reason(abs, stat, filter_status)
116+
if filter_reason == FILTER_REASON.none then
105117
remain_childs[abs] = true
106118

107119
-- Recreate node if type changes.
@@ -138,6 +150,12 @@ function M.reload(node, git_status)
138150
n.fs_stat = stat
139151
end
140152
end
153+
else
154+
for reason, value in pairs(FILTER_REASON) do
155+
if filter_reason == value then
156+
node.hidden_stats[reason] = node.hidden_stats[reason] + 1
157+
end
158+
end
141159
end
142160
end
143161

lua/nvim-tree/node.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
---@field group_next Node|nil
2222
---@field nodes Node[]
2323
---@field open boolean
24+
---@field hidden_stats table -- Each field of this table is a key for source and value for count
2425

2526
---@class FileNode: BaseNode
2627
---@field extension string

0 commit comments

Comments
 (0)