From df00d38afb97cc7ec0a31a871f4de318ed731ee0 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 17 Aug 2025 21:24:15 -0300 Subject: [PATCH 1/2] feat(#1826): allow using config from vim.diagnostic for icons + severity --- doc/nvim-tree-lua.txt | 4 ++++ lua/nvim-tree.lua | 1 + lua/nvim-tree/diagnostics.lua | 5 ++++- .../renderer/decorator/diagnostics.lua | 22 ++++++++++++++----- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 857e9a98e88..424f9b6d4a1 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1329,6 +1329,10 @@ Icons for diagnostic severity. error = "" } < +*nvim-tree.diagnostics.diagnostic_opts* +|vim.diagnostic.Opts| overrides |nvim-tree.diagnostics.severity| and +|nvim-tree.diagnostics.icons| + Type: `boolean`, Default: `false` ============================================================================== 5.9 OPTS: MODIFIED *nvim-tree-opts-modified* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 8befe53ed05..4b8389e93a0 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -420,6 +420,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS warning = "", error = "", }, + diagnostic_opts = false, }, modified = { enable = false, diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index 76810d4a796..853966b983a 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -231,7 +231,10 @@ end function M.setup(opts) M.enable = opts.diagnostics.enable M.debounce_delay = opts.diagnostics.debounce_delay - M.severity = opts.diagnostics.severity + M.severity = opts.diagnostics.diagnostic_opts and { + min = vim.diagnostic.severity.HINT, + max = vim.diagnostic.severity.ERROR + } or opts.diagnostics.severity if M.enable then log.line("diagnostics", "setup") diff --git a/lua/nvim-tree/renderer/decorator/diagnostics.lua b/lua/nvim-tree/renderer/decorator/diagnostics.lua index 35f76109251..56598ef9418 100644 --- a/lua/nvim-tree/renderer/decorator/diagnostics.lua +++ b/lua/nvim-tree/renderer/decorator/diagnostics.lua @@ -41,17 +41,29 @@ local DiagnosticsDecorator = Decorator:extend() ---@protected ---@param args DecoratorArgs function DiagnosticsDecorator:new(args) - self.explorer = args.explorer + self.explorer = args.explorer - self.enabled = true - self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none" - self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none" + self.enabled = true + self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none" + self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none" + + local vim_diagnostic_icons = {} + + if self.explorer.opts.diagnostics.diagnostic_opts then + local vim_diagnostic_config = vim.diagnostic.config() or {} + local signs = vim_diagnostic_config.signs or {} + if type(signs) == "function" then + signs = signs(0, 0) + end + + vim_diagnostic_icons = (type(signs) == "table" and signs.text) or {} + end if self.explorer.opts.renderer.icons.show.diagnostics then self.diag_icons = {} for name, sev in pairs(ICON_KEYS) do self.diag_icons[sev] = { - str = self.explorer.opts.diagnostics.icons[name], + str = vim_diagnostic_icons[sev] or self.explorer.opts.diagnostics.icons[name], hl = { HG_ICON[sev] }, } self:define_sign(self.diag_icons[sev]) From 0e62506b9e083ceace586d0946ecd5cc88c06b2a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 25 Aug 2025 13:19:39 +1000 Subject: [PATCH 2/2] update help default options, add index --- doc/nvim-tree-lua.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 424f9b6d4a1..f686a89dfac 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -545,6 +545,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua warning = "", error = "", }, + diagnostic_opts = false, }, modified = { enable = false, @@ -3179,6 +3180,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.actions.use_system_clipboard| |nvim-tree.auto_reload_on_write| |nvim-tree.diagnostics.debounce_delay| +|nvim-tree.diagnostics.diagnostic_opts| |nvim-tree.diagnostics.enable| |nvim-tree.diagnostics.icons| |nvim-tree.diagnostics.severity|