diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 2 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 52 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 26 |
3 files changed, 71 insertions, 9 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d750a47588..309c0fc062 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9943,7 +9943,7 @@ static void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg, if (what_arg->v_type == VAR_UNKNOWN) { tv_list_alloc_ret(rettv, kListLenMayKnow); 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 { tv_dict_alloc_ret(rettv); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 263b8b3a77..d290beac59 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2414,7 +2414,7 @@ static void qf_free_items(qf_info_T *qi, int idx) while (qfl->qf_count && qfl->qf_start != NULL) { qfp = qfl->qf_start; qfpnext = qfp->qf_next; - if (qfl->qf_title != NULL && !stop) { + if (!stop) { xfree(qfp->qf_text); stop = (qfp == qfpnext); xfree(qfp->qf_pattern); @@ -4031,18 +4031,22 @@ static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start) /// Add each quickfix error to list "list" as a dictionary. /// 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) +int get_errorlist(const qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) { - qf_info_T *qi = &ql_info; + const qf_info_T *qi = qi_arg; char_u buf[2]; qfline_T *qfp; int i; int bufnum; - if (wp != NULL) { - qi = GET_LOC_LIST(wp); - if (qi == NULL) - return FAIL; + if (qi == NULL) { + qi = &ql_info; + if (wp != NULL) { + qi = GET_LOC_LIST(wp); + if (qi == NULL) { + return FAIL; + } + } } if (qf_idx == -1) { @@ -4109,6 +4113,34 @@ 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; + + // 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)) { + qf_info_T *qi = xmalloc(sizeof(*qi)); + memset(qi, 0, sizeof(*qi)); + 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 = tv_list_alloc(kListLenMayKnow); + (void)get_errorlist(qi, NULL, 0, l); + tv_dict_add_list(retdict, S_LEN("items"), l); + status = OK; + qf_free(qi, 0); + } + xfree(qi); + } + + return status; +} + /// Return quickfix/location list details (title) as a /// dictionary. 'what' contains the details to return. If 'list_idx' is -1, /// then current list is used. Otherwise the specified list is used. @@ -4117,6 +4149,10 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) qf_info_T *qi = &ql_info; dictitem_T *di; + if ((di = tv_dict_find(what, S_LEN("text"))) != NULL) { + return qf_get_list_from_text(di, retdict); + } + if (wp != NULL) { qi = GET_LOC_LIST(wp); if (qi == NULL) { @@ -4201,7 +4237,7 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict) } if ((status == OK) && (flags & QF_GETLIST_ITEMS)) { list_T *l = tv_list_alloc(kListLenMayKnow); - (void)get_errorlist(wp, qf_idx, l); + (void)get_errorlist(qi, NULL, qf_idx, l); tv_dict_add_list(retdict, S_LEN("items"), l); } diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index f603f46d63..fd51fb22b4 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -2501,3 +2501,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 |