aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-04-14 16:54:33 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-04-14 19:09:19 -0400
commite52f6f21a116a85fc90e273a7ddede7013520231 (patch)
treeafa4261fcd27a1a1ac7b271a10cd601e9884ec5a /src
parent6de1ed1ff11a59b063ae8d199aab17977d7b445f (diff)
downloadrneovim-e52f6f21a116a85fc90e273a7ddede7013520231.tar.gz
rneovim-e52f6f21a116a85fc90e273a7ddede7013520231.tar.bz2
rneovim-e52f6f21a116a85fc90e273a7ddede7013520231.zip
vim-patch:8.0.1093: various small quickfix issues
Problem: Various small quickfix issues. Solution: Remove ":" prefix from title set by a user. Add the qf_id2nr(). function. Add a couple more tests. Update documentation. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/b4d5fbabc99917a8069ba32a60c2d73d4f60e128
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/quickfix.c37
-rw-r--r--src/nvim/testdir/test_quickfix.vim26
3 files changed, 49 insertions, 16 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 86333acbef..9f88f1e393 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10065,7 +10065,7 @@ static void get_qf_loc_list(int is_qf, win_T *wp, typval_T *what_arg,
dict_T *d = what_arg->vval.v_dict;
if (d != NULL) {
- get_errorlist_properties(wp, d, rettv->vval.v_dict);
+ qf_get_properties(wp, d, rettv->vval.v_dict);
}
} else {
EMSG(_(e_dictreq));
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 6444661512..bc794addc6 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -4243,10 +4243,22 @@ static int qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
return status;
}
+// Return the quickfix/location list number with the given identifier.
+// Returns -1 if list is not found.
+static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid)
+{
+ for (int qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) {
+ if (qi->qf_lists[qf_idx].qf_id == qfid) {
+ return qf_idx;
+ }
+ }
+ return -1;
+}
+
/// Return quickfix/location list details (title) as a
/// dictionary. 'what' contains the details to return. If 'list_idx' is -1,
/// then current list is used. Otherwise the specified list is used.
-int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
+int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
{
qf_info_T *qi = &ql_info;
dictitem_T *di;
@@ -4298,12 +4310,8 @@ int get_errorlist_properties(win_T *wp, dict_T *what, dict_T *retdict)
if (di->di_tv.v_type == VAR_NUMBER) {
// For zero, use the current list or the list specifed by 'nr'
if (di->di_tv.vval.v_number != 0) {
- for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) {
- if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number) {
- break;
- }
- }
- if (qf_idx == qi->qf_listcount) {
+ qf_idx = qf_id2nr(qi, (unsigned)di->di_tv.vval.v_number);
+ if (qf_idx == -1) {
return FAIL; // List not found
}
}
@@ -4528,12 +4536,8 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action,
if (!newlist && (di = tv_dict_find(what, S_LEN("id"))) != NULL) {
// Use the quickfix/location list with the specified id
if (di->di_tv.v_type == VAR_NUMBER) {
- for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++) {
- if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number) {
- break;
- }
- }
- if (qf_idx == qi->qf_listcount) {
+ qf_idx = qf_id2nr(qi, (unsigned)di->di_tv.vval.v_number);
+ if (qf_idx == -1) {
return FAIL; // List not found
}
} else {
@@ -4565,6 +4569,13 @@ static int qf_set_properties(qf_info_T *qi, dict_T *what, int action,
retval = qf_add_entries(qi, qf_idx, di->di_tv.vval.v_list,
title_save, action == ' ' ? 'a' : action);
+ if (action == 'r') {
+ // When replacing the quickfix list entries using
+ // qf_add_entries(), the title is set with a ':' prefix.
+ // Restore the title with the saved title.
+ xfree(qi->qf_lists[qf_idx].qf_title);
+ qi->qf_lists[qf_idx].qf_title = vim_strsave(title_save);
+ }
xfree(title_save);
}
}
diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim
index 6227095f4f..7c4d1d3b81 100644
--- a/src/nvim/testdir/test_quickfix.vim
+++ b/src/nvim/testdir/test_quickfix.vim
@@ -469,6 +469,19 @@ func s:test_xhelpgrep(cchar)
" This wipes out the buffer, make sure that doesn't cause trouble.
Xclose
+ if a:cchar == 'l'
+ " When a help window is present, running :lhelpgrep should reuse the
+ " help window and not the current window
+ new | only
+ call g:Xsetlist([], 'f')
+ help index.txt
+ wincmd w
+ lhelpgrep quickfix
+ call assert_equal(1, winnr())
+ call assert_notequal([], getloclist(1))
+ call assert_equal([], getloclist(2))
+ endif
+
new | only
" Search for non existing help string
@@ -1666,6 +1679,10 @@ func HistoryTest(cchar)
call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
+
+ call g:Xsetlist([], 'f')
+ let l = split(execute(a:cchar . 'hist'), "\n")
+ call assert_equal('No entries', l[0])
endfunc
func Test_history()
@@ -1844,6 +1861,11 @@ func Xproperty_tests(cchar)
let l = g:Xgetlist({'items':1})
call assert_equal(0, len(l.items))
+ call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
+ call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
+ call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
+ call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
+
" The following used to crash Vim with address sanitizer
call g:Xsetlist([], 'f')
call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
@@ -1886,10 +1908,10 @@ func Xproperty_tests(cchar)
call g:Xsetlist([], 'r', l2)
let newl1=g:Xgetlist({'nr':1,'all':1})
let newl2=g:Xgetlist({'nr':2,'all':1})
- call assert_equal(':Fruits', newl1.title)
+ call assert_equal('Fruits', newl1.title)
call assert_equal(['Fruits'], newl1.context)
call assert_equal('Line20', newl1.items[0].text)
- call assert_equal(':Colors', newl2.title)
+ call assert_equal('Colors', newl2.title)
call assert_equal(['Colors'], newl2.context)
call assert_equal('Line10', newl2.items[0].text)
call g:Xsetlist([], 'f')