mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
c9cc9c78f2
This commit is contained in:
parent
5e02bd071e
commit
f3d6d8750b
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user