Skip to content

Commit 829e9f6

Browse files
authored
feat: add diagnostics.show_on_open_dirs git.show_on_open_dirs (#1778)
* feat(diagnostics): only show diagnostic on closed folder * feat(git): only show git icon on closed folder
1 parent 0b319a1 commit 829e9f6

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

doc/nvim-tree-lua.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Subsequent calls to setup will replace the previous configuration.
292292
diagnostics = {
293293
enable = false,
294294
show_on_dirs = false,
295+
show_on_open_dirs = true,
295296
debounce_delay = 50,
296297
severity = {
297298
min = vim.diagnostic.severity.HINT,
@@ -318,6 +319,7 @@ Subsequent calls to setup will replace the previous configuration.
318319
enable = true,
319320
ignore = true,
320321
show_on_dirs = true,
322+
show_on_open_dirs = true,
321323
timeout = 400,
322324
},
323325
actions = {
@@ -557,6 +559,11 @@ Show LSP and COC diagnostics in the signcolumn
557559
Show diagnostic icons on parent directories.
558560
Type: `boolean`, Default: `false`
559561

562+
*nvim-tree.diagnostics.show_on_open_dirs*
563+
Show diagnostics icons on directories that are open.
564+
Only relevant when `diagnostics.show_on_dirs` is `true`.
565+
Type: `boolean`, Default: `true`
566+
560567
*nvim-tree.diagnostics.icons*
561568
Icons for diagnostic severity.
562569
Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }`
@@ -588,6 +595,11 @@ Git integration with icons and colors.
588595
Show status icons of children when directory itself has no status icon.
589596
Type: `boolean`, Default: `true`
590597

598+
*nvim-tree.git.show_on_open_dirs*
599+
Show status icons on directories that are open.
600+
Only relevant when `git.show_on_dirs` is `true`.
601+
Type: `boolean`, Default: `true`
602+
591603
*nvim-tree.git.timeout*
592604
Kills the git process after some time if it takes too long.
593605
Type: `number`, Default: `400` (ms)

lua/nvim-tree.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
568568
diagnostics = {
569569
enable = false,
570570
show_on_dirs = false,
571+
show_on_open_dirs = true,
571572
debounce_delay = 50,
572573
severity = {
573574
min = vim.diagnostic.severity.HINT,
@@ -594,6 +595,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
594595
enable = true,
595596
ignore = true,
596597
show_on_dirs = true,
598+
show_on_open_dirs = true,
597599
timeout = 400,
598600
},
599601
actions = {

lua/nvim-tree/diagnostics.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function M.update()
114114
for line, node in pairs(nodes_by_line) do
115115
local nodepath = utils.canonical_path(node.absolute_path)
116116
log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath)
117-
if M.show_on_dirs and vim.startswith(bufpath, nodepath) then
117+
if M.show_on_dirs and vim.startswith(bufpath, nodepath) and (not node.open or M.show_on_open_dirs) then
118118
log.line("diagnostics", " matched fold node '%s'", node.absolute_path)
119119
node.diag_status = severity
120120
add_sign(line, severity)
@@ -147,6 +147,7 @@ function M.setup(opts)
147147
end
148148

149149
M.show_on_dirs = opts.diagnostics.show_on_dirs
150+
M.show_on_open_dirs = opts.diagnostics.show_on_open_dirs
150151
vim.fn.sign_define(sign_names[1][1], { text = opts.diagnostics.icons.error, texthl = sign_names[1][2] })
151152
vim.fn.sign_define(sign_names[2][1], { text = opts.diagnostics.icons.warning, texthl = sign_names[2][2] })
152153
vim.fn.sign_define(sign_names[3][1], { text = opts.diagnostics.icons.info, texthl = sign_names[3][2] })

lua/nvim-tree/renderer/components/git.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ local function warn_status(git_status)
7575
)
7676
end
7777

78+
local function show_git(node)
79+
return node.git_status and (not node.open or M.git_show_on_open_dirs)
80+
end
81+
7882
local function get_icons_(node)
7983
local git_status = node.git_status
80-
if not git_status then
84+
if not show_git(node) then
8185
return nil
8286
end
8387

@@ -137,7 +141,7 @@ end
137141

138142
local function get_highlight_(node)
139143
local git_status = node.git_status
140-
if not git_status then
144+
if not show_git(node) then
141145
return
142146
end
143147

@@ -162,6 +166,8 @@ function M.setup(opts)
162166
else
163167
M.get_highlight = nil_
164168
end
169+
170+
M.git_show_on_open_dirs = opts.git.show_on_open_dirs
165171
end
166172

167173
return M

0 commit comments

Comments
 (0)