Skip to content

Commit 1edebb7

Browse files
committed
chore: lsp diagnostics setup
1 parent 0ca8717 commit 1edebb7

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ require'nvim-tree'.setup {
5151
hijack_cursor = false,
5252
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
5353
update_cwd = false,
54+
-- show lsp diagnostics in the signcolumn
55+
lsp_diagnostics = false,
5456
-- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
5557
update_focused_file = {
5658
-- enables the feature
@@ -86,7 +88,6 @@ let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help file
8688
let g:nvim_tree_auto_resize = 0 "1 by default, will resize the tree to its saved width when opening a file
8789
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
8890
let g:nvim_tree_group_empty = 1 " 0 by default, compact folders that only contain a single folder into one node in the file tree
89-
let g:nvim_tree_lsp_diagnostics = 1 "0 by default, will show lsp diagnostics in the signcolumn. See :help nvim_tree_lsp_diagnostics
9091
let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker.
9192
let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
9293
let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target.

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function.
7474
open_on_tab = false,
7575
hijack_cursor = false,
7676
update_cwd = false,
77+
lsp_diagnostics = false,
7778
update_focused_file = {
7879
enable = false,
7980
update_cwd = false,
@@ -159,6 +160,10 @@ Here is a list of the options available in the setup call:
159160
type: `{string}`
160161
default: `{}`
161162

163+
- |lsp_diagnostics|: show lsp diagnostics in the signcolumn
164+
type: `boolean`
165+
default: false
166+
162167
==============================================================================
163168
OPTIONS *nvim-tree-options*
164169

@@ -317,12 +322,6 @@ Can be 0 or 1. When 1, appends a trailing slash to folder names.
317322
Can be 0 or 1. When 1, folders that contain only one folder are grouped
318323
together. 0 by default.
319324

320-
|g:nvim_tree_lsp_diagnostics| *g:nvim_tree_lsp_diagnostics*
321-
322-
Can be 0 or 1. When 1, will show nvim-lsp diagnostics in the signcolumn
323-
of the tree highlighted by diagnostic severity.
324-
Code will be executed on `LspDiagnosticsChanged`. 0 by default.
325-
326325
|g:nvim_tree_special_files| *g:nvim_tree_special_files*
327326

328327
A list of filenames that gets highlighted with `NvimTreeSpecialFile`.

lua/nvim-tree.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ local function setup_autocommands(opts)
374374
au SessionLoadPost * lua require'nvim-tree.view'._wipe_rogue_buffer()
375375
]]
376376

377-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
377+
if opts.lsp_diagnostics then
378378
vim.cmd "au User LspDiagnosticsChanged lua require'nvim-tree.diagnostics'.update()"
379379
end
380380
if opts.auto_close then
@@ -404,6 +404,7 @@ local DEFAULT_OPTS = {
404404
auto_close = false,
405405
hijack_cursor = false,
406406
update_cwd = false,
407+
lsp_diagnostics = false,
407408
update_focused_file = {
408409
enable = false,
409410
update_cwd = false,
@@ -428,6 +429,7 @@ function M.setup(conf)
428429

429430
require'nvim-tree.colors'.setup()
430431
require'nvim-tree.view'.setup()
432+
require'nvim-tree.diagnostics'.setup(opts)
431433

432434
setup_autocommands(opts)
433435
setup_vim_commands()
@@ -448,6 +450,7 @@ local out_config = {
448450
"nvim_tree_system_open_command_args",
449451
"nvim_tree_follow",
450452
"nvim_tree_follow_update_path",
453+
"nvim_tree_lsp_diagnostics"
451454
}
452455

453456
local x = vim.tbl_filter(function(v)

lua/nvim-tree/diagnostics.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ local function from_coc()
8888
end
8989

9090
function M.update()
91+
if not M.enable then
92+
return
93+
end
9194
local buffer_severity
9295
if vim.g.coc_service_initialized == 1 then
9396
buffer_severity = from_coc()
@@ -116,4 +119,8 @@ function M.update()
116119
end
117120
end
118121

122+
function M.setup(opts)
123+
M.enable = opts.lsp_diagnostics
124+
end
125+
119126
return M

lua/nvim-tree/lib.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ function M.unroll_dir(node)
146146
renderer.draw(M.Tree, true)
147147
end
148148

149-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
150-
diagnostics.update()
151-
end
149+
diagnostics.update()
152150
end
153151

154152
local function refresh_git(node)
@@ -190,9 +188,7 @@ function M.refresh_tree(disable_clock)
190188
end)
191189
end
192190

193-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
194-
vim.schedule(diagnostics.update)
195-
end
191+
vim.schedule(diagnostics.update)
196192

197193
if view.win_open() then
198194
renderer.draw(M.Tree, true)

0 commit comments

Comments
 (0)