diff options
| author | Dmytro Pletenskyi <32138582+ph1losof@users.noreply.github.com> | 2026-02-14 12:07:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-14 06:07:01 -0500 |
| commit | 01666aae64d15d88896f99bc064c7b2b4c2ed276 (patch) | |
| tree | 230c6a134c72522e028683b8eaa5ae881e07958d /runtime/lua/vim/diagnostic.lua | |
| parent | 0864939cc58d3f0af1a88a4baf34ed6b2a2c53ed (diff) | |
| download | rneovim-01666aae64d15d88896f99bc064c7b2b4c2ed276.tar.gz rneovim-01666aae64d15d88896f99bc064c7b2b4c2ed276.tar.bz2 rneovim-01666aae64d15d88896f99bc064c7b2b4c2ed276.zip | |
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
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
| -rw-r--r-- | runtime/lua/vim/diagnostic.lua | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 0214b02cf0..8ae4eda3b7 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -2913,14 +2913,27 @@ function M.toqflist(diagnostics) return list end +--- Configuration table with the following keys: +--- @class vim.diagnostic.fromqflist.Opts +--- @inlinedoc +--- +--- When true, items with valid=0 are appended to the previous valid item's +--- message with a newline. (default: false) +--- @field merge_lines? boolean + --- Convert a list of quickfix items to a list of diagnostics. --- ----@param list table[] List of quickfix items from |getqflist()| or |getloclist()|. +---@param list vim.quickfix.entry[] List of quickfix items from |getqflist()| or |getloclist()|. +---@param opts? vim.diagnostic.fromqflist.Opts ---@return vim.Diagnostic[] -function M.fromqflist(list) +function M.fromqflist(list, opts) vim.validate('list', list, 'table') + opts = opts or {} + local merge = opts.merge_lines + local diagnostics = {} --- @type vim.Diagnostic[] + local last_diag --- @type vim.Diagnostic? for _, item in ipairs(list) do if item.valid == 1 then local lnum = math.max(0, item.lnum - 1) @@ -2929,7 +2942,7 @@ function M.fromqflist(list) local end_col = item.end_col > 0 and (item.end_col - 1) or col local code = item.nr > 0 and item.nr or nil local severity = item.type ~= '' and M.severity[item.type:upper()] or M.severity.ERROR - diagnostics[#diagnostics + 1] = { + local diag = { bufnr = item.bufnr, lnum = lnum, col = col, @@ -2939,6 +2952,10 @@ function M.fromqflist(list) message = item.text, code = code, } + diagnostics[#diagnostics + 1] = diag + last_diag = diag + elseif merge and last_diag then + last_diag.message = last_diag.message .. '\n' .. item.text end end return diagnostics |