mirror of
https://github.com/neovim/neovim.git
synced 2025-09-17 16:58:17 +00:00
vim-patch:8.0.1040: cannot use another error format in getqflist()
Problem: Cannot use another error format in getqflist().
Solution: Add the "efm" argument to getqflist(). (Yegappan Lakshmanan)
3653822546
This commit is contained in:
@@ -4335,16 +4335,19 @@ getqflist([{what}]) *getqflist()*
|
|||||||
returns only the items listed in {what} as a dictionary. The
|
returns only the items listed in {what} as a dictionary. The
|
||||||
following string items are supported in {what}:
|
following string items are supported in {what}:
|
||||||
context get the context stored with |setqflist()|
|
context get the context stored with |setqflist()|
|
||||||
|
efm errorformat to use when parsing "lines". If
|
||||||
|
not present, then the 'erroformat' option
|
||||||
|
value is used.
|
||||||
id get information for the quickfix list with
|
id get information for the quickfix list with
|
||||||
|quickfix-ID|; zero means the id for the
|
|quickfix-ID|; zero means the id for the
|
||||||
current list or the list specifed by 'nr'
|
current list or the list specifed by "nr"
|
||||||
items quickfix list entries
|
items quickfix list entries
|
||||||
lines use 'errorformat' to extract items from a list
|
lines use 'errorformat' to extract items from a list
|
||||||
of lines and return the resulting entries.
|
of lines and return the resulting entries.
|
||||||
Only a |List| type is accepted. The current
|
Only a |List| type is accepted. The current
|
||||||
quickfix list is not modified.
|
quickfix list is not modified.
|
||||||
nr get information for this quickfix list; zero
|
nr get information for this quickfix list; zero
|
||||||
means the current quickfix list and '$' means
|
means the current quickfix list and "$" means
|
||||||
the last quickfix list
|
the last quickfix list
|
||||||
title get the list title
|
title get the list title
|
||||||
winid get the |window-ID| (if opened)
|
winid get the |window-ID| (if opened)
|
||||||
@@ -6918,7 +6921,7 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
|
|||||||
is created. The new quickfix list is added after the current
|
is created. The new quickfix list is added after the current
|
||||||
quickfix list in the stack and all the following lists are
|
quickfix list in the stack and all the following lists are
|
||||||
freed. To add a new quickfix list at the end of the stack,
|
freed. To add a new quickfix list at the end of the stack,
|
||||||
set "nr" in {what} to '$'.
|
set "nr" in {what} to "$".
|
||||||
|
|
||||||
If {title} is given, it will be used to set |w:quickfix_title|
|
If {title} is given, it will be used to set |w:quickfix_title|
|
||||||
after opening the quickfix window.
|
after opening the quickfix window.
|
||||||
@@ -6928,6 +6931,9 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
|
|||||||
argument is ignored. The following items can be specified in
|
argument is ignored. The following items can be specified in
|
||||||
{what}:
|
{what}:
|
||||||
context any Vim type can be stored as a context
|
context any Vim type can be stored as a context
|
||||||
|
efm errorformat to use when parsing text from
|
||||||
|
"lines". If this is not present, then the
|
||||||
|
'errorformat' option value is used.
|
||||||
id quickfix list identifier |quickfix-ID|
|
id quickfix list identifier |quickfix-ID|
|
||||||
items list of quickfix entries. Same as the {list}
|
items list of quickfix entries. Same as the {list}
|
||||||
argument.
|
argument.
|
||||||
@@ -6935,7 +6941,7 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
|
|||||||
add the resulting entries to the quickfix list
|
add the resulting entries to the quickfix list
|
||||||
{nr} or {id}. Only a |List| value is supported.
|
{nr} or {id}. Only a |List| value is supported.
|
||||||
nr list number in the quickfix stack; zero
|
nr list number in the quickfix stack; zero
|
||||||
means the current quickfix list and '$' means
|
means the current quickfix list and "$" means
|
||||||
the last quickfix list
|
the last quickfix list
|
||||||
title quickfix list title text
|
title quickfix list title text
|
||||||
Unsupported keys in {what} are ignored.
|
Unsupported keys in {what} are ignored.
|
||||||
@@ -6943,7 +6949,7 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
|
|||||||
is modified. When creating a new quickfix list, "nr" can be
|
is modified. When creating a new quickfix list, "nr" can be
|
||||||
set to a value one greater than the quickfix stack size.
|
set to a value one greater than the quickfix stack size.
|
||||||
When modifying a quickfix list, to guarantee that the correct
|
When modifying a quickfix list, to guarantee that the correct
|
||||||
list is modified, 'id' should be used instead of 'nr' to
|
list is modified, "id" should be used instead of "nr" to
|
||||||
specify the list.
|
specify the list.
|
||||||
|
|
||||||
Examples: >
|
Examples: >
|
||||||
|
@@ -4122,18 +4122,30 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Parse text from 'di' and return the quickfix list items
|
// Parse text from 'di' and return the quickfix list items
|
||||||
static int qf_get_list_from_lines(dictitem_T *di, dict_T *retdict)
|
static int qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
|
||||||
{
|
{
|
||||||
int status = FAIL;
|
int status = FAIL;
|
||||||
|
char_u *errorformat = p_efm;
|
||||||
|
dictitem_T *efm_di;
|
||||||
|
|
||||||
// Only a List value is supported
|
// Only a List value is supported
|
||||||
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) {
|
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) {
|
||||||
|
// If errorformat is supplied then use it, otherwise use the 'efm'
|
||||||
|
// option setting
|
||||||
|
if ((efm_di = tv_dict_find(what, S_LEN("efm"))) != NULL) {
|
||||||
|
if (efm_di->di_tv.v_type != VAR_STRING
|
||||||
|
|| efm_di->di_tv.vval.v_string == NULL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
errorformat = efm_di->di_tv.vval.v_string;
|
||||||
|
}
|
||||||
|
|
||||||
list_T *l = tv_list_alloc(kListLenMayKnow);
|
list_T *l = tv_list_alloc(kListLenMayKnow);
|
||||||
qf_info_T *qi = xmalloc(sizeof(*qi));
|
qf_info_T *qi = xmalloc(sizeof(*qi));
|
||||||
memset(qi, 0, sizeof(*qi));
|
memset(qi, 0, sizeof(*qi));
|
||||||
qi->qf_refcount++;
|
qi->qf_refcount++;
|
||||||
|
|
||||||
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, p_efm,
|
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
|
||||||
true, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) {
|
true, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) {
|
||||||
(void)get_errorlist(qi, NULL, 0, l);
|
(void)get_errorlist(qi, NULL, 0, l);
|
||||||
qf_free(qi, 0);
|
qf_free(qi, 0);
|
||||||
@@ -4156,7 +4168,7 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
|||||||
dictitem_T *di;
|
dictitem_T *di;
|
||||||
|
|
||||||
if ((di = tv_dict_find(what, S_LEN("lines"))) != NULL) {
|
if ((di = tv_dict_find(what, S_LEN("lines"))) != NULL) {
|
||||||
return qf_get_list_from_lines(di, retdict);
|
return qf_get_list_from_lines(what, di, retdict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp != NULL) {
|
if (wp != NULL) {
|
||||||
@@ -4390,6 +4402,7 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action,
|
|||||||
dictitem_T *di;
|
dictitem_T *di;
|
||||||
int retval = FAIL;
|
int retval = FAIL;
|
||||||
int newlist = false;
|
int newlist = false;
|
||||||
|
char_u *errorformat = p_efm;
|
||||||
|
|
||||||
if (action == ' ' || qi->qf_curlist == qi->qf_listcount) {
|
if (action == ' ' || qi->qf_curlist == qi->qf_listcount) {
|
||||||
newlist = true;
|
newlist = true;
|
||||||
@@ -4471,13 +4484,20 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((di = tv_dict_find(what, S_LEN("efm"))) != NULL) {
|
||||||
|
if (di->di_tv.v_type != VAR_STRING || di->di_tv.vval.v_string == NULL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
errorformat = di->di_tv.vval.v_string;
|
||||||
|
}
|
||||||
|
|
||||||
if ((di = tv_dict_find(what, S_LEN("lines"))) != NULL) {
|
if ((di = tv_dict_find(what, S_LEN("lines"))) != NULL) {
|
||||||
// Only a List value is supported
|
// Only a List value is supported
|
||||||
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) {
|
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) {
|
||||||
if (action == 'r') {
|
if (action == 'r') {
|
||||||
qf_free_items(qi, qf_idx);
|
qf_free_items(qi, qf_idx);
|
||||||
}
|
}
|
||||||
if (qf_init_ext(qi, qf_idx, NULL, NULL, &di->di_tv, p_efm,
|
if (qf_init_ext(qi, qf_idx, NULL, NULL, &di->di_tv, errorformat,
|
||||||
false, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) {
|
false, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) {
|
||||||
retval = OK;
|
retval = OK;
|
||||||
}
|
}
|
||||||
|
@@ -2303,6 +2303,17 @@ func Xsetexpr_tests(cchar)
|
|||||||
call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
|
call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
|
||||||
call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
|
call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
|
||||||
call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
|
call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
|
||||||
|
|
||||||
|
" Adding entries using a custom efm
|
||||||
|
set efm&
|
||||||
|
call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
|
||||||
|
\ 'lines' : ["F1#10#L10", "F2#20#L20"]})
|
||||||
|
call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
|
||||||
|
call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
|
||||||
|
call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
|
||||||
|
call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
|
||||||
|
call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
|
||||||
|
\ 'lines' : ['F1:10:L10']}))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_setexpr()
|
func Test_setexpr()
|
||||||
@@ -2519,6 +2530,17 @@ func XgetListFromLines(cchar)
|
|||||||
call assert_equal([], g:Xgetlist({'lines' : []}).items)
|
call assert_equal([], g:Xgetlist({'lines' : []}).items)
|
||||||
call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
|
call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
|
||||||
|
|
||||||
|
" Parse text using a custom efm
|
||||||
|
set efm&
|
||||||
|
let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
|
||||||
|
call assert_equal('Line30', l[0].text)
|
||||||
|
let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
|
||||||
|
call assert_equal('File3:30:Line30', l[0].text)
|
||||||
|
let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
|
||||||
|
call assert_equal({}, l)
|
||||||
|
call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
|
||||||
|
call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
|
||||||
|
|
||||||
" Make sure that the quickfix stack is not modified
|
" Make sure that the quickfix stack is not modified
|
||||||
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
|
call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
|
||||||
endfunc
|
endfunc
|
||||||
|
Reference in New Issue
Block a user