Hi,

On Thu, Jun 17, 2021 at 4:06 PM Yorick Peterse <[email protected]>
wrote:

> *Describe the bug*
>
> I sometimes open two windows: A and B. I then open a location list for A.
> This list is formatted using quickfixtextfunc as expect. If I then switch
> to window B, and somehow trigger the updating of the location list for A
> (e.g. using some plugin triggered by wa), the formatting of the location
> list for A is lost.
>
> The reason for this appears as follows: the dictionary passed to the
> formatting function contains a field called winid. When I switch to
> window B, the ID is set to the ID of B. But if B has no location list
> items, there's nothing to format. The bug here seems that vim (and NeoVim,
> which also suffers from this) sets winid to the *currently active*
> window; not the ID of a window a location list belongs to (for every
> location list there is to update).
>
> *To Reproduce*
>
> Create a file called test.vim with the following content:
>
> function! QfFormat(info)
>   let l:what = { 'id': a:info['id'], 'items': 1 }
>   let l:items = getloclist(a:info['winid'], l:what)
>
>   echo l:items
>
>   return ['Custom format']endfunction
> function! Test()
>   let l:winid = 1000
>
>   call setloclist(l:winid, [{ 'bufnr': winbufnr(l:winid), 'lnum': 1, 'col': 
> 1, 'text': 'This is a test', 'type': 'E' }])endfunction
> set quickfixtextfunc=QfFormat
>
> Now start vim using vim -u test.vim. In the buffer, type foo. The text
> doesn't matter and is just to make it easier to see we're in a different
> buffer later on.
>
> Next, run :call Test() | lope. This will populate the location list of
> the first window with some dummy data. Note how in the commandline it
> prints the items used to populate/format the quickfix/location list entries.
>
> Next, run :vne followed by :call Test(). Note how this time the items
> field is an empty list. If our quickfixtextfunc function actually did
> something with the items, this can result in a loss of formatting (as there
> are no entries to process, so the default formatting is used).
>
> *Expected behavior*
>
> When using location lists, quickfixtextfunc should be called in the
> context of the window every location list belongs to; not simply the
> currently active window.
>
> A real-world case where this happens can be seen in the following
> recording. I'm using NeoVim here, but it appears to affect both Vim and
> NeoVim:
>
> [image: asciicast] <https://asciinema.org/a/7wYsVB5L2ehCp5yxxN0AnekpA>
>
> Note how at the very end my location list formatting reverts back to the
> default, instead of the custom formatting seen earlier on.
>
>
>
I can reproduce the problem. Can you try the below patch?

diff --git a/src/quickfix.c b/src/quickfix.c
index ad07a5b4e..653f7f5c0 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4473,7 +4473,12 @@ qf_update_buffer(qf_info_T *qi, qfline_T *old_last)
        int             qf_winid = 0;

        if (IS_LL_STACK(qi))
-           qf_winid = curwin->w_id;
+       {
+           win = qf_find_win_with_loclist(qi);
+           if (win == NULL)
+               return;
+           qf_winid = win->w_id;
+       }

        if (old_last == NULL)
            // set curwin/curbuf to buf and save a few things

Thanks,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7%3D4CO2wL%3DYQK63UW5bHR1JvvXyDhK-ov3qUj_ZSgQRY%2Bg%40mail.gmail.com.

Raspunde prin e-mail lui