mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.0330: the qf_add_entries() function is too long
Problem: The qf_add_entries() function is too long.
Solution: Split in two parts. (Yegappan Lakshmanan)
6f6ef7c195
This commit is contained in:
parent
ada2ec4416
commit
4518f230fa
@ -5030,15 +5030,86 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a new quickfix entry to list at 'qf_idx' in the stack 'qi' from the
|
||||||
|
// items in the dict 'd'.
|
||||||
|
static int qf_add_entry_from_dict(
|
||||||
|
qf_info_T *qi,
|
||||||
|
int qf_idx,
|
||||||
|
const dict_T *d,
|
||||||
|
bool first_entry)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
static bool did_bufnr_emsg;
|
||||||
|
|
||||||
|
if (first_entry) {
|
||||||
|
did_bufnr_emsg = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *const filename = tv_dict_get_string(d, "filename", true);
|
||||||
|
char *const module = tv_dict_get_string(d, "module", true);
|
||||||
|
int bufnum = (int)tv_dict_get_number(d, "bufnr");
|
||||||
|
const long lnum = (long)tv_dict_get_number(d, "lnum");
|
||||||
|
const int col = (int)tv_dict_get_number(d, "col");
|
||||||
|
const char_u vcol = (char_u)tv_dict_get_number(d, "vcol");
|
||||||
|
const int nr = (int)tv_dict_get_number(d, "nr");
|
||||||
|
const char *const type = tv_dict_get_string(d, "type", false);
|
||||||
|
char *const pattern = tv_dict_get_string(d, "pattern", true);
|
||||||
|
char *text = tv_dict_get_string(d, "text", true);
|
||||||
|
if (text == NULL) {
|
||||||
|
text = xcalloc(1, 1);
|
||||||
|
}
|
||||||
|
bool valid = true;
|
||||||
|
if ((filename == NULL && bufnum == 0)
|
||||||
|
|| (lnum == 0 && pattern == NULL)) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark entries with non-existing buffer number as not valid. Give the
|
||||||
|
// error message only once.
|
||||||
|
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) {
|
||||||
|
if (!did_bufnr_emsg) {
|
||||||
|
did_bufnr_emsg = true;
|
||||||
|
EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
|
||||||
|
}
|
||||||
|
valid = false;
|
||||||
|
bufnum = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the 'valid' field is present it overrules the detected value.
|
||||||
|
if (tv_dict_find(d, "valid", -1) != NULL) {
|
||||||
|
valid = tv_dict_get_number(d, "valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
const int status = qf_add_entry(qi,
|
||||||
|
qf_idx,
|
||||||
|
NULL, // dir
|
||||||
|
(char_u *)filename,
|
||||||
|
(char_u *)module,
|
||||||
|
bufnum,
|
||||||
|
(char_u *)text,
|
||||||
|
lnum,
|
||||||
|
col,
|
||||||
|
vcol, // vis_col
|
||||||
|
(char_u *)pattern, // search pattern
|
||||||
|
nr,
|
||||||
|
(char_u)(type == NULL ? NUL : *type),
|
||||||
|
valid);
|
||||||
|
|
||||||
|
xfree(filename);
|
||||||
|
xfree(module);
|
||||||
|
xfree(pattern);
|
||||||
|
xfree(text);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/// Add list of entries to quickfix/location list. Each list entry is
|
/// Add list of entries to quickfix/location list. Each list entry is
|
||||||
/// a dictionary with item information.
|
/// a dictionary with item information.
|
||||||
static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list,
|
static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list,
|
||||||
char_u *title, int action)
|
char_u *title, int action)
|
||||||
{
|
{
|
||||||
dict_T *d;
|
|
||||||
qfline_T *old_last = NULL;
|
qfline_T *old_last = NULL;
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
bool did_bufnr_emsg = false;
|
|
||||||
|
|
||||||
if (action == ' ' || qf_idx == qi->qf_listcount) {
|
if (action == ' ' || qf_idx == qi->qf_listcount) {
|
||||||
// make place for a new list
|
// make place for a new list
|
||||||
@ -5057,68 +5128,13 @@ static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list,
|
|||||||
continue; // Skip non-dict items.
|
continue; // Skip non-dict items.
|
||||||
}
|
}
|
||||||
|
|
||||||
d = TV_LIST_ITEM_TV(li)->vval.v_dict;
|
const dict_T *const d = TV_LIST_ITEM_TV(li)->vval.v_dict;
|
||||||
if (d == NULL) {
|
if (d == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *const filename = tv_dict_get_string(d, "filename", true);
|
retval = qf_add_entry_from_dict(qi, qf_idx, d, li == tv_list_first(list));
|
||||||
char *const module = tv_dict_get_string(d, "module", true);
|
if (retval == FAIL) {
|
||||||
int bufnum = (int)tv_dict_get_number(d, "bufnr");
|
|
||||||
long lnum = (long)tv_dict_get_number(d, "lnum");
|
|
||||||
int col = (int)tv_dict_get_number(d, "col");
|
|
||||||
char_u vcol = (char_u)tv_dict_get_number(d, "vcol");
|
|
||||||
int nr = (int)tv_dict_get_number(d, "nr");
|
|
||||||
const char *type_str = tv_dict_get_string(d, "type", false);
|
|
||||||
const char_u type = (char_u)(uint8_t)(type_str == NULL ? NUL : *type_str);
|
|
||||||
char *const pattern = tv_dict_get_string(d, "pattern", true);
|
|
||||||
char *text = tv_dict_get_string(d, "text", true);
|
|
||||||
if (text == NULL) {
|
|
||||||
text = xcalloc(1, 1);
|
|
||||||
}
|
|
||||||
bool valid = true;
|
|
||||||
if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) {
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mark entries with non-existing buffer number as not valid. Give the
|
|
||||||
* error message only once. */
|
|
||||||
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) {
|
|
||||||
if (!did_bufnr_emsg) {
|
|
||||||
did_bufnr_emsg = TRUE;
|
|
||||||
EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
|
|
||||||
}
|
|
||||||
valid = false;
|
|
||||||
bufnum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the 'valid' field is present it overrules the detected value.
|
|
||||||
if (tv_dict_find(d, "valid", -1) != NULL) {
|
|
||||||
valid = (int)tv_dict_get_number(d, "valid");
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = qf_add_entry(qi,
|
|
||||||
qf_idx,
|
|
||||||
NULL, // dir
|
|
||||||
(char_u *)filename,
|
|
||||||
(char_u *)module,
|
|
||||||
bufnum,
|
|
||||||
(char_u *)text,
|
|
||||||
lnum,
|
|
||||||
col,
|
|
||||||
vcol, // vis_col
|
|
||||||
(char_u *)pattern, // search pattern
|
|
||||||
nr,
|
|
||||||
type,
|
|
||||||
valid);
|
|
||||||
|
|
||||||
xfree(filename);
|
|
||||||
xfree(module);
|
|
||||||
xfree(pattern);
|
|
||||||
xfree(text);
|
|
||||||
|
|
||||||
if (status == FAIL) {
|
|
||||||
retval = FAIL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user