feat(diagnostic): fromqflist({merge_lines}) #37416

Problem:
`vim.diagnostic.fromqflist` ignores lines that are `item.valid == 0` (see
`getqflist`). Many qflists have messages that span multiple lines, which look
like this:

    collection/src/Modelling/CdOd/Central.hs|496 col 80| error: [GHC-83865]
    ||     • Couldn't match expected type: InstanceWithForm
    ||                                       (FilePath
    ||                                        -> SelectValidCdInstWithForm
    ...

calling `vim.diagnostic.fromqflist(vim.fn.getqflist)` gets a diagnostic message
like this:

    error: [GHC-83865]

only the first line is kept, but often, the remaing lines are useful as well.

Solution:
Introduce `merge_lines` option, which "squashes" lines from invalid qflist items
into the error message of the previous valid item, so that we get this
diagnostic message instead:

    error: [GHC-83865]
         • Couldn't match expected type: InstanceWithForm
                                           (FilePath
                                            -> SelectValidCdInstWithForm
This commit is contained in:
Dmytro Pletenskyi
2026-02-14 12:07:01 +01:00
committed by GitHub
parent 0864939cc5
commit 01666aae64
4 changed files with 121 additions and 6 deletions

View File

@@ -4089,6 +4089,98 @@ describe('vim.diagnostic', function()
end)
eq(result[1], result[2])
end)
it('merge_lines=true merges continuation lines', function()
local result = exec_lua(function()
local qflist = {
{
bufnr = 1,
lnum = 10,
col = 5,
end_lnum = 10,
end_col = 10,
text = 'error: [GHC-83865]',
type = 'E',
nr = 0,
valid = 1,
},
{
bufnr = 1,
lnum = 0,
col = 0,
end_lnum = 0,
end_col = 0,
text = " Couldn't match expected type",
type = '',
nr = 0,
valid = 0,
},
{
bufnr = 1,
lnum = 0,
col = 0,
end_lnum = 0,
end_col = 0,
text = ' with actual type',
type = '',
nr = 0,
valid = 0,
},
{
bufnr = 1,
lnum = 20,
col = 1,
end_lnum = 20,
end_col = 5,
text = 'warning: unused',
type = 'W',
nr = 0,
valid = 1,
},
}
return vim.diagnostic.fromqflist(qflist, { merge_lines = true })
end)
eq(2, #result)
eq(
"error: [GHC-83865]\n Couldn't match expected type\n with actual type",
result[1].message
)
eq('warning: unused', result[2].message)
end)
it('merge_lines=false ignores continuation lines', function()
local result = exec_lua(function()
local qflist = {
{
bufnr = 1,
lnum = 10,
col = 5,
end_lnum = 10,
end_col = 10,
text = 'error: main',
type = 'E',
nr = 0,
valid = 1,
},
{
bufnr = 1,
lnum = 0,
col = 0,
end_lnum = 0,
end_col = 0,
text = 'continuation',
type = '',
nr = 0,
valid = 0,
},
}
return vim.diagnostic.fromqflist(qflist)
end)
eq(1, #result)
eq('error: main', result[1].message)
end)
end)
describe('status()', function()