mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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)
7adf06f4e2
This commit is contained in:
parent
50eadfe2e9
commit
b4acf609ac
@ -4339,6 +4339,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
|
||||
@ -4347,6 +4352,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.
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user