aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-10-13 19:49:17 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-10-23 01:33:16 -0400
commitf3d6d8750b70d56f92d6ece87031ed205abdfcca (patch)
tree62e68f3de2f7a26d9aa803c2a31617c54059d80f
parent5e02bd071ed054b52ca7e53536d4b5cd594737eb (diff)
downloadrneovim-f3d6d8750b70d56f92d6ece87031ed205abdfcca.tar.gz
rneovim-f3d6d8750b70d56f92d6ece87031ed205abdfcca.tar.bz2
rneovim-f3d6d8750b70d56f92d6ece87031ed205abdfcca.zip
vim-patch:8.1.0345: cannot get the window id associated with the location list
Problem: Cannot get the window id associated with the location list. Solution: Add the "filewinid" argument to getloclist(). (Yegappan Lakshmanan, closes vim/vim#3202) https://github.com/vim/vim/commit/c9cc9c78f21caba7ecb5c90403df5e19a57aa96a
-rw-r--r--runtime/doc/eval.txt4
-rw-r--r--src/nvim/quickfix.c40
-rw-r--r--src/nvim/testdir/test_quickfix.vim46
3 files changed, 84 insertions, 6 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 77b6ee24a4..d21e441888 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -4553,6 +4553,10 @@ getloclist({nr},[, {what}]) *getloclist()*
If the optional {what} dictionary argument is supplied, then
returns the items listed in {what} as a dictionary. Refer to
|getqflist()| for the supported items in {what}.
+ If {what} contains 'filewinid', then returns the id of the
+ window used to display files from the location list. This
+ field is applicable only when called from a location list
+ window.
getmatches() *getmatches()*
Returns a |List| with all matches previously defined for the
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 4483ada3e4..13e8a73af4 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -4809,7 +4809,8 @@ enum {
QF_GETLIST_IDX = 0x40,
QF_GETLIST_SIZE = 0x80,
QF_GETLIST_TICK = 0x100,
- QF_GETLIST_ALL = 0x1FF
+ QF_GETLIST_FILEWINID = 0x200,
+ QF_GETLIST_ALL = 0x3FF,
};
/// Parse text from 'di' and return the quickfix list items.
@@ -4865,12 +4866,17 @@ static int qf_winid(qf_info_T *qi)
}
/// Convert the keys in 'what' to quickfix list property flags.
-static int qf_getprop_keys2flags(dict_T *what)
+static int qf_getprop_keys2flags(const dict_T *what, bool loclist)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
int flags = QF_GETLIST_NONE;
if (tv_dict_find(what, S_LEN("all")) != NULL) {
flags |= QF_GETLIST_ALL;
+ if (!loclist) {
+ // File window ID is applicable only to location list windows
+ flags &= ~QF_GETLIST_FILEWINID;
+ }
}
if (tv_dict_find(what, S_LEN("title")) != NULL) {
flags |= QF_GETLIST_TITLE;
@@ -4899,6 +4905,9 @@ static int qf_getprop_keys2flags(dict_T *what)
if (tv_dict_find(what, S_LEN("changedtick")) != NULL) {
flags |= QF_GETLIST_TICK;
}
+ if (loclist && tv_dict_find(what, S_LEN("filewinid")) != NULL) {
+ flags |= QF_GETLIST_FILEWINID;
+ }
return flags;
}
@@ -4984,6 +4993,9 @@ static int qf_getprop_defaults(qf_info_T *qi, int flags, dict_T *retdict)
if ((status == OK) && (flags & QF_GETLIST_TICK)) {
status = tv_dict_add_nr(retdict, S_LEN("changedtick"), 0);
}
+ if ((status == OK) && (qi != &ql_info) && (flags & QF_GETLIST_FILEWINID)) {
+ status = tv_dict_add_nr(retdict, S_LEN("filewinid"), 0);
+ }
return status;
}
@@ -4995,6 +5007,25 @@ static int qf_getprop_title(qf_info_T *qi, int qf_idx, dict_T *retdict)
(const char *)qi->qf_lists[qf_idx].qf_title);
}
+// Returns the identifier of the window used to display files from a location
+// list. If there is no associated window, then returns 0. Useful only when
+// called from a location list window.
+static int qf_getprop_filewinid(const win_T *wp, const qf_info_T *qi,
+ dict_T *retdict)
+ FUNC_ATTR_NONNULL_ARG(3)
+{
+ handle_T winid = 0;
+
+ if (wp != NULL && IS_LL_WINDOW(wp)) {
+ win_T *ll_wp = qf_find_win_with_loclist(qi);
+ if (ll_wp != NULL) {
+ winid = ll_wp->handle;
+ }
+ }
+
+ return tv_dict_add_nr(retdict, S_LEN("filewinid"), winid);
+}
+
/// Return the quickfix list items/entries as 'items' in retdict
static int qf_getprop_items(qf_info_T *qi, int qf_idx, dict_T *retdict)
{
@@ -5053,7 +5084,7 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
qi = GET_LOC_LIST(wp);
}
- int flags = qf_getprop_keys2flags(what);
+ const int flags = qf_getprop_keys2flags(what, wp != NULL);
if (qi != NULL && qi->qf_listcount != 0) {
qf_idx = qf_getprop_qfidx(qi, what);
@@ -5093,6 +5124,9 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
status = tv_dict_add_nr(retdict, S_LEN("changedtick"),
qi->qf_lists[qf_idx].qf_changedtick);
}
+ if ((status == OK) && (wp != NULL) && (flags & QF_GETLIST_FILEWINID)) {
+ status = qf_getprop_filewinid(wp, qi, retdict);
+ }
return status;
}
diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim
index fc514fc9e6..4af986ffba 100644
--- a/src/nvim/testdir/test_quickfix.vim
+++ b/src/nvim/testdir/test_quickfix.vim
@@ -1963,6 +1963,18 @@ func Xproperty_tests(cchar)
call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
+ " Test for getting id of window associated with a location list window
+ if a:cchar == 'l'
+ only
+ call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
+ let wid = win_getid()
+ Xopen
+ call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
+ wincmd w
+ call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
+ only
+ endif
+
" The following used to crash Vim with address sanitizer
call g:Xsetlist([], 'f')
call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
@@ -3075,7 +3087,17 @@ func Xgetlist_empty_tests(cchar)
call assert_equal('', g:Xgetlist({'title' : 0}).title)
call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
- call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, 'changedtick': 0}, g:Xgetlist({'all' : 0}))
+ if a:cchar == 'c'
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
+ \ 'items' : [], 'nr' : 0, 'size' : 0,
+ \ 'title' : '', 'winid' : 0, 'changedtick': 0},
+ \ g:Xgetlist({'all' : 0}))
+ else
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
+ \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
+ \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0},
+ \ g:Xgetlist({'all' : 0}))
+ endif
" Quickfix window with empty stack
silent! Xopen
@@ -3108,7 +3130,16 @@ func Xgetlist_empty_tests(cchar)
call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
- call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
+ if a:cchar == 'c'
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
+ \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
+ \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
+ else
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
+ \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
+ \ 'changedtick' : 0, 'filewinid' : 0},
+ \ g:Xgetlist({'id' : qfid, 'all' : 0}))
+ endif
" Non-existing quickfix list number
call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
@@ -3120,7 +3151,16 @@ func Xgetlist_empty_tests(cchar)
call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
- call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, 'changedtick' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0}))
+ if a:cchar == 'c'
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
+ \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
+ \ 'changedtick' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0}))
+ else
+ call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
+ \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
+ \ 'changedtick' : 0, 'filewinid' : 0},
+ \ g:Xgetlist({'nr' : 5, 'all' : 0}))
+ endif
endfunc
func Test_getqflist()