Skip to content

Commit 5ee7324

Browse files
kyazdani42jim-fx
authored andcommitted
chore: lsp diagnostics setup
1 parent aa6e674 commit 5ee7324

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
@@ -87,7 +89,6 @@ let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help file
8789
let g:nvim_tree_auto_resize = 0 "1 by default, will resize the tree to its saved width when opening a file
8890
let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names
8991
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
90-
let g:nvim_tree_lsp_diagnostics = 1 "0 by default, will show lsp diagnostics in the signcolumn. See :help nvim_tree_lsp_diagnostics
9192
let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker.
9293
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.
9394
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

@@ -323,12 +328,6 @@ Can be 0 or 1. When 1, appends a trailing slash to folder names.
323328
Can be 0 or 1. When 1, folders that contain only one folder are grouped
324329
together. 0 by default.
325330

326-
|g:nvim_tree_lsp_diagnostics| *g:nvim_tree_lsp_diagnostics*
327-
328-
Can be 0 or 1. When 1, will show nvim-lsp diagnostics in the signcolumn
329-
of the tree highlighted by diagnostic severity.
330-
Code will be executed on `LspDiagnosticsChanged`. 0 by default.
331-
332331
|g:nvim_tree_special_files| *g:nvim_tree_special_files*
333332

334333
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
@@ -380,7 +380,7 @@ local function setup_autocommands(opts)
380380
au SessionLoadPost * lua require'nvim-tree.view'._wipe_rogue_buffer()
381381
]]
382382

383-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
383+
if opts.lsp_diagnostics then
384384
vim.cmd "au User LspDiagnosticsChanged lua require'nvim-tree.diagnostics'.update()"
385385
end
386386
if opts.auto_close then
@@ -410,6 +410,7 @@ local DEFAULT_OPTS = {
410410
auto_close = false,
411411
hijack_cursor = false,
412412
update_cwd = false,
413+
lsp_diagnostics = false,
413414
update_focused_file = {
414415
enable = false,
415416
update_cwd = false,
@@ -434,6 +435,7 @@ function M.setup(conf)
434435

435436
require'nvim-tree.colors'.setup()
436437
require'nvim-tree.view'.setup()
438+
require'nvim-tree.diagnostics'.setup(opts)
437439

438440
setup_autocommands(opts)
439441
setup_vim_commands()
@@ -454,6 +456,7 @@ local out_config = {
454456
"nvim_tree_system_open_command_args",
455457
"nvim_tree_follow",
456458
"nvim_tree_follow_update_path",
459+
"nvim_tree_lsp_diagnostics"
457460
}
458461

459462
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
@@ -152,9 +152,7 @@ function M.unroll_dir(node)
152152
renderer.draw(M.Tree, true)
153153
end
154154

155-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
156-
diagnostics.update()
157-
end
155+
diagnostics.update()
158156
end
159157

160158
local function refresh_git(node)
@@ -196,9 +194,7 @@ function M.refresh_tree(disable_clock)
196194
end)
197195
end
198196

199-
if vim.g.nvim_tree_lsp_diagnostics == 1 then
200-
vim.schedule(diagnostics.update)
201-
end
197+
vim.schedule(diagnostics.update)
202198

203199
if view.win_open() then
204200
renderer.draw(M.Tree, true)

0 commit comments

Comments
 (0)