Skip to content

Commit df00d38

Browse files
committed
feat(#1826): allow using config from vim.diagnostic for icons + severity
1 parent f0e9951 commit df00d38

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

doc/nvim-tree-lua.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,10 @@ Icons for diagnostic severity.
13291329
error = ""
13301330
}
13311331
<
1332+
*nvim-tree.diagnostics.diagnostic_opts*
1333+
|vim.diagnostic.Opts| overrides |nvim-tree.diagnostics.severity| and
1334+
|nvim-tree.diagnostics.icons|
1335+
Type: `boolean`, Default: `false`
13321336
==============================================================================
13331337
5.9 OPTS: MODIFIED *nvim-tree-opts-modified*
13341338

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
420420
warning = "",
421421
error = "",
422422
},
423+
diagnostic_opts = false,
423424
},
424425
modified = {
425426
enable = false,

lua/nvim-tree/diagnostics.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ end
231231
function M.setup(opts)
232232
M.enable = opts.diagnostics.enable
233233
M.debounce_delay = opts.diagnostics.debounce_delay
234-
M.severity = opts.diagnostics.severity
234+
M.severity = opts.diagnostics.diagnostic_opts and {
235+
min = vim.diagnostic.severity.HINT,
236+
max = vim.diagnostic.severity.ERROR
237+
} or opts.diagnostics.severity
235238

236239
if M.enable then
237240
log.line("diagnostics", "setup")

lua/nvim-tree/renderer/decorator/diagnostics.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,29 @@ local DiagnosticsDecorator = Decorator:extend()
4141
---@protected
4242
---@param args DecoratorArgs
4343
function DiagnosticsDecorator:new(args)
44-
self.explorer = args.explorer
44+
self.explorer = args.explorer
4545

46-
self.enabled = true
47-
self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none"
48-
self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none"
46+
self.enabled = true
47+
self.highlight_range = self.explorer.opts.renderer.highlight_diagnostics or "none"
48+
self.icon_placement = self.explorer.opts.renderer.icons.diagnostics_placement or "none"
49+
50+
local vim_diagnostic_icons = {}
51+
52+
if self.explorer.opts.diagnostics.diagnostic_opts then
53+
local vim_diagnostic_config = vim.diagnostic.config() or {}
54+
local signs = vim_diagnostic_config.signs or {}
55+
if type(signs) == "function" then
56+
signs = signs(0, 0)
57+
end
58+
59+
vim_diagnostic_icons = (type(signs) == "table" and signs.text) or {}
60+
end
4961

5062
if self.explorer.opts.renderer.icons.show.diagnostics then
5163
self.diag_icons = {}
5264
for name, sev in pairs(ICON_KEYS) do
5365
self.diag_icons[sev] = {
54-
str = self.explorer.opts.diagnostics.icons[name],
66+
str = vim_diagnostic_icons[sev] or self.explorer.opts.diagnostics.icons[name],
5567
hl = { HG_ICON[sev] },
5668
}
5769
self:define_sign(self.diag_icons[sev])

0 commit comments

Comments
 (0)