diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/quickfix.c | 34 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 22 |
2 files changed, 46 insertions, 10 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index da315252b5..276427f216 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -5779,11 +5779,13 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict) } /// Add a new quickfix entry to list at 'qf_idx' in the stack 'qi' from the -/// items in the dict 'd'. +/// items in the dict 'd'. If it is a valid error entry, then set 'valid_entry' +/// to true. static int qf_add_entry_from_dict( qf_list_T *qfl, const dict_T *d, - bool first_entry) + bool first_entry, + bool *valid_entry) FUNC_ATTR_NONNULL_ALL { static bool did_bufnr_emsg; @@ -5846,6 +5848,10 @@ static int qf_add_entry_from_dict( xfree(pattern); xfree(text); + if (valid) { + *valid_entry = true; + } + return status; } @@ -5857,6 +5863,7 @@ static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list, qf_list_T *qfl = qf_get_list(qi, qf_idx); qfline_T *old_last = NULL; int retval = OK; + bool valid_entry = false; if (action == ' ' || qf_idx == qi->qf_listcount) { // make place for a new list @@ -5881,23 +5888,30 @@ static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list, continue; } - retval = qf_add_entry_from_dict(qfl, d, li == tv_list_first(list)); + retval = qf_add_entry_from_dict(qfl, d, li == tv_list_first(list), + &valid_entry); if (retval == QF_FAIL) { break; } }); - if (qfl->qf_index == 0) { - // no valid entry - qfl->qf_nonevalid = true; - } else { + // Check if any valid error entries are added to the list. + if (valid_entry) { qfl->qf_nonevalid = false; + } else if (qfl->qf_index == 0) { + qfl->qf_nonevalid = true; } + + // If not appending to the list, set the current error to the first entry if (action != 'a') { qfl->qf_ptr = qfl->qf_start; - if (!qf_list_empty(qfl)) { - qfl->qf_index = 1; - } + } + + // Update the current error index if not appending to the list or if the + // list was empty before and it is not empty now. + if ((action != 'a' || qfl->qf_index == 0) + && !qf_list_empty(qfl)) { + qfl->qf_index = 1; } // Don't update the cursor in quickfix window when appending entries diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 8949b3d968..15cbf52cb5 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1320,6 +1320,28 @@ func SetXlistTests(cchar, bnum) let l = g:Xgetlist() call g:Xsetlist(l) call assert_equal(0, g:Xgetlist()[0].valid) + " Adding a non-valid entry should not mark the list as having valid entries + call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a') + Xwindow + call assert_equal(1, winnr('$')) + + " :cnext/:cprev should still work even with invalid entries in the list + let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0}, + \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}] + call g:Xsetlist(l) + Xnext + call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) + Xprev + call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) + " :cnext/:cprev should still work after appending invalid entries to an + " empty list + call g:Xsetlist([]) + call g:Xsetlist(l, 'a') + Xnext + call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) + Xprev + call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) + call g:Xsetlist([{'text':'Text1', 'valid':1}]) Xwindow call assert_equal(2, winnr('$')) |