mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(diagnostic): use sign priority for severity_sort #15785
Rather than relying on the order in which signs are placed to dictate the order in which they are displayed, explicitly set the priority of the sign according to the severity of the diagnostic and the value of severity_sort. If severity_sort is false or unset then all signs use the same priority.
This commit is contained in:
parent
cb51a1b615
commit
187e3a3b7e
@ -187,6 +187,11 @@ can be customized using the following: >
|
||||
sign define DiagnosticSignInfo text=I texthl=DiagnosticSignInfo linehl= numhl=
|
||||
sign define DiagnosticSignHint text=H texthl=DiagnosticSignHint linehl= numhl=
|
||||
|
||||
When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
|
||||
priority of each sign depends on the severity of the associated diagnostic.
|
||||
Otherwise, all signs have the same priority (the value of the "priority"
|
||||
option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
|
||||
|
||||
==============================================================================
|
||||
EVENTS *diagnostic-events*
|
||||
|
||||
|
@ -806,16 +806,35 @@ function M._set_signs(namespace, bufnr, diagnostics, opts)
|
||||
}
|
||||
|
||||
bufnr = get_bufnr(bufnr)
|
||||
opts = get_resolved_options({ signs = opts }, namespace, bufnr).signs
|
||||
opts = get_resolved_options({ signs = opts }, namespace, bufnr)
|
||||
|
||||
if opts and opts.severity then
|
||||
diagnostics = filter_by_severity(opts.severity, diagnostics)
|
||||
if opts.signs and opts.signs.severity then
|
||||
diagnostics = filter_by_severity(opts.signs.severity, diagnostics)
|
||||
end
|
||||
|
||||
local ns = get_namespace(namespace)
|
||||
|
||||
define_default_signs()
|
||||
|
||||
-- 10 is the default sign priority when none is explicitly specified
|
||||
local priority = opts.signs and opts.signs.priority or 10
|
||||
local get_priority
|
||||
if opts.severity_sort then
|
||||
if type(opts.severity_sort) == "table" and opts.severity_sort.reverse then
|
||||
get_priority = function(severity)
|
||||
return priority + (severity - vim.diagnostic.severity.ERROR)
|
||||
end
|
||||
else
|
||||
get_priority = function(severity)
|
||||
return priority + (vim.diagnostic.severity.HINT - severity)
|
||||
end
|
||||
end
|
||||
else
|
||||
get_priority = function()
|
||||
return priority
|
||||
end
|
||||
end
|
||||
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
vim.fn.sign_place(
|
||||
0,
|
||||
@ -823,7 +842,7 @@ function M._set_signs(namespace, bufnr, diagnostics, opts)
|
||||
sign_highlight_map[diagnostic.severity],
|
||||
bufnr,
|
||||
{
|
||||
priority = opts and opts.priority,
|
||||
priority = get_priority(diagnostic.severity),
|
||||
lnum = diagnostic.lnum + 1
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user