Hi Bram,

On Sun, Apr 30, 2017 at 5:21 AM, Bram Moolenaar <[email protected]> wrote:
>
> Patch 8.0.0590
> Problem:    Cannot add a context to locations.
> Solution:   Add the "context" entry in location entries. (Yegappan Lakshmanan,
>             closes #1012)
> Files:      src/eval.c, src/proto/quickfix.pro, src/quickfix.c,
>             src/testdir/test_quickfix.vim
>

The setqflist() function only sets the context for the current quickfix list.
Even if the quickfix list number in the stack is specified, it sets the
context for the current list instead of the specified list. I am attaching a
patch to fix this bug. It also includes additional tests.

Note that the getqflist() function works correctly by returning the
context for the specified quickfix list.

- 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].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/quickfix.c b/src/quickfix.c
index 7b07f9358..bc0718855 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4908,11 +4908,11 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int 
action)
     if ((di = dict_find(what, (char_u *)"context", -1)) != NULL)
     {
        typval_T        *ctx;
-       free_tv(qi->qf_lists[qi->qf_curlist].qf_ctx);
+       free_tv(qi->qf_lists[qf_idx].qf_ctx);
        ctx =  alloc_tv();
        if (ctx != NULL)
            copy_tv(&di->di_tv, ctx);
-       qi->qf_lists[qi->qf_curlist].qf_ctx = ctx;
+       qi->qf_lists[qf_idx].qf_ctx = ctx;
     }
 
     return retval;
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index f1fd3c97a..b0a873dc3 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -1804,6 +1804,36 @@ func Xproperty_tests(cchar)
        call setloclist(0, [], 'f')
        call assert_equal({}, getloclist(0, {'context':1}))
     endif
+
+    " Test for changing the context of previous quickfix lists
+    call g:Xsetlist([], 'f')
+    Xexpr "One"
+    Xexpr "Two"
+    Xexpr "Three"
+    call g:Xsetlist([], ' ', {'context' : [1], 'nr' : 1})
+    call g:Xsetlist([], ' ', {'context' : [2], 'nr' : 2})
+    call g:Xsetlist([], ' ', {'context' : [3], 'nr' : 3})
+    call test_garbagecollect_now()
+    let l = g:Xgetlist({'nr' : 1, 'context' : 1})
+    call assert_equal([1], l.context)
+    let l = g:Xgetlist({'nr' : 2, 'context' : 1})
+    call assert_equal([2], l.context)
+    let l = g:Xgetlist({'nr' : 3, 'context' : 1})
+    call assert_equal([3], l.context)
+
+    " Test for changing the context through reference and for garbage
+    " collection of quickfix context
+    let l = ["red"]
+    call g:Xsetlist([], ' ', {'context' : l})
+    call add(l, "blue")
+    let x = g:Xgetlist({'context' : 1})
+    call add(x.context, "green")
+    call assert_equal(["red", "blue", "green"], l)
+    call assert_equal(["red", "blue", "green"], x.context)
+    unlet l
+    call test_garbagecollect_now()
+    let m = g:Xgetlist({'context' : 1})
+    call assert_equal(["red", "blue", "green"], m.context)
 endfunc
 
 func Test_qf_property()

Raspunde prin e-mail lui