mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
eval: Fix setmatches(), setqflist() and setloclist()
This commit is contained in:
parent
f572bd7e4e
commit
5008205a3e
171
src/nvim/eval.c
171
src/nvim/eval.c
@ -14653,8 +14653,8 @@ skip_args:
|
||||
title = (wp ? "setloclist()" : "setqflist()");
|
||||
}
|
||||
|
||||
list_T *l = list_arg->vval.v_list;
|
||||
if (l && set_errorlist(wp, l, action, (char_u *)title, d) == OK) {
|
||||
list_T *const l = list_arg->vval.v_list;
|
||||
if (set_errorlist(wp, l, action, (char_u *)title, d) == OK) {
|
||||
rettv->vval.v_number = 0;
|
||||
}
|
||||
}
|
||||
@ -14687,92 +14687,89 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
EMSG(_(e_listreq));
|
||||
return;
|
||||
}
|
||||
list_T *l;
|
||||
if ((l = argvars[0].vval.v_list) != NULL) {
|
||||
|
||||
// To some extent make sure that we are dealing with a list from
|
||||
// "getmatches()".
|
||||
int i = 0;
|
||||
TV_LIST_ITER_CONST(l, li, {
|
||||
if (TV_LIST_ITEM_TV(li)->v_type != VAR_DICT
|
||||
|| (d = TV_LIST_ITEM_TV(li)->vval.v_dict) == NULL) {
|
||||
emsgf(_("E474: List item %d is either not a dictionary "
|
||||
"or an empty one"), i);
|
||||
return;
|
||||
}
|
||||
if (!(tv_dict_find(d, S_LEN("group")) != NULL
|
||||
&& (tv_dict_find(d, S_LEN("pattern")) != NULL
|
||||
|| tv_dict_find(d, S_LEN("pos1")) != NULL)
|
||||
&& tv_dict_find(d, S_LEN("priority")) != NULL
|
||||
&& tv_dict_find(d, S_LEN("id")) != NULL)) {
|
||||
emsgf(_("E474: List item %d is missing one of the required keys"), i);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
});
|
||||
|
||||
clear_matches(curwin);
|
||||
bool match_add_failed = false;
|
||||
TV_LIST_ITER_CONST(l, li, {
|
||||
int i = 0;
|
||||
|
||||
d = TV_LIST_ITEM_TV(li)->vval.v_dict;
|
||||
dictitem_T *const di = tv_dict_find(d, S_LEN("pattern"));
|
||||
if (di == NULL) {
|
||||
if (s == NULL) {
|
||||
s = tv_list_alloc();
|
||||
}
|
||||
|
||||
// match from matchaddpos()
|
||||
for (i = 1; i < 9; i++) {
|
||||
char buf[5];
|
||||
snprintf(buf, sizeof(buf), "pos%d", i);
|
||||
dictitem_T *const pos_di = tv_dict_find(d, buf, -1);
|
||||
if (pos_di != NULL) {
|
||||
if (pos_di->di_tv.v_type != VAR_LIST) {
|
||||
return;
|
||||
}
|
||||
|
||||
tv_list_append_tv(s, &pos_di->di_tv);
|
||||
tv_list_ref(s);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: there are three number buffers involved:
|
||||
// - group_buf below.
|
||||
// - numbuf in tv_dict_get_string().
|
||||
// - mybuf in tv_get_string().
|
||||
//
|
||||
// If you change this code make sure that buffers will not get
|
||||
// accidentally reused.
|
||||
char group_buf[NUMBUFLEN];
|
||||
const char *const group = tv_dict_get_string_buf(d, "group", group_buf);
|
||||
const int priority = (int)tv_dict_get_number(d, "priority");
|
||||
const int id = (int)tv_dict_get_number(d, "id");
|
||||
dictitem_T *const conceal_di = tv_dict_find(d, S_LEN("conceal"));
|
||||
const char *const conceal = (conceal_di != NULL
|
||||
? tv_get_string(&conceal_di->di_tv)
|
||||
: NULL);
|
||||
if (i == 0) {
|
||||
if (match_add(curwin, group,
|
||||
tv_dict_get_string(d, "pattern", false),
|
||||
priority, id, NULL, conceal) != id) {
|
||||
match_add_failed = true;
|
||||
}
|
||||
} else {
|
||||
if (match_add(curwin, group, NULL, priority, id, s, conceal) != id) {
|
||||
match_add_failed = true;
|
||||
}
|
||||
tv_list_unref(s);
|
||||
s = NULL;
|
||||
}
|
||||
});
|
||||
if (!match_add_failed) {
|
||||
rettv->vval.v_number = 0;
|
||||
list_T *const l = argvars[0].vval.v_list;
|
||||
// To some extent make sure that we are dealing with a list from
|
||||
// "getmatches()".
|
||||
int i = 0;
|
||||
TV_LIST_ITER_CONST(l, li, {
|
||||
if (TV_LIST_ITEM_TV(li)->v_type != VAR_DICT
|
||||
|| (d = TV_LIST_ITEM_TV(li)->vval.v_dict) == NULL) {
|
||||
emsgf(_("E474: List item %d is either not a dictionary "
|
||||
"or an empty one"), i);
|
||||
return;
|
||||
}
|
||||
if (!(tv_dict_find(d, S_LEN("group")) != NULL
|
||||
&& (tv_dict_find(d, S_LEN("pattern")) != NULL
|
||||
|| tv_dict_find(d, S_LEN("pos1")) != NULL)
|
||||
&& tv_dict_find(d, S_LEN("priority")) != NULL
|
||||
&& tv_dict_find(d, S_LEN("id")) != NULL)) {
|
||||
emsgf(_("E474: List item %d is missing one of the required keys"), i);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
});
|
||||
|
||||
clear_matches(curwin);
|
||||
bool match_add_failed = false;
|
||||
TV_LIST_ITER_CONST(l, li, {
|
||||
int i = 0;
|
||||
|
||||
d = TV_LIST_ITEM_TV(li)->vval.v_dict;
|
||||
dictitem_T *const di = tv_dict_find(d, S_LEN("pattern"));
|
||||
if (di == NULL) {
|
||||
if (s == NULL) {
|
||||
s = tv_list_alloc();
|
||||
}
|
||||
|
||||
// match from matchaddpos()
|
||||
for (i = 1; i < 9; i++) {
|
||||
char buf[5];
|
||||
snprintf(buf, sizeof(buf), "pos%d", i);
|
||||
dictitem_T *const pos_di = tv_dict_find(d, buf, -1);
|
||||
if (pos_di != NULL) {
|
||||
if (pos_di->di_tv.v_type != VAR_LIST) {
|
||||
return;
|
||||
}
|
||||
|
||||
tv_list_append_tv(s, &pos_di->di_tv);
|
||||
tv_list_ref(s);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: there are three number buffers involved:
|
||||
// - group_buf below.
|
||||
// - numbuf in tv_dict_get_string().
|
||||
// - mybuf in tv_get_string().
|
||||
//
|
||||
// If you change this code make sure that buffers will not get
|
||||
// accidentally reused.
|
||||
char group_buf[NUMBUFLEN];
|
||||
const char *const group = tv_dict_get_string_buf(d, "group", group_buf);
|
||||
const int priority = (int)tv_dict_get_number(d, "priority");
|
||||
const int id = (int)tv_dict_get_number(d, "id");
|
||||
dictitem_T *const conceal_di = tv_dict_find(d, S_LEN("conceal"));
|
||||
const char *const conceal = (conceal_di != NULL
|
||||
? tv_get_string(&conceal_di->di_tv)
|
||||
: NULL);
|
||||
if (i == 0) {
|
||||
if (match_add(curwin, group,
|
||||
tv_dict_get_string(d, "pattern", false),
|
||||
priority, id, NULL, conceal) != id) {
|
||||
match_add_failed = true;
|
||||
}
|
||||
} else {
|
||||
if (match_add(curwin, group, NULL, priority, id, s, conceal) != id) {
|
||||
match_add_failed = true;
|
||||
}
|
||||
tv_list_unref(s);
|
||||
s = NULL;
|
||||
}
|
||||
});
|
||||
if (!match_add_failed) {
|
||||
rettv->vval.v_number = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,6 @@ describe('NULL', function()
|
||||
describe('list', function()
|
||||
-- Incorrect behaviour
|
||||
|
||||
-- FIXME should return 0
|
||||
null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1)
|
||||
-- FIXME should return 0
|
||||
null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1)
|
||||
-- FIXME should return 0
|
||||
null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1)
|
||||
-- FIXME should not error out
|
||||
null_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected')
|
||||
-- FIXME should not error out
|
||||
@ -129,6 +123,9 @@ describe('NULL', function()
|
||||
'', '\n', function()
|
||||
eq({''}, curbufmeths.get_lines(0, -1, false))
|
||||
end)
|
||||
null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0)
|
||||
null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, 0)
|
||||
null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, 0)
|
||||
end)
|
||||
describe('dict', function()
|
||||
it('does not crash when indexing NULL dict', function()
|
||||
|
Loading…
Reference in New Issue
Block a user