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.
This commit is contained in:
kiyan
2021-10-10 11:41:57 +02:00
parent 64c31aaec7
commit 94b8604e86
6 changed files with 73 additions and 34 deletions

View File

@@ -61,7 +61,15 @@ require'nvim-tree'.setup {
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
update_cwd = false, update_cwd = false,
-- show lsp diagnostics in the signcolumn -- 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 the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
update_focused_file = { update_focused_file = {
-- enables the feature -- enables the feature
@@ -167,12 +175,6 @@ let g:nvim_tree_icons = {
\ 'empty_open': "", \ 'empty_open': "",
\ 'symlink': "", \ 'symlink': "",
\ 'symlink_open': "", \ 'symlink_open': "",
\ },
\ 'lsp': {
\ 'hint': "",
\ 'info': "",
\ 'warning': "",
\ 'error': "",
\ } \ }
\ } \ }

View File

@@ -78,7 +78,15 @@ function.
open_on_tab = false, open_on_tab = false,
hijack_cursor = false, hijack_cursor = false,
update_cwd = false, update_cwd = false,
lsp_diagnostics = false, diagnostics = {
enable = false,
icons = {
hint = "",
info = "",
warning = "",
error = "",
}
},
update_focused_file = { update_focused_file = {
enable = false, enable = false,
update_cwd = false, update_cwd = false,
@@ -196,10 +204,23 @@ Here is a list of the options available in the setup call:
type: `{string}` type: `{string}`
default: `{}` default: `{}`
*nvim-tree.lsp_diagnostics* *nvim-tree.diagnostics*
- |lsp_diagnostics|: show lsp diagnostics in the signcolumn - |diagnostics|: show lsp diagnostics in the signcolumn
type: `boolean`
default: false - |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* *nvim-tree.view*
- |view|: window / buffer setup - |view|: window / buffer setup

View File

@@ -7,6 +7,7 @@ local colors = require'nvim-tree.colors'
local renderer = require'nvim-tree.renderer' local renderer = require'nvim-tree.renderer'
local fs = require'nvim-tree.fs' local fs = require'nvim-tree.fs'
local view = require'nvim-tree.view' local view = require'nvim-tree.view'
local utils = require'nvim-tree.utils'
local _config = { local _config = {
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1, is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
@@ -416,7 +417,6 @@ local DEFAULT_OPTS = {
auto_close = false, auto_close = false,
hijack_cursor = false, hijack_cursor = false,
update_cwd = false, update_cwd = false,
lsp_diagnostics = false,
update_focused_file = { update_focused_file = {
enable = false, enable = false,
update_cwd = false, update_cwd = false,
@@ -427,6 +427,15 @@ local DEFAULT_OPTS = {
cmd = nil, cmd = nil,
args = {} args = {}
}, },
diagnostics = {
enable = false,
icons = {
hint = "",
info = "",
warning = "",
error = "",
}
},
} }
function M.setup(conf) function M.setup(conf)
@@ -439,7 +448,7 @@ function M.setup(conf)
_config.open_on_setup = opts.open_on_setup _config.open_on_setup = opts.open_on_setup
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup
if type(opts.update_to_buf_dir) == "boolean" then 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 = { _config.update_to_buf_dir = {
enable = opts.update_to_buf_dir, enable = opts.update_to_buf_dir,
auto_open = 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 _config.update_to_buf_dir = opts.update_to_buf_dir
end 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.colors'.setup()
require'nvim-tree.view'.setup(opts.view or {}) require'nvim-tree.view'.setup(opts.view or {})
require'nvim-tree.diagnostics'.setup(opts) require'nvim-tree.diagnostics'.setup(opts)

View File

@@ -70,10 +70,6 @@ local function get_links()
FileDeleted = 'NvimTreeGitDeleted', FileDeleted = 'NvimTreeGitDeleted',
Popup = 'Normal', Popup = 'Normal',
GitIgnored = 'Comment', GitIgnored = 'Comment',
LspDiagnosticsError = "LspDiagnosticsDefaultError",
LspDiagnosticsWarning = "LspDiagnosticsDefaultWarning",
LspDiagnosticsInformation = "LspDiagnosticsDefaultInformation",
LspDiagnosticsHint = "LspDiagnosticsDefaultHint",
StatusLine = "StatusLine", StatusLine = "StatusLine",
StatusLineNC = "StatusLineNC", StatusLineNC = "StatusLineNC",
SignColumn = 'Normal', SignColumn = 'Normal',

View File

@@ -24,12 +24,6 @@ function M.get_icon_state()
symlink = "", symlink = "",
symlink_open = "", symlink_open = "",
}, },
lsp = {
hint = "",
info = "",
warning = "",
error = "",
},
} }
local user_icons = vim.g.nvim_tree_icons local user_icons = vim.g.nvim_tree_icons

View File

@@ -1,8 +1,6 @@
local a = vim.api local a = vim.api
local utils = require'nvim-tree.utils' local utils = require'nvim-tree.utils'
local view = require'nvim-tree.view' 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 get_diagnostics = vim.lsp.diagnostic.get_all
local M = {} local M = {}
@@ -25,11 +23,6 @@ local sign_names = {
{ "NvimTreeSignHint", "NvimTreeLspDiagnosticsHint" }, { "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 signs = {}
local function add_sign(linenr, severity) local function add_sign(linenr, severity)
@@ -75,7 +68,7 @@ local function from_coc()
local severity_list = diagnostics[bufname] or {} local severity_list = diagnostics[bufname] or {}
table.insert(severity_list, severity) table.insert(severity_list, severity)
diagnostics[bufname] = severity_list diagnostics[bufname] = severity_list
end end
for bufname, severity_list in pairs(diagnostics) do for bufname, severity_list in pairs(diagnostics) do
if not buffer_severity[bufname] then if not buffer_severity[bufname] then
@@ -87,12 +80,16 @@ local function from_coc()
return buffer_severity return buffer_severity
end end
local function is_using_coc()
return vim.g.coc_service_initialized == 1
end
function M.update() function M.update()
if not M.enable then if not M.enable then
return return
end end
local buffer_severity local buffer_severity
if vim.g.coc_service_initialized == 1 then if is_using_coc() then
buffer_severity = from_coc() buffer_severity = from_coc()
else else
buffer_severity = from_nvim_lsp() buffer_severity = from_nvim_lsp()
@@ -119,8 +116,24 @@ function M.update()
end end
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) 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 end
return M return M