Skip to content

Commit 7adf06f

Browse files
committed
patch 8.0.1006: quickfix list changes when parsing text with 'erroformat'
Problem: Cannot parse text with 'erroformat' without changing a quickfix list. Solution: Add the "text" argument to getqflist(). (Yegappan Lakshmanan)
1 parent 4ab7968 commit 7adf06f

6 files changed

Lines changed: 92 additions & 10 deletions

File tree

runtime/doc/eval.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,6 +4616,11 @@ getqflist([{what}]) *getqflist()*
46164616
nr get information for this quickfix list; zero
46174617
means the current quickfix list and '$' means
46184618
the last quickfix list
4619+
text use 'errorformat' to extract items from the
4620+
text and return the resulting entries. The
4621+
value can be a string with one line or a list
4622+
with multiple lines. The current quickfix list
4623+
is not modified.
46194624
title get the list title
46204625
winid get the |window-ID| (if opened)
46214626
all all of the above quickfix properties
@@ -4624,6 +4629,9 @@ getqflist([{what}]) *getqflist()*
46244629
To get the number of lists in the quickfix stack, set 'nr' to
46254630
'$' in {what}. The 'nr' value in the returned dictionary
46264631
contains the quickfix stack size.
4632+
When 'text' is specified, all the other items are ignored. The
4633+
returned dictionary contains the entry 'items' with the list
4634+
of entries.
46274635
In case of error processing {what}, an empty dictionary is
46284636
returned.
46294637

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4810,7 +4810,7 @@ get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv)
48104810
{
48114811
if (rettv_list_alloc(rettv) == OK)
48124812
if (is_qf || wp != NULL)
4813-
(void)get_errorlist(wp, -1, rettv->vval.v_list);
4813+
(void)get_errorlist(NULL, wp, -1, rettv->vval.v_list);
48144814
}
48154815
else
48164816
{

src/proto/quickfix.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void ex_cc(exarg_T *eap);
2121
void ex_cnext(exarg_T *eap);
2222
void ex_cfile(exarg_T *eap);
2323
void ex_vimgrep(exarg_T *eap);
24-
int get_errorlist(win_T *wp, int qf_idx, list_T *list);
24+
int get_errorlist(qf_info_T *qi, win_T *wp, int qf_idx, list_T *list);
2525
int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict);
2626
int set_errorlist(win_T *wp, list_T *list, int action, char_u *title, dict_T *what);
2727
int set_ref_in_quickfix(int copyID);

src/quickfix.c

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ qf_free_items(qf_info_T *qi, int idx)
27622762
{
27632763
qfp = qfl->qf_start;
27642764
qfpnext = qfp->qf_next;
2765-
if (qfl->qf_title != NULL && !stop)
2765+
if (!stop)
27662766
{
27672767
vim_free(qfp->qf_text);
27682768
stop = (qfp == qfpnext);
@@ -4556,20 +4556,24 @@ unload_dummy_buffer(buf_T *buf, char_u *dirname_start)
45564556
* If qf_idx is -1, use the current list. Otherwise, use the specified list.
45574557
*/
45584558
int
4559-
get_errorlist(win_T *wp, int qf_idx, list_T *list)
4559+
get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list)
45604560
{
4561-
qf_info_T *qi = &ql_info;
4561+
qf_info_T *qi = qi_arg;
45624562
dict_T *dict;
45634563
char_u buf[2];
45644564
qfline_T *qfp;
45654565
int i;
45664566
int bufnum;
45674567

4568-
if (wp != NULL)
4568+
if (qi == NULL)
45694569
{
4570-
qi = GET_LOC_LIST(wp);
4571-
if (qi == NULL)
4572-
return FAIL;
4570+
qi = &ql_info;
4571+
if (wp != NULL)
4572+
{
4573+
qi = GET_LOC_LIST(wp);
4574+
if (qi == NULL)
4575+
return FAIL;
4576+
}
45734577
}
45744578

45754579
if (qf_idx == -1)
@@ -4627,6 +4631,45 @@ enum {
46274631
QF_GETLIST_ALL = 0xFF
46284632
};
46294633

4634+
/*
4635+
* Parse text from 'di' and return the quickfix list items
4636+
*/
4637+
static int
4638+
qf_get_list_from_text(dictitem_T *di, dict_T *retdict)
4639+
{
4640+
int status = FAIL;
4641+
qf_info_T *qi;
4642+
4643+
/* Only string and list values are supported */
4644+
if ((di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
4645+
|| (di->di_tv.v_type == VAR_LIST
4646+
&& di->di_tv.vval.v_list != NULL))
4647+
{
4648+
qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
4649+
if (qi != NULL)
4650+
{
4651+
vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
4652+
qi->qf_refcount++;
4653+
4654+
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
4655+
TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
4656+
{
4657+
list_T *l = list_alloc();
4658+
if (l != NULL)
4659+
{
4660+
(void)get_errorlist(qi, NULL, 0, l);
4661+
dict_add_list(retdict, "items", l);
4662+
status = OK;
4663+
}
4664+
qf_free(qi, 0);
4665+
}
4666+
free(qi);
4667+
}
4668+
}
4669+
4670+
return status;
4671+
}
4672+
46304673
/*
46314674
* Return quickfix/location list details (title) as a
46324675
* dictionary. 'what' contains the details to return. If 'list_idx' is -1,
@@ -4641,6 +4684,9 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
46414684
dictitem_T *di;
46424685
int flags = QF_GETLIST_NONE;
46434686

4687+
if ((di = dict_find(what, (char_u *)"text", -1)) != NULL)
4688+
return qf_get_list_from_text(di, retdict);
4689+
46444690
if (wp != NULL)
46454691
{
46464692
qi = GET_LOC_LIST(wp);
@@ -4726,7 +4772,7 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
47264772
list_T *l = list_alloc();
47274773
if (l != NULL)
47284774
{
4729-
(void)get_errorlist(wp, qf_idx, l);
4775+
(void)get_errorlist(qi, NULL, qf_idx, l);
47304776
dict_add_list(retdict, "items", l);
47314777
}
47324778
else

src/testdir/test_quickfix.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,3 +2519,29 @@ func Test_add_qf()
25192519
call XaddQf_tests('c')
25202520
call XaddQf_tests('l')
25212521
endfunc
2522+
2523+
" Test for getting the quickfix list items from some text without modifying
2524+
" the quickfix stack
2525+
func XgetListFromText(cchar)
2526+
call s:setup_commands(a:cchar)
2527+
call g:Xsetlist([], 'f')
2528+
2529+
let l = g:Xgetlist({'text' : "File1:10:Line10"}).items
2530+
call assert_equal(1, len(l))
2531+
call assert_equal('Line10', l[0].text)
2532+
2533+
let l = g:Xgetlist({'text' : ["File2:20:Line20", "File2:30:Line30"]}).items
2534+
call assert_equal(2, len(l))
2535+
call assert_equal(30, l[1].lnum)
2536+
2537+
call assert_equal({}, g:Xgetlist({'text' : 10}))
2538+
call assert_equal({}, g:Xgetlist({'text' : []}))
2539+
2540+
" Make sure that the quickfix stack is not modified
2541+
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
2542+
endfunc
2543+
2544+
func Test_get_list_from_text()
2545+
call XgetListFromText('c')
2546+
call XgetListFromText('l')
2547+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1006,
772774
/**/
773775
1005,
774776
/**/

0 commit comments

Comments
 (0)