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
This commit is contained in:
Richard Li
2022-11-29 11:12:34 +11:00
committed by GitHub
parent 0b319a1b28
commit 829e9f68e1
4 changed files with 24 additions and 3 deletions

View File

@@ -292,6 +292,7 @@ Subsequent calls to setup will replace the previous configuration.
diagnostics = { diagnostics = {
enable = false, enable = false,
show_on_dirs = false, show_on_dirs = false,
show_on_open_dirs = true,
debounce_delay = 50, debounce_delay = 50,
severity = { severity = {
min = vim.diagnostic.severity.HINT, min = vim.diagnostic.severity.HINT,
@@ -318,6 +319,7 @@ Subsequent calls to setup will replace the previous configuration.
enable = true, enable = true,
ignore = true, ignore = true,
show_on_dirs = true, show_on_dirs = true,
show_on_open_dirs = true,
timeout = 400, timeout = 400,
}, },
actions = { actions = {
@@ -557,6 +559,11 @@ Show LSP and COC diagnostics in the signcolumn
Show diagnostic icons on parent directories. Show diagnostic icons on parent directories.
Type: `boolean`, Default: `false` Type: `boolean`, Default: `false`
*nvim-tree.diagnostics.show_on_open_dirs*
Show diagnostics icons on directories that are open.
Only relevant when `diagnostics.show_on_dirs` is `true`.
Type: `boolean`, Default: `true`
*nvim-tree.diagnostics.icons* *nvim-tree.diagnostics.icons*
Icons for diagnostic severity. Icons for diagnostic severity.
Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }` Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }`
@@ -588,6 +595,11 @@ Git integration with icons and colors.
Show status icons of children when directory itself has no status icon. Show status icons of children when directory itself has no status icon.
Type: `boolean`, Default: `true` Type: `boolean`, Default: `true`
*nvim-tree.git.show_on_open_dirs*
Show status icons on directories that are open.
Only relevant when `git.show_on_dirs` is `true`.
Type: `boolean`, Default: `true`
*nvim-tree.git.timeout* *nvim-tree.git.timeout*
Kills the git process after some time if it takes too long. Kills the git process after some time if it takes too long.
Type: `number`, Default: `400` (ms) Type: `number`, Default: `400` (ms)

View File

@@ -568,6 +568,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
diagnostics = { diagnostics = {
enable = false, enable = false,
show_on_dirs = false, show_on_dirs = false,
show_on_open_dirs = true,
debounce_delay = 50, debounce_delay = 50,
severity = { severity = {
min = vim.diagnostic.severity.HINT, min = vim.diagnostic.severity.HINT,
@@ -594,6 +595,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
enable = true, enable = true,
ignore = true, ignore = true,
show_on_dirs = true, show_on_dirs = true,
show_on_open_dirs = true,
timeout = 400, timeout = 400,
}, },
actions = { actions = {

View File

@@ -114,7 +114,7 @@ function M.update()
for line, node in pairs(nodes_by_line) do for line, node in pairs(nodes_by_line) do
local nodepath = utils.canonical_path(node.absolute_path) local nodepath = utils.canonical_path(node.absolute_path)
log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath) log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath)
if M.show_on_dirs and vim.startswith(bufpath, nodepath) then if M.show_on_dirs and vim.startswith(bufpath, nodepath) and (not node.open or M.show_on_open_dirs) then
log.line("diagnostics", " matched fold node '%s'", node.absolute_path) log.line("diagnostics", " matched fold node '%s'", node.absolute_path)
node.diag_status = severity node.diag_status = severity
add_sign(line, severity) add_sign(line, severity)
@@ -147,6 +147,7 @@ function M.setup(opts)
end end
M.show_on_dirs = opts.diagnostics.show_on_dirs M.show_on_dirs = opts.diagnostics.show_on_dirs
M.show_on_open_dirs = opts.diagnostics.show_on_open_dirs
vim.fn.sign_define(sign_names[1][1], { text = opts.diagnostics.icons.error, texthl = sign_names[1][2] }) vim.fn.sign_define(sign_names[1][1], { text = opts.diagnostics.icons.error, texthl = sign_names[1][2] })
vim.fn.sign_define(sign_names[2][1], { text = opts.diagnostics.icons.warning, texthl = sign_names[2][2] }) vim.fn.sign_define(sign_names[2][1], { text = opts.diagnostics.icons.warning, texthl = sign_names[2][2] })
vim.fn.sign_define(sign_names[3][1], { text = opts.diagnostics.icons.info, texthl = sign_names[3][2] }) vim.fn.sign_define(sign_names[3][1], { text = opts.diagnostics.icons.info, texthl = sign_names[3][2] })

View File

@@ -75,9 +75,13 @@ local function warn_status(git_status)
) )
end end
local function show_git(node)
return node.git_status and (not node.open or M.git_show_on_open_dirs)
end
local function get_icons_(node) local function get_icons_(node)
local git_status = node.git_status local git_status = node.git_status
if not git_status then if not show_git(node) then
return nil return nil
end end
@@ -137,7 +141,7 @@ end
local function get_highlight_(node) local function get_highlight_(node)
local git_status = node.git_status local git_status = node.git_status
if not git_status then if not show_git(node) then
return return
end end
@@ -162,6 +166,8 @@ function M.setup(opts)
else else
M.get_highlight = nil_ M.get_highlight = nil_
end end
M.git_show_on_open_dirs = opts.git.show_on_open_dirs
end end
return M return M