diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-10-02 00:06:37 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-10-02 00:52:22 -0400 |
commit | 4518f230fa84e66737f6fc313fb669984974a1fd (patch) | |
tree | d45c8254fa620d1416aa7c1f674a9fb142459e45 | |
parent | ada2ec441617077110e503c550dd3227eb9da072 (diff) | |
download | rneovim-4518f230fa84e66737f6fc313fb669984974a1fd.tar.gz rneovim-4518f230fa84e66737f6fc313fb669984974a1fd.tar.bz2 rneovim-4518f230fa84e66737f6fc313fb669984974a1fd.zip |
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)
https://github.com/vim/vim/commit/6f6ef7c1951b080843f3da049d3f5d0679de7348
-rw-r--r-- | src/nvim/quickfix.c | 136 |
1 files changed, 76 insertions, 60 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 511fb037fb..c5e8d4b490 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -5030,15 +5030,86 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict) 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 /// a dictionary with item information. static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list, char_u *title, int action) { - dict_T *d; qfline_T *old_last = NULL; int retval = OK; - bool did_bufnr_emsg = false; if (action == ' ' || qf_idx == qi->qf_listcount) { // 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. } - 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) { continue; } - 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"); - 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; + retval = qf_add_entry_from_dict(qi, qf_idx, d, li == tv_list_first(list)); + if (retval == FAIL) { break; } }); |