0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

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 #3202)
This commit is contained in:
Bram Moolenaar 2018-09-02 15:18:42 +02:00
parent 7ee3f15b21
commit c9cc9c78f2
4 changed files with 85 additions and 6 deletions

View File

@ -4729,6 +4729,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 by

View File

@ -5670,7 +5670,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,
};
/*
@ -5744,12 +5745,17 @@ qf_winid(qf_info_T *qi)
* Convert the keys in 'what' to quickfix list property flags.
*/
static int
qf_getprop_keys2flags(dict_T *what)
qf_getprop_keys2flags(dict_T *what, int loclist)
{
int flags = QF_GETLIST_NONE;
if (dict_find(what, (char_u *)"all", -1) != NULL)
{
flags |= QF_GETLIST_ALL;
if (!loclist)
// File window ID is applicable only to location list windows
flags &= ~ QF_GETLIST_FILEWINID;
}
if (dict_find(what, (char_u *)"title", -1) != NULL)
flags |= QF_GETLIST_TITLE;
@ -5778,6 +5784,9 @@ qf_getprop_keys2flags(dict_T *what)
if (dict_find(what, (char_u *)"changedtick", -1) != NULL)
flags |= QF_GETLIST_TICK;
if (loclist && dict_find(what, (char_u *)"filewinid", -1) != NULL)
flags |= QF_GETLIST_FILEWINID;
return flags;
}
@ -5870,6 +5879,8 @@ qf_getprop_defaults(qf_info_T *qi, int flags, dict_T *retdict)
status = dict_add_number(retdict, "size", 0);
if ((status == OK) && (flags & QF_GETLIST_TICK))
status = dict_add_number(retdict, "changedtick", 0);
if ((status == OK) && (qi != &ql_info) && (flags & QF_GETLIST_FILEWINID))
status = dict_add_number(retdict, "filewinid", 0);
return status;
}
@ -5883,6 +5894,26 @@ qf_getprop_title(qf_info_T *qi, int qf_idx, dict_T *retdict)
return dict_add_string(retdict, "title", 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(win_T *wp, qf_info_T *qi, dict_T *retdict)
{
int 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->w_id;
}
return dict_add_number(retdict, "filewinid", winid);
}
/*
* Return the quickfix list items/entries as 'items' in retdict
*/
@ -5963,7 +5994,7 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
if (wp != NULL)
qi = GET_LOC_LIST(wp);
flags = qf_getprop_keys2flags(what);
flags = qf_getprop_keys2flags(what, (wp != NULL));
if (qi != NULL && qi->qf_listcount != 0)
qf_idx = qf_getprop_qfidx(qi, what);
@ -5992,6 +6023,8 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
if ((status == OK) && (flags & QF_GETLIST_TICK))
status = dict_add_number(retdict, "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;
}

View File

@ -1973,6 +1973,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}]})
@ -3000,7 +3012,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
@ -3033,7 +3055,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)
@ -3045,7 +3076,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()

View File

@ -794,6 +794,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
345,
/**/
344,
/**/