]> granicus.if.org Git - vim/commitdiff
patch 8.0.1006: quickfix list changes when parsing text with 'erroformat' v8.0.1006
authorBram Moolenaar <Bram@vim.org>
Sun, 27 Aug 2017 13:23:41 +0000 (15:23 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 27 Aug 2017 13:23:41 +0000 (15:23 +0200)
Problem:    Cannot parse text with 'erroformat' without changing a quickfix
            list.
Solution:   Add the "text" argument to getqflist(). (Yegappan Lakshmanan)

runtime/doc/eval.txt
src/evalfunc.c
src/proto/quickfix.pro
src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index 37e849c90a9c1b3b3528fcdf3c7da28d08c7c578..a1a76f91435755647591c76adf04e9ffc4891362 100644 (file)
@@ -4616,6 +4616,11 @@ getqflist([{what}])                                      *getqflist()*
                        nr      get information for this quickfix list; zero
                                means the current quickfix list and '$' means
                                the last quickfix list
+                       text    use 'errorformat' to extract items from the
+                               text and return the resulting entries. The
+                               value can be a string with one line or a list
+                               with multiple lines. The current quickfix list
+                               is not modified.
                        title   get the list title
                        winid   get the |window-ID| (if opened)
                        all     all of the above quickfix properties
@@ -4624,6 +4629,9 @@ getqflist([{what}])                                       *getqflist()*
                To get the number of lists in the quickfix stack, set 'nr' to
                '$' in {what}. The 'nr' value in the returned dictionary
                contains the quickfix stack size.
+               When 'text' is specified, all the other items are ignored. The
+               returned dictionary contains the entry 'items' with the list
+               of entries.
                In case of error processing {what}, an empty dictionary is
                returned.
 
index c900b532c21726adc5e4c9cca785f8898db5bbea..d11d96db941372bc2cd1269a1718fd61ca2dec0b 100644 (file)
@@ -4810,7 +4810,7 @@ get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, typval_T *rettv)
     {
        if (rettv_list_alloc(rettv) == OK)
            if (is_qf || wp != NULL)
-               (void)get_errorlist(wp, -1, rettv->vval.v_list);
+               (void)get_errorlist(NULL, wp, -1, rettv->vval.v_list);
     }
     else
     {
index 4418cc47b89645b8336897f7b1c5adc05e3d6551..ad6ad34330d8675c03bb7a03d1d040e81effdf67 100644 (file)
@@ -21,7 +21,7 @@ void ex_cc(exarg_T *eap);
 void ex_cnext(exarg_T *eap);
 void ex_cfile(exarg_T *eap);
 void ex_vimgrep(exarg_T *eap);
-int get_errorlist(win_T *wp, int qf_idx, list_T *list);
+int get_errorlist(qf_info_T *qi, win_T *wp, int qf_idx, list_T *list);
 int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict);
 int set_errorlist(win_T *wp, list_T *list, int action, char_u *title, dict_T *what);
 int set_ref_in_quickfix(int copyID);
index 42077c2a3c8544effb43d03467305a9c22496d21..71270d9b9712a24911925dde05f7f9af9911f440 100644 (file)
@@ -2762,7 +2762,7 @@ qf_free_items(qf_info_T *qi, int idx)
     {
        qfp = qfl->qf_start;
        qfpnext = qfp->qf_next;
-       if (qfl->qf_title != NULL && !stop)
+       if (!stop)
        {
            vim_free(qfp->qf_text);
            stop = (qfp == qfpnext);
@@ -4556,20 +4556,24 @@ unload_dummy_buffer(buf_T *buf, char_u *dirname_start)
  * If qf_idx is -1, use the current list. Otherwise, use the specified list.
  */
     int
-get_errorlist(win_T *wp, int qf_idx, list_T *list)
+get_errorlist(qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list)
 {
-    qf_info_T  *qi = &ql_info;
+    qf_info_T  *qi = qi_arg;
     dict_T     *dict;
     char_u     buf[2];
     qfline_T   *qfp;
     int                i;
     int                bufnum;
 
-    if (wp != NULL)
+    if (qi == NULL)
     {
-       qi = GET_LOC_LIST(wp);
-       if (qi == NULL)
-           return FAIL;
+       qi = &ql_info;
+       if (wp != NULL)
+       {
+           qi = GET_LOC_LIST(wp);
+           if (qi == NULL)
+               return FAIL;
+       }
     }
 
     if (qf_idx == -1)
@@ -4627,6 +4631,45 @@ enum {
     QF_GETLIST_ALL     = 0xFF
 };
 
+/*
+ * Parse text from 'di' and return the quickfix list items
+ */
+    static int
+qf_get_list_from_text(dictitem_T *di, dict_T *retdict)
+{
+    int                status = FAIL;
+    qf_info_T  *qi;
+
+    /* Only string and list values are supported */
+    if ((di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
+           || (di->di_tv.v_type == VAR_LIST
+               && di->di_tv.vval.v_list != NULL))
+    {
+       qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T));
+       if (qi != NULL)
+       {
+           vim_memset(qi, 0, (size_t)(sizeof(qf_info_T)));
+           qi->qf_refcount++;
+
+           if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
+                       TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
+           {
+               list_T  *l = list_alloc();
+               if (l != NULL)
+               {
+                   (void)get_errorlist(qi, NULL, 0, l);
+                   dict_add_list(retdict, "items", l);
+                   status = OK;
+               }
+               qf_free(qi, 0);
+           }
+           free(qi);
+       }
+    }
+
+    return status;
+}
+
 /*
  * Return quickfix/location list details (title) as a
  * 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)
     dictitem_T *di;
     int                flags = QF_GETLIST_NONE;
 
+    if ((di = dict_find(what, (char_u *)"text", -1)) != NULL)
+       return qf_get_list_from_text(di, retdict);
+
     if (wp != NULL)
     {
        qi = GET_LOC_LIST(wp);
@@ -4726,7 +4772,7 @@ get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
        list_T  *l = list_alloc();
        if (l != NULL)
        {
-           (void)get_errorlist(wp, qf_idx, l);
+           (void)get_errorlist(qi, NULL, qf_idx, l);
            dict_add_list(retdict, "items", l);
        }
        else
index 8fa715395ce36cadf45cd0ff18d09da77fd1982f..32b04c34e95a1973d02c03ac35ca7314cc482a70 100644 (file)
@@ -2519,3 +2519,29 @@ func Test_add_qf()
   call XaddQf_tests('c')
   call XaddQf_tests('l')
 endfunc
+
+" Test for getting the quickfix list items from some text without modifying
+" the quickfix stack
+func XgetListFromText(cchar)
+  call s:setup_commands(a:cchar)
+  call g:Xsetlist([], 'f')
+
+  let l = g:Xgetlist({'text' : "File1:10:Line10"}).items
+  call assert_equal(1, len(l))
+  call assert_equal('Line10', l[0].text)
+
+  let l = g:Xgetlist({'text' : ["File2:20:Line20", "File2:30:Line30"]}).items
+  call assert_equal(2, len(l))
+  call assert_equal(30, l[1].lnum)
+
+  call assert_equal({}, g:Xgetlist({'text' : 10}))
+  call assert_equal({}, g:Xgetlist({'text' : []}))
+
+  " Make sure that the quickfix stack is not modified
+  call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
+endfunc
+
+func Test_get_list_from_text()
+  call XgetListFromText('c')
+  call XgetListFromText('l')
+endfunc
index 68f3534f6dd81b2efce1e53207a0ce74bd0e5b7a..5df1fc36ac10cc1c2fe06b0c75c325568336f26d 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1006,
 /**/
     1005,
 /**/