Skip to content

Commit 94b8604

Browse files
committed
chore: complete the diagnostic setup migration
Colors groups and icons are now in diagnostics.lua. They are defined on setup which allows an easier configuration and better documentation. `lsp_diagnostics` boolean value has been moved into a table `diagnostics` with `enable` and `icons` as properties.
1 parent 64c31aa commit 94b8604

File tree

6 files changed

+73
-34
lines changed

6 files changed

+73
-34
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ require'nvim-tree'.setup {
6161
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
6262
update_cwd = false,
6363
-- show lsp diagnostics in the signcolumn
64-
lsp_diagnostics = false,
64+
diagnostics = {
65+
enable = false,
66+
icons = {
67+
hint = "",
68+
info = "",
69+
warning = "",
70+
error = "",
71+
}
72+
},
6573
-- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
6674
update_focused_file = {
6775
-- enables the feature
@@ -167,12 +175,6 @@ let g:nvim_tree_icons = {
167175
\ 'empty_open': "",
168176
\ 'symlink': "",
169177
\ 'symlink_open': "",
170-
\ },
171-
\ 'lsp': {
172-
\ 'hint': "",
173-
\ 'info': "",
174-
\ 'warning': "",
175-
\ 'error': "",
176178
\ }
177179
\ }
178180

doc/nvim-tree-lua.txt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ function.
7878
open_on_tab = false,
7979
hijack_cursor = false,
8080
update_cwd = false,
81-
lsp_diagnostics = false,
81+
diagnostics = {
82+
enable = false,
83+
icons = {
84+
hint = "",
85+
info = "",
86+
warning = "",
87+
error = "",
88+
}
89+
},
8290
update_focused_file = {
8391
enable = false,
8492
update_cwd = false,
@@ -196,10 +204,23 @@ Here is a list of the options available in the setup call:
196204
type: `{string}`
197205
default: `{}`
198206

199-
*nvim-tree.lsp_diagnostics*
200-
- |lsp_diagnostics|: show lsp diagnostics in the signcolumn
201-
type: `boolean`
202-
default: false
207+
*nvim-tree.diagnostics*
208+
- |diagnostics|: show lsp diagnostics in the signcolumn
209+
210+
- |diagnostics.enable|: enable/disable the feature
211+
type: `boolean`
212+
default: `false`
213+
214+
- |diagnostics.icons|: icons for diagnostic severity
215+
type: `table`
216+
default: `{ hint = "", info = "", warning = "", error = "" }`
217+
218+
`NOTE`: it will use the default diagnostic color groups to highlight the signs.
219+
If you wish to customize, you can override these groups:
220+
- `NvimTreeLspDiagnosticsError`
221+
- `NvimTreeLspDiagnosticsWarning`
222+
- `NvimTreeLspDiagnosticsInformation`
223+
- `NvimTreeLspDiagnosticsHint`
203224

204225
*nvim-tree.view*
205226
- |view|: window / buffer setup

lua/nvim-tree.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local colors = require'nvim-tree.colors'
77
local renderer = require'nvim-tree.renderer'
88
local fs = require'nvim-tree.fs'
99
local view = require'nvim-tree.view'
10+
local utils = require'nvim-tree.utils'
1011

1112
local _config = {
1213
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
@@ -416,7 +417,6 @@ local DEFAULT_OPTS = {
416417
auto_close = false,
417418
hijack_cursor = false,
418419
update_cwd = false,
419-
lsp_diagnostics = false,
420420
update_focused_file = {
421421
enable = false,
422422
update_cwd = false,
@@ -427,6 +427,15 @@ local DEFAULT_OPTS = {
427427
cmd = nil,
428428
args = {}
429429
},
430+
diagnostics = {
431+
enable = false,
432+
icons = {
433+
hint = "",
434+
info = "",
435+
warning = "",
436+
error = "",
437+
}
438+
},
430439
}
431440

432441
function M.setup(conf)
@@ -439,7 +448,7 @@ function M.setup(conf)
439448
_config.open_on_setup = opts.open_on_setup
440449
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup
441450
if type(opts.update_to_buf_dir) == "boolean" then
442-
require'nvim-tree.utils'.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
451+
utils.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
443452
_config.update_to_buf_dir = {
444453
enable = opts.update_to_buf_dir,
445454
auto_open = opts.update_to_buf_dir,
@@ -448,6 +457,10 @@ function M.setup(conf)
448457
_config.update_to_buf_dir = opts.update_to_buf_dir
449458
end
450459

460+
if opts.lsp_diagnostics ~= nil then
461+
utils.echo_warning("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics")
462+
end
463+
451464
require'nvim-tree.colors'.setup()
452465
require'nvim-tree.view'.setup(opts.view or {})
453466
require'nvim-tree.diagnostics'.setup(opts)

lua/nvim-tree/colors.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ local function get_links()
7070
FileDeleted = 'NvimTreeGitDeleted',
7171
Popup = 'Normal',
7272
GitIgnored = 'Comment',
73-
LspDiagnosticsError = "LspDiagnosticsDefaultError",
74-
LspDiagnosticsWarning = "LspDiagnosticsDefaultWarning",
75-
LspDiagnosticsInformation = "LspDiagnosticsDefaultInformation",
76-
LspDiagnosticsHint = "LspDiagnosticsDefaultHint",
7773
StatusLine = "StatusLine",
7874
StatusLineNC = "StatusLineNC",
7975
SignColumn = 'Normal',

lua/nvim-tree/config.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ function M.get_icon_state()
2424
symlink = "",
2525
symlink_open = "",
2626
},
27-
lsp = {
28-
hint = "",
29-
info = "",
30-
warning = "",
31-
error = "",
32-
},
3327
}
3428

3529
local user_icons = vim.g.nvim_tree_icons

lua/nvim-tree/diagnostics.lua

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
local a = vim.api
22
local utils = require'nvim-tree.utils'
33
local view = require'nvim-tree.view'
4-
local config = require'nvim-tree.config'
5-
local icon_state = config.get_icon_state()
64
local get_diagnostics = vim.lsp.diagnostic.get_all
75

86
local M = {}
@@ -25,11 +23,6 @@ local sign_names = {
2523
{ "NvimTreeSignHint", "NvimTreeLspDiagnosticsHint" },
2624
}
2725

28-
vim.fn.sign_define(sign_names[1][1], { text=icon_state.icons.lsp.error, texthl=sign_names[1][2]})
29-
vim.fn.sign_define(sign_names[2][1], { text=icon_state.icons.lsp.warning, texthl=sign_names[2][2]})
30-
vim.fn.sign_define(sign_names[3][1], { text=icon_state.icons.lsp.info, texthl=sign_names[3][2]})
31-
vim.fn.sign_define(sign_names[4][1], { text=icon_state.icons.lsp.hint, texthl=sign_names[4][2]})
32-
3326
local signs = {}
3427

3528
local function add_sign(linenr, severity)
@@ -75,7 +68,7 @@ local function from_coc()
7568
local severity_list = diagnostics[bufname] or {}
7669
table.insert(severity_list, severity)
7770
diagnostics[bufname] = severity_list
78-
end
71+
end
7972

8073
for bufname, severity_list in pairs(diagnostics) do
8174
if not buffer_severity[bufname] then
@@ -87,12 +80,16 @@ local function from_coc()
8780
return buffer_severity
8881
end
8982

83+
local function is_using_coc()
84+
return vim.g.coc_service_initialized == 1
85+
end
86+
9087
function M.update()
9188
if not M.enable then
9289
return
9390
end
9491
local buffer_severity
95-
if vim.g.coc_service_initialized == 1 then
92+
if is_using_coc() then
9693
buffer_severity = from_coc()
9794
else
9895
buffer_severity = from_nvim_lsp()
@@ -119,8 +116,24 @@ function M.update()
119116
end
120117
end
121118

119+
local has_06 = vim.fn.has('nvim-0.6') == 1
120+
local links = {
121+
NvimTreeLspDiagnosticsError = has_06 and "DiagnosticError" or "LspDiagnosticsDefaultError",
122+
NvimTreeLspDiagnosticsWarning = has_06 and "DiagnosticWarning" or "LspDiagnosticsDefaultWarning",
123+
NvimTreeLspDiagnosticsInformation = has_06 and "DiagnosticInfo" or "LspDiagnosticsDefaultInformation",
124+
NvimTreeLspDiagnosticsHint = has_06 and "DiagnosticHint" or "LspDiagnosticsDefaultHint",
125+
}
126+
122127
function M.setup(opts)
123-
M.enable = opts.lsp_diagnostics
128+
M.enable = opts.diagnostics.enable
129+
vim.fn.sign_define(sign_names[1][1], { text = opts.diagnostics.icons.error, texthl = sign_names[1][2] })
130+
vim.fn.sign_define(sign_names[2][1], { text = opts.diagnostics.icons.warning, texthl = sign_names[2][2] })
131+
vim.fn.sign_define(sign_names[3][1], { text = opts.diagnostics.icons.info, texthl = sign_names[3][2] })
132+
vim.fn.sign_define(sign_names[4][1], { text = opts.diagnostics.icons.hint, texthl = sign_names[4][2] })
133+
134+
for lhs, rhs in pairs(links) do
135+
vim.cmd("hi def link "..lhs.." "..rhs)
136+
end
124137
end
125138

126139
return M

0 commit comments

Comments
 (0)