[vim/vim] Duplicate/missing quickfix lines when combining caddexpr and multi-line errorformat (%A,%Z) (#5735)

23 views
Skip to first unread message

David Briscoe

unread,
Mar 5, 2020, 2:51:04 PM3/5/20
to vim/vim, Subscribed

Description

If 'errorformat' uses multi-line messages (%A, %C, %Z) and output is added
line-by-line with :caddexpr, vim omits lines and adds duplicate lines to the
quickfix. It's unsurprising that vim is unable to parse the multiple lines when
it only receives the first one, but I wouldn't expect it to repeat output. I'd
also hope it wouldn't drop output.

Minimal reproduction

c:/scratch/test.vim

function! Test_multiline_efm()
    let output = [
            \   '[python3 -t scratch\mytest.py]'
            \ , 'hello'
            \ , 'Traceback (most recent call last):'
            \ , '  File "scratch\mytest.py", line 2, in <module>'
            \ , '    raise Exception("bad")'
            \ , 'Exception: bad'
            \ , '[Finished in 0 seconds with code 1]'
            \ , 'placeholder 1'
            \ , 'placeholder 2'
            \ , 'placeholder 3'
            \ , 'placeholder 4'
            \ , 'placeholder 5'
            \]


    " Multi-line (%A, %Z) causes duplicated and missing lines.
    let &efm = '%A%\s%#File "%f"\, line %l%.%#,%Z    %m'
    " Same with set:
    set errorformat=%A%\\s%#File\ \"%f\"\\,\ line\ %l\\,%.%#,%Z\ \ \ \ %m

    " Single-line is fine, but obviously can't match error message to line since
    " they're on separate lines.
    "~ let &efm = '%\s%#File "%f"\, line %l\,%.%#,    %m'

    call setqflist([])

    " Add output all at once -- works wonderfully:
    " || [python3 -t scratch\mytest.py]
    " || hello
    " || Traceback (most recent call last):
    " scratch/mytest.py|2|  raise Exception("bad")
    " || Exception: bad
    " || [Finished in 0 seconds with code 1]
    " || placeholder 1
    " || placeholder 2
    " || placeholder 3
    " || placeholder 4
    " || placeholder 5
    "~ caddexpr output

    " Add output one at a time -- omits and duplicates lines:
    " || [python3 -t scratch\mytest.py]
    " || hello
    " || Traceback (most recent call last):
    " scratch/mytest.py|2|  raise Exception("bad")
    " || [python3 -t scratch\mytest.py]
    " || hello
    " || Traceback (most recent call last):
    " scratch/mytest.py|2| 
    " || placeholder 3
    " || placeholder 4
    " || placeholder 5
    for line in output
        caddexpr line
        " Not sure if this should work better, but I can't figure out how to
        " make it work.
        "~ call setqflist([{'text' : line}], 'a', {'efm' : &efm})
    endfor
endf

copen
call Test_multiline_efm()
> gvim --clean +"source c:/scratch/test.vim"

Expected

I would expect the output to not duplicate lines and to include the omitted lines:

|| [python3 -t scratch\mytest.py]
|| hello
|| Traceback (most recent call last):
scratch/mytest.py|2|
||     raise Exception("bad")
|| Exception: bad
|| [Finished in 0 seconds with code 1]
|| placeholder 1
|| placeholder 2
|| placeholder 3
|| placeholder 4
|| placeholder 5

Instead, it omits 4 lines that appear after the %Z-matching line. If I insert another
placeholder line before 'raise Exception' (so there's a non-matching line
between %A and %Z), then it outputs as desired. So it seems like matching %A
and then matching %Z on the next input triggers this bad behaviour
.

Environment

  • OS: Windows 10
  • Vim: Vi IMproved 8.2 (2019 Dec 12, compiled Feb 26 2020 23:02:14)
    MS-Windows 64-bit GUI version with OLE support
    Included patches: 1-324
  • gvim

Context

I'm using skywind3000/asyncrun.vim which adds uses vim jobs to run commands in
the background and add their output to the quickfix as it's received. It uses
caddexpr to add the lines.

I have a python compiler script that uses multi-line output to capture the
traceback and add it to the quickfix.

Using the two of these in combination causes the quickfix to be populated with
duplicate lines and some lines are missing.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

bfrg

unread,
Mar 5, 2020, 4:01:27 PM3/5/20
to vim/vim, Subscribed

If you close and then reopen the quickfix window it will show the correct output. It looks like it's parsed correctly but just not properly displayed in the quickfix window (at first).

Regarding setqflist():

" Line by line
for line in output
    call setqflist([], 'a', {'lines': [line], 'efm' : &efm})
endfor

" Or all lines at once
call setqflist([], 'a', {'lines': output, 'efm' : &errorformat})

Both give the same result. You can check the current quickfix list with getqflist():

[
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "[python3 -t scratch\\mytest.py]"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "hello"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "Traceback (most recent call last):"
	},
	{
		"lnum": 2,
		"bufnr": 4,
		"col": 0,
		"pattern": "",
		"valid": 1,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "\nraise Exception(\"bad\")"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "Exception: bad"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "[Finished in 0 seconds with code 1]"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "placeholder 1"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "placeholder 2"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "placeholder 3"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "placeholder 4"
	},
	{
		"lnum": 0,
		"bufnr": 0,
		"col": 0,
		"pattern": "",
		"valid": 0,
		"vcol": 0,
		"nr": -1,
		"type": "",
		"module": "",
		"text": "placeholder 5"
	}
]

