From 94b8604e8689c295a78d7a868ba906cd061baa99 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sun, 10 Oct 2021 11:41:57 +0200 Subject: [PATCH] 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. --- README.md | 16 +++++++++------- doc/nvim-tree-lua.txt | 31 ++++++++++++++++++++++++++----- lua/nvim-tree.lua | 17 +++++++++++++++-- lua/nvim-tree/colors.lua | 4 ---- lua/nvim-tree/config.lua | 6 ------ lua/nvim-tree/diagnostics.lua | 33 +++++++++++++++++++++++---------- 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index b8262ec1..8d68987d 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,15 @@ require'nvim-tree'.setup { -- 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, + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + } + }, -- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file update_focused_file = { -- enables the feature @@ -167,12 +175,6 @@ let g:nvim_tree_icons = { \ 'empty_open': "", \ 'symlink': "", \ 'symlink_open': "", - \ }, - \ 'lsp': { - \ 'hint': "", - \ 'info': "", - \ 'warning': "", - \ 'error': "", \ } \ } diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 9b3d545c..5bdf0aef 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -78,7 +78,15 @@ function. open_on_tab = false, hijack_cursor = false, update_cwd = false, - lsp_diagnostics = false, + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + } + }, update_focused_file = { enable = false, update_cwd = false, @@ -196,10 +204,23 @@ Here is a list of the options available in the setup call: type: `{string}` default: `{}` -*nvim-tree.lsp_diagnostics* -- |lsp_diagnostics|: show lsp diagnostics in the signcolumn - type: `boolean` - default: false +*nvim-tree.diagnostics* +- |diagnostics|: show lsp diagnostics in the signcolumn + + - |diagnostics.enable|: enable/disable the feature + type: `boolean` + default: `false` + + - |diagnostics.icons|: icons for diagnostic severity + type: `table` + default: `{ hint = "", info = "", warning = "", error = "" }` + + `NOTE`: it will use the default diagnostic color groups to highlight the signs. + If you wish to customize, you can override these groups: + - `NvimTreeLspDiagnosticsError` + - `NvimTreeLspDiagnosticsWarning` + - `NvimTreeLspDiagnosticsInformation` + - `NvimTreeLspDiagnosticsHint` *nvim-tree.view* - |view|: window / buffer setup diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 03dd960a..e7068e9f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -7,6 +7,7 @@ local colors = require'nvim-tree.colors' local renderer = require'nvim-tree.renderer' local fs = require'nvim-tree.fs' local view = require'nvim-tree.view' +local utils = require'nvim-tree.utils' local _config = { is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1, @@ -416,7 +417,6 @@ local DEFAULT_OPTS = { auto_close = false, hijack_cursor = false, update_cwd = false, - lsp_diagnostics = false, update_focused_file = { enable = false, update_cwd = false, @@ -427,6 +427,15 @@ local DEFAULT_OPTS = { cmd = nil, args = {} }, + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + } + }, } function M.setup(conf) @@ -439,7 +448,7 @@ function M.setup(conf) _config.open_on_setup = opts.open_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup if type(opts.update_to_buf_dir) == "boolean" then - require'nvim-tree.utils'.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir") + utils.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir") _config.update_to_buf_dir = { enable = opts.update_to_buf_dir, auto_open = opts.update_to_buf_dir, @@ -448,6 +457,10 @@ function M.setup(conf) _config.update_to_buf_dir = opts.update_to_buf_dir end + if opts.lsp_diagnostics ~= nil then + utils.echo_warning("setup.lsp_diagnostics has been removed, see :help nvim-tree.diagnostics") + end + require'nvim-tree.colors'.setup() require'nvim-tree.view'.setup(opts.view or {}) require'nvim-tree.diagnostics'.setup(opts) diff --git a/lua/nvim-tree/colors.lua b/lua/nvim-tree/colors.lua index d81164ac..ceaeab00 100644 --- a/lua/nvim-tree/colors.lua +++ b/lua/nvim-tree/colors.lua @@ -70,10 +70,6 @@ local function get_links() FileDeleted = 'NvimTreeGitDeleted', Popup = 'Normal', GitIgnored = 'Comment', - LspDiagnosticsError = "LspDiagnosticsDefaultError", - LspDiagnosticsWarning = "LspDiagnosticsDefaultWarning", - LspDiagnosticsInformation = "LspDiagnosticsDefaultInformation", - LspDiagnosticsHint = "LspDiagnosticsDefaultHint", StatusLine = "StatusLine", StatusLineNC = "StatusLineNC", SignColumn = 'Normal', diff --git a/lua/nvim-tree/config.lua b/lua/nvim-tree/config.lua index 49e862ab..8821ef06 100644 --- a/lua/nvim-tree/config.lua +++ b/lua/nvim-tree/config.lua @@ -24,12 +24,6 @@ function M.get_icon_state() symlink = "", symlink_open = "", }, - lsp = { - hint = "", - info = "", - warning = "", - error = "", - }, } local user_icons = vim.g.nvim_tree_icons diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index 81c1d195..2e579c3c 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -1,8 +1,6 @@ local a = vim.api local utils = require'nvim-tree.utils' local view = require'nvim-tree.view' -local config = require'nvim-tree.config' -local icon_state = config.get_icon_state() local get_diagnostics = vim.lsp.diagnostic.get_all local M = {} @@ -25,11 +23,6 @@ local sign_names = { { "NvimTreeSignHint", "NvimTreeLspDiagnosticsHint" }, } -vim.fn.sign_define(sign_names[1][1], { text=icon_state.icons.lsp.error, texthl=sign_names[1][2]}) -vim.fn.sign_define(sign_names[2][1], { text=icon_state.icons.lsp.warning, texthl=sign_names[2][2]}) -vim.fn.sign_define(sign_names[3][1], { text=icon_state.icons.lsp.info, texthl=sign_names[3][2]}) -vim.fn.sign_define(sign_names[4][1], { text=icon_state.icons.lsp.hint, texthl=sign_names[4][2]}) - local signs = {} local function add_sign(linenr, severity) @@ -75,7 +68,7 @@ local function from_coc() local severity_list = diagnostics[bufname] or {} table.insert(severity_list, severity) diagnostics[bufname] = severity_list - end + end for bufname, severity_list in pairs(diagnostics) do if not buffer_severity[bufname] then @@ -87,12 +80,16 @@ local function from_coc() return buffer_severity end +local function is_using_coc() + return vim.g.coc_service_initialized == 1 +end + function M.update() if not M.enable then return end local buffer_severity - if vim.g.coc_service_initialized == 1 then + if is_using_coc() then buffer_severity = from_coc() else buffer_severity = from_nvim_lsp() @@ -119,8 +116,24 @@ function M.update() end end +local has_06 = vim.fn.has('nvim-0.6') == 1 +local links = { + NvimTreeLspDiagnosticsError = has_06 and "DiagnosticError" or "LspDiagnosticsDefaultError", + NvimTreeLspDiagnosticsWarning = has_06 and "DiagnosticWarning" or "LspDiagnosticsDefaultWarning", + NvimTreeLspDiagnosticsInformation = has_06 and "DiagnosticInfo" or "LspDiagnosticsDefaultInformation", + NvimTreeLspDiagnosticsHint = has_06 and "DiagnosticHint" or "LspDiagnosticsDefaultHint", +} + function M.setup(opts) - M.enable = opts.lsp_diagnostics + M.enable = opts.diagnostics.enable + vim.fn.sign_define(sign_names[1][1], { text = opts.diagnostics.icons.error, texthl = sign_names[1][2] }) + vim.fn.sign_define(sign_names[2][1], { text = opts.diagnostics.icons.warning, texthl = sign_names[2][2] }) + vim.fn.sign_define(sign_names[3][1], { text = opts.diagnostics.icons.info, texthl = sign_names[3][2] }) + vim.fn.sign_define(sign_names[4][1], { text = opts.diagnostics.icons.hint, texthl = sign_names[4][2] }) + + for lhs, rhs in pairs(links) do + vim.cmd("hi def link "..lhs.." "..rhs) + end end return M