From 1edebb789415e2c63db4ffc4d2ea1149bccbe865 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sun, 26 Sep 2021 11:56:44 +0200 Subject: [PATCH] chore: lsp diagnostics setup --- README.md | 3 ++- doc/nvim-tree-lua.txt | 11 +++++------ lua/nvim-tree.lua | 5 ++++- lua/nvim-tree/diagnostics.lua | 7 +++++++ lua/nvim-tree/lib.lua | 8 ++------ 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 67e63a2b..3642c92a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ require'nvim-tree'.setup { hijack_cursor = false, -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) update_cwd = false, + -- show lsp diagnostics in the signcolumn + lsp_diagnostics = false, -- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file update_focused_file = { -- enables the feature @@ -86,7 +88,6 @@ let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help file let g:nvim_tree_auto_resize = 0 "1 by default, will resize the tree to its saved width when opening a file let g:nvim_tree_add_trailing = 1 "0 by default, append a trailing slash to folder names 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 -let g:nvim_tree_lsp_diagnostics = 1 "0 by default, will show lsp diagnostics in the signcolumn. See :help nvim_tree_lsp_diagnostics let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker. 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. let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target. diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 74ca0314..6336777a 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -74,6 +74,7 @@ function. open_on_tab = false, hijack_cursor = false, update_cwd = false, + lsp_diagnostics = false, update_focused_file = { enable = false, update_cwd = false, @@ -159,6 +160,10 @@ Here is a list of the options available in the setup call: type: `{string}` default: `{}` +- |lsp_diagnostics|: show lsp diagnostics in the signcolumn + type: `boolean` + default: false + ============================================================================== OPTIONS *nvim-tree-options* @@ -317,12 +322,6 @@ Can be 0 or 1. When 1, appends a trailing slash to folder names. Can be 0 or 1. When 1, folders that contain only one folder are grouped together. 0 by default. -|g:nvim_tree_lsp_diagnostics| *g:nvim_tree_lsp_diagnostics* - -Can be 0 or 1. When 1, will show nvim-lsp diagnostics in the signcolumn -of the tree highlighted by diagnostic severity. -Code will be executed on `LspDiagnosticsChanged`. 0 by default. - |g:nvim_tree_special_files| *g:nvim_tree_special_files* A list of filenames that gets highlighted with `NvimTreeSpecialFile`. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index a43213f7..3de3743e 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -374,7 +374,7 @@ local function setup_autocommands(opts) au SessionLoadPost * lua require'nvim-tree.view'._wipe_rogue_buffer() ]] - if vim.g.nvim_tree_lsp_diagnostics == 1 then + if opts.lsp_diagnostics then vim.cmd "au User LspDiagnosticsChanged lua require'nvim-tree.diagnostics'.update()" end if opts.auto_close then @@ -404,6 +404,7 @@ local DEFAULT_OPTS = { auto_close = false, hijack_cursor = false, update_cwd = false, + lsp_diagnostics = false, update_focused_file = { enable = false, update_cwd = false, @@ -428,6 +429,7 @@ function M.setup(conf) require'nvim-tree.colors'.setup() require'nvim-tree.view'.setup() + require'nvim-tree.diagnostics'.setup(opts) setup_autocommands(opts) setup_vim_commands() @@ -448,6 +450,7 @@ local out_config = { "nvim_tree_system_open_command_args", "nvim_tree_follow", "nvim_tree_follow_update_path", + "nvim_tree_lsp_diagnostics" } local x = vim.tbl_filter(function(v) diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index 3d4241ea..81c1d195 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -88,6 +88,9 @@ local function from_coc() end function M.update() + if not M.enable then + return + end local buffer_severity if vim.g.coc_service_initialized == 1 then buffer_severity = from_coc() @@ -116,4 +119,8 @@ function M.update() end end +function M.setup(opts) + M.enable = opts.lsp_diagnostics +end + return M diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index e97608a1..efac656f 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -146,9 +146,7 @@ function M.unroll_dir(node) renderer.draw(M.Tree, true) end - if vim.g.nvim_tree_lsp_diagnostics == 1 then - diagnostics.update() - end + diagnostics.update() end local function refresh_git(node) @@ -190,9 +188,7 @@ function M.refresh_tree(disable_clock) end) end - if vim.g.nvim_tree_lsp_diagnostics == 1 then - vim.schedule(diagnostics.update) - end + vim.schedule(diagnostics.update) if view.win_open() then renderer.draw(M.Tree, true)