David Briscoe

unread,
Mar 5, 2020, 6:42:37 PM3/5/20
to vim/vim, Subscribed

If you close and then reopen the quickfix window

Looks like you don't even need to close the quickfix. Looks like :copen fixes it regardless!


Thanks for clearing up setqflist. Does that mean that if I want to pass {what}, I should always pass an empty list for {list}?

Maybe that's implied by this line from :help setqflist:

When {what} is not present, use the items in {list}.

Although it wasn't clear to me that this line no longer applies:

If you supply an empty {list}, the quickfix list will be cleared.

Yegappan Lakshmanan

unread,
Mar 5, 2020, 9:59:36 PM3/5/20
to vim_dev, reply+ACY5DGHPWVUEHBZ2VV...@reply.github.com, vim/vim, Subscribed
Hi,

On Thu, Mar 5, 2020 at 3:42 PM David Briscoe <vim-dev...@256bit.org> wrote:

If you close and then reopen the quickfix window

Looks like you don't even need to close the quickfix. Looks like :copen fixes it regardless!


Thanks for clearing up setqflist. Does that mean that if I want to pass {what}, I should always pass an empty list for {list}?


If you want to create or add items to a quickfix list, then you can pass the items
either through the {list} argument or using the 'items' key in {what}. The {list}
argument is kept for backward compatibility reasons. When setqflist() was
introduced, it supported only the {list} argument. The {what} argument to
modify the various quickfix attributes was added later.

If you supply the {what} argument, then the {list} argument will be ignored.

Maybe that's implied by this line from :help setqflist:

When {what} is not present, use the items in {list}.

Although it wasn't clear to me that this line no longer applies:

If you supply an empty {list}, the quickfix list will be cleared.


This applies only when the {what} argument is not supplied.

Regards,
Yegappan
 

vim-dev ML

unread,
Mar 5, 2020, 10:00:11 PM3/5/20
to vim/vim, vim-dev ML, Your activity
Hi,

On Thu, Mar 5, 2020 at 3:42 PM David Briscoe <vim-dev...@256bit.org>
wrote:

> If you close and then reopen the quickfix window
>
> Looks like you don't even need to close the quickfix. Looks like :copen
> fixes it regardless!
> ------------------------------

>
> Thanks for clearing up setqflist. Does that mean that if I want to pass
> {what}, I should always pass an empty list for {list}?
>

If you want to create or add items to a quickfix list, then you can pass
the items
either through the {list} argument or using the 'items' key in {what}. The
{list}
argument is kept for backward compatibility reasons. When setqflist() was
introduced, it supported only the {list} argument. The {what} argument to
modify the various quickfix attributes was added later.

If you supply the {what} argument, then the {list} argument will be ignored.

Maybe that's implied by this line from :help setqflist:
>
> When {what} is not present, use the items in {list}.
>
> Although it wasn't clear to me that this line no longer applies:
>
> If you supply an empty {list}, the quickfix list will be cleared.
>
>
> This applies only when the {what} argument is not supplied.

Regards,
Yegappan

bfrg

unread,
Nov 14, 2020, 7:35:37 AM11/14/20
to vim/vim, vim-dev ML, Comment

I think this was fixed in 2ce7790. Or at least I can't reproduce it anymore.

@idbrii Maybe you can also give it a try.


You are receiving this because you commented.

Christian Brabandt

unread,
Nov 16, 2020, 2:32:24 AM11/16/20
to vim/vim, vim-dev ML, Comment

Closed #5735.


You are receiving this because you commented.

David Briscoe

unread,
Jan 8, 2021, 4:16:13 PM1/8/21
to vim/vim, vim-dev ML, Comment

Sorry for the delay. Confirmed fixed for me. Thanks!


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages