mirror of
https://github.com/neovim/neovim.git
synced 2026-07-16 14:11:28 +00:00
fix(diagnostic): stack _tags hl-groups in a single extmark #38654
Problem: Diagnostic highlight groups were applied by iterating and calling `vim.hl.range` for each group individually. That resulted in multiple extmarks with the same priority being created separately, which does not allow `DiagnosticUnnecessary` and `DiagnosticDeprecated` with matching options override `Diagnostic*` styling. Solution: Pass the list of hl-groups to `vim.hl.range` so they are applied together in the correct order.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
|
||||
local command = n.command
|
||||
local clear = n.clear
|
||||
@@ -2041,29 +2042,41 @@ describe('vim.diagnostic', function()
|
||||
it(
|
||||
'shows deprecated and unnecessary highlights in addition to severity-based highlights',
|
||||
function()
|
||||
---@type string[]
|
||||
local result = exec_lua(function()
|
||||
local diagnostic = _G.make_error('Some error', 0, 0, 0, 0, 'source x')
|
||||
local screen = Screen.new(50, 3)
|
||||
screen:set_default_attr_ids({
|
||||
--- DiagnosticUnderlineError + DiagnosticUnnecessary + DiagnosticDeprecated combined
|
||||
[1] = {
|
||||
background = Screen.colors.Red1,
|
||||
strikethrough = true,
|
||||
underline = true,
|
||||
special = Screen.colors.Red1,
|
||||
bold = true,
|
||||
},
|
||||
})
|
||||
|
||||
command('hi DiagnosticUnderlineError guibg=Red gui=underline guisp=Red')
|
||||
command('hi DiagnosticUnnecessary gui=bold')
|
||||
command('hi DiagnosticDeprecated gui=strikethrough')
|
||||
|
||||
exec_lua(function()
|
||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||
vim.diagnostic.config({
|
||||
signs = false,
|
||||
})
|
||||
|
||||
local diagnostic = _G.make_error('Some error', 0, 0, 0, 3, 'source x')
|
||||
diagnostic._tags = {
|
||||
deprecated = true,
|
||||
unnecessary = true,
|
||||
}
|
||||
|
||||
local diagnostics = { diagnostic }
|
||||
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, diagnostics)
|
||||
|
||||
local extmarks = _G.get_underline_extmarks(_G.diagnostic_ns)
|
||||
local hl_groups = vim.tbl_map(function(extmark)
|
||||
return extmark[4].hl_group
|
||||
end, extmarks)
|
||||
return hl_groups
|
||||
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { diagnostic })
|
||||
end)
|
||||
|
||||
eq({
|
||||
'DiagnosticDeprecated',
|
||||
'DiagnosticUnnecessary',
|
||||
'DiagnosticUnderlineError',
|
||||
}, result)
|
||||
screen:expect([[
|
||||
{1:^1st} line of text |
|
||||
2nd line of text |
|
||||
|
|
||||
]])
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user