* feat(#1917): add renderer.highlight_diagnostics * feat(#1917): add renderer.highlight_diagnostics * feat(#1917): add enderer.icons.diagnostics_placement * feat(#1917): add renderer.icons.show.diagnostics * feat(#1917): document highlight overrides
This commit is contained in:
committed by
GitHub
parent
28c3980b25
commit
323f65cb9c
@@ -5,24 +5,7 @@ local log = require "nvim-tree.log"
|
||||
|
||||
local M = {}
|
||||
|
||||
local GROUP = "NvimTreeDiagnosticSigns"
|
||||
|
||||
local severity_levels = { Error = 1, Warning = 2, Information = 3, Hint = 4 }
|
||||
local sign_names = {
|
||||
{ "NvimTreeSignError", "NvimTreeLspDiagnosticsError" },
|
||||
{ "NvimTreeSignWarning", "NvimTreeLspDiagnosticsWarning" },
|
||||
{ "NvimTreeSignInformation", "NvimTreeLspDiagnosticsInformation" },
|
||||
{ "NvimTreeSignHint", "NvimTreeLspDiagnosticsHint" },
|
||||
}
|
||||
|
||||
local function add_sign(linenr, severity)
|
||||
local buf = view.get_bufnr()
|
||||
if not vim.api.nvim_buf_is_valid(buf) or not vim.api.nvim_buf_is_loaded(buf) then
|
||||
return
|
||||
end
|
||||
local sign_name = sign_names[severity][1]
|
||||
vim.fn.sign_place(0, GROUP, sign_name, buf, { lnum = linenr, priority = 2 })
|
||||
end
|
||||
|
||||
local function from_nvim_lsp()
|
||||
local buffer_severity = {}
|
||||
@@ -85,14 +68,6 @@ local function is_using_coc()
|
||||
return vim.g.coc_service_initialized == 1
|
||||
end
|
||||
|
||||
function M.clear()
|
||||
if not M.enable or not view.is_buf_valid(view.get_bufnr()) then
|
||||
return
|
||||
end
|
||||
|
||||
vim.fn.sign_unplace(GROUP)
|
||||
end
|
||||
|
||||
function M.update()
|
||||
if not M.enable or not core.get_explorer() or not view.is_buf_valid(view.get_bufnr()) then
|
||||
return
|
||||
@@ -108,8 +83,6 @@ function M.update()
|
||||
buffer_severity = from_nvim_lsp()
|
||||
end
|
||||
|
||||
M.clear()
|
||||
|
||||
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())
|
||||
for _, node in pairs(nodes_by_line) do
|
||||
node.diag_status = nil
|
||||
@@ -129,26 +102,18 @@ function M.update()
|
||||
then
|
||||
log.line("diagnostics", " matched fold node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
elseif nodepath == bufpath then
|
||||
log.line("diagnostics", " matched file node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
log.profile_end(profile)
|
||||
require("nvim-tree.renderer").draw()
|
||||
end)
|
||||
end
|
||||
|
||||
local links = {
|
||||
NvimTreeLspDiagnosticsError = "DiagnosticError",
|
||||
NvimTreeLspDiagnosticsWarning = "DiagnosticWarn",
|
||||
NvimTreeLspDiagnosticsInformation = "DiagnosticInfo",
|
||||
NvimTreeLspDiagnosticsHint = "DiagnosticHint",
|
||||
}
|
||||
|
||||
function M.setup(opts)
|
||||
M.enable = opts.diagnostics.enable
|
||||
M.debounce_delay = opts.diagnostics.debounce_delay
|
||||
@@ -160,14 +125,6 @@ function M.setup(opts)
|
||||
|
||||
M.show_on_dirs = opts.diagnostics.show_on_dirs
|
||||
M.show_on_open_dirs = opts.diagnostics.show_on_open_dirs
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user