Skip to content

Commit dca7abe

Browse files
committed
patch 8.1.2192: cannot easily fill the info popup asynchronously
Problem: Cannot easily fill the info popup asynchronously. Solution: Add the "popuphidden" value to 'completeopt'. (closes #4924)
1 parent 88d3d09 commit dca7abe

15 files changed

Lines changed: 195 additions & 28 deletions

runtime/doc/insert.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*insert.txt* For Vim version 8.1. Last change: 2019 Sep 27
1+
*insert.txt* For Vim version 8.1. Last change: 2019 Oct 20
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1138,6 +1138,27 @@ below the text, and the bottom of the menu otherwise.
11381138
After the info popup is created it can be found with |popup_findinfo()| and
11391139
properties can be changed with |popup_setoptions()|.
11401140

1141+
*complete-popuphidden*
1142+
If the information for the popup is obtained asynchronously, use "popuphidden"
1143+
in 'completeopt'. The info popup will then be initally hidden and
1144+
|popup_show()| must be called once it has been filled with the info. This can
1145+
be done with a |CompleteChanged| autocommand, something like this: >
1146+
set completeopt+=popuphidden
1147+
au CompleteChanged * call UpdateCompleteInfo()
1148+
func UpdateCompleteInfo()
1149+
" Cancel any pending info fetch
1150+
let item = v:event.completed_item
1151+
" Start fetching info for the item then call ShowCompleteInfo(info)
1152+
endfunc
1153+
func ShowCompleteInfo(info)
1154+
let id = popup_findinfo()
1155+
if id
1156+
call popup_settext(id, 'async info: ' .. a:info)
1157+
call popup_show(id)
1158+
endif
1159+
endfunc
1160+
1161+
< *complete-item-kind*
11411162
The "kind" item uses a single letter to indicate the kind of completion. This
11421163
may be used to show the completion differently (different color or icon).
11431164
Currently these types can be used:

runtime/doc/options.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 8.1. Last change: 2019 Sep 28
1+
*options.txt* For Vim version 8.1. Last change: 2019 Oct 20
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1919,6 +1919,13 @@ A jump table for the options with a short description can be found at |Q_op|.
19191919
See |'completepopup'| for specifying properties.
19201920
{only works when compiled with the |+textprop| feature}
19211921

1922+
popuphidden
1923+
Just like "popup" but initially hide the popup. Use a
1924+
|CompleteChanged| autocommand to fetch the info and call
1925+
|popup_show()| once the popup has been filled.
1926+
See the example at |complete-popuphidden|.
1927+
{only works when compiled with the |+textprop| feature}
1928+
19221929
noinsert Do not insert any text for a match until the user selects
19231930
a match from the menu. Only works in combination with
19241931
"menu" or "menuone". No effect if "longest" is present.

src/ex_cmds.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,13 +4919,14 @@ free_old_sub(void)
49194919
#if defined(FEAT_QUICKFIX) || defined(PROTO)
49204920
/*
49214921
* Set up for a tagpreview.
4922+
* Makes the preview window the current window.
49224923
* Return TRUE when it was created.
49234924
*/
49244925
int
49254926
prepare_tagpreview(
49264927
int undo_sync, // sync undo when leaving the window
49274928
int use_previewpopup, // use popup if 'previewpopup' set
4928-
int use_popup) // use other popup window
4929+
use_popup_T use_popup) // use other popup window
49294930
{
49304931
win_T *wp;
49314932

@@ -4945,11 +4946,16 @@ prepare_tagpreview(
49454946
if (wp != NULL)
49464947
popup_set_wantpos_cursor(wp, wp->w_minwidth);
49474948
}
4948-
else if (use_popup)
4949+
else if (use_popup != USEPOPUP_NONE)
49494950
{
49504951
wp = popup_find_info_window();
49514952
if (wp != NULL)
4952-
popup_show(wp);
4953+
{
4954+
if (use_popup == USEPOPUP_NORMAL)
4955+
popup_show(wp);
4956+
else
4957+
popup_hide(wp);
4958+
}
49534959
}
49544960
else
49554961
# endif
@@ -4966,8 +4972,9 @@ prepare_tagpreview(
49664972
* There is no preview window open yet. Create one.
49674973
*/
49684974
# ifdef FEAT_TEXT_PROP
4969-
if ((use_previewpopup && *p_pvp != NUL) || use_popup)
4970-
return popup_create_preview_window(use_popup);
4975+
if ((use_previewpopup && *p_pvp != NUL)
4976+
|| use_popup != USEPOPUP_NONE)
4977+
return popup_create_preview_window(use_popup != USEPOPUP_NONE);
49714978
# endif
49724979
if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) == FAIL)
49734980
return FALSE;

src/optionstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
7676
NULL};
7777
static char *(p_fcl_values[]) = {"all", NULL};
7878
#endif
79-
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
79+
static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "popuphidden", "noinsert", "noselect", NULL};
8080
#ifdef BACKSLASH_IN_FILENAME
8181
static char *(p_csl_values[]) = {"slash", "backslash", NULL};
8282
#endif

src/popupmenu.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -622,33 +622,36 @@ pum_redraw(void)
622622
}
623623

624624
#if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
625-
static void
626-
pum_position_info_popup(void)
625+
/*
626+
* Position the info popup relative to the popup menu item.
627+
*/
628+
void
629+
pum_position_info_popup(win_T *wp)
627630
{
628631
int col = pum_col + pum_width + 1;
629632
int row = pum_row;
630633
int botpos = POPPOS_BOTLEFT;
631634

632-
curwin->w_popup_pos = POPPOS_TOPLEFT;
635+
wp->w_popup_pos = POPPOS_TOPLEFT;
633636
if (Columns - col < 20 && Columns - col < pum_col)
634637
{
635638
col = pum_col - 1;
636-
curwin->w_popup_pos = POPPOS_TOPRIGHT;
639+
wp->w_popup_pos = POPPOS_TOPRIGHT;
637640
botpos = POPPOS_BOTRIGHT;
638-
curwin->w_maxwidth = pum_col - 1;
641+
wp->w_maxwidth = pum_col - 1;
639642
}
640643
else
641-
curwin->w_maxwidth = Columns - col + 1;
642-
curwin->w_maxwidth -= popup_extra_width(curwin);
644+
wp->w_maxwidth = Columns - col + 1;
645+
wp->w_maxwidth -= popup_extra_width(wp);
643646

644-
row -= popup_top_extra(curwin);
645-
if (curwin->w_popup_flags & POPF_INFO_MENU)
647+
row -= popup_top_extra(wp);
648+
if (wp->w_popup_flags & POPF_INFO_MENU)
646649
{
647650
if (pum_row < pum_win_row)
648651
{
649652
// menu above cursor line, align with bottom
650653
row += pum_height;
651-
curwin->w_popup_pos = botpos;
654+
wp->w_popup_pos = botpos;
652655
}
653656
else
654657
// menu below cursor line, align with top
@@ -658,7 +661,7 @@ pum_position_info_popup(void)
658661
// align with the selected item
659662
row += pum_selected - pum_first + 1;
660663

661-
popup_set_wantpos_rowcol(curwin, row, col);
664+
popup_set_wantpos_rowcol(wp, row, col);
662665
}
663666
#endif
664667

@@ -756,15 +759,21 @@ pum_set_selected(int n, int repeat UNUSED)
756759
tabpage_T *curtab_save = curtab;
757760
int res = OK;
758761
# ifdef FEAT_TEXT_PROP
759-
int use_popup = strstr((char *)p_cot, "popup") != NULL;
762+
use_popup_T use_popup;
760763
# else
761-
# define use_popup 0
764+
# define use_popup POPUP_NONE
762765
# endif
763766
# ifdef FEAT_TEXT_PROP
764767
has_info = TRUE;
768+
if (strstr((char *)p_cot, "popuphidden") != NULL)
769+
use_popup = USEPOPUP_HIDDEN;
770+
else if (strstr((char *)p_cot, "popup") != NULL)
771+
use_popup = USEPOPUP_NORMAL;
772+
else
773+
use_popup = USEPOPUP_NONE;
765774
# endif
766-
// Open a preview window. 3 lines by default. Prefer
767-
// 'previewheight' if set and smaller.
775+
// Open a preview window and set "curwin" to it.
776+
// 3 lines by default, prefer 'previewheight' if set and smaller.
768777
g_do_tagpreview = 3;
769778
if (p_pvh > 0 && p_pvh < g_do_tagpreview)
770779
g_do_tagpreview = p_pvh;
@@ -838,7 +847,7 @@ pum_set_selected(int n, int repeat UNUSED)
838847

839848
/* Increase the height of the preview window to show the
840849
* text, but no more than 'previewheight' lines. */
841-
if (repeat == 0 && !use_popup)
850+
if (repeat == 0 && use_popup == USEPOPUP_NONE)
842851
{
843852
if (lnum > p_pvh)
844853
lnum = p_pvh;
@@ -863,9 +872,9 @@ pum_set_selected(int n, int repeat UNUSED)
863872
curwin->w_cursor.lnum = curwin->w_topline;
864873
curwin->w_cursor.col = 0;
865874
# ifdef FEAT_TEXT_PROP
866-
if (use_popup)
875+
if (use_popup != USEPOPUP_NONE)
867876
{
868-
pum_position_info_popup();
877+
pum_position_info_popup(curwin);
869878
if (win_valid(curwin_save))
870879
redraw_win_later(curwin_save, SOME_VALID);
871880
}
@@ -907,9 +916,16 @@ pum_set_selected(int n, int repeat UNUSED)
907916

908917
if (!resized && win_valid(curwin_save))
909918
{
919+
# ifdef FEAT_TEXT_PROP
920+
win_T *wp = curwin;
921+
# endif
910922
++no_u_sync;
911923
win_enter(curwin_save, TRUE);
912924
--no_u_sync;
925+
# ifdef FEAT_TEXT_PROP
926+
if (use_popup == USEPOPUP_HIDDEN && win_valid(wp))
927+
popup_hide(wp);
928+
# endif
913929
}
914930

915931
/* May need to update the screen again when there are

src/popupwin.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
22252225
popup_close_and_callback(wp, &argvars[1]);
22262226
}
22272227

2228-
static void
2228+
void
22292229
popup_hide(win_T *wp)
22302230
{
22312231
if ((wp->w_popup_flags & POPF_HIDDEN) == 0)
@@ -2272,7 +2272,11 @@ f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
22722272
win_T *wp = find_popup_win(id);
22732273

22742274
if (wp != NULL)
2275+
{
22752276
popup_show(wp);
2277+
if (wp->w_popup_flags & POPF_INFO)
2278+
pum_position_info_popup(wp);
2279+
}
22762280
}
22772281

22782282
/*

src/proto/ex_cmds.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void global_exe(char_u *cmd);
3535
char_u *get_old_sub(void);
3636
void set_old_sub(char_u *val);
3737
void free_old_sub(void);
38-
int prepare_tagpreview(int undo_sync, int use_previewpopup, int use_popup);
38+
int prepare_tagpreview(int undo_sync, int use_previewpopup, use_popup_T use_popup);
3939
void ex_help(exarg_T *eap);
4040
void ex_helpclose(exarg_T *eap);
4141
char_u *check_help_lang(char_u *arg);

src/proto/popupmenu.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ void pum_display(pumitem_T *array, int size, int selected);
33
void pum_call_update_screen(void);
44
int pum_under_menu(int row, int col);
55
void pum_redraw(void);
6+
void pum_position_info_popup(win_T *wp);
67
void pum_undisplay(void);
78
void pum_clear(void);
89
int pum_visible(void);

src/proto/popupwin.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void f_popup_dialog(typval_T *argvars, typval_T *rettv);
2626
void f_popup_menu(typval_T *argvars, typval_T *rettv);
2727
void f_popup_notification(typval_T *argvars, typval_T *rettv);
2828
void f_popup_close(typval_T *argvars, typval_T *rettv);
29+
void popup_hide(win_T *wp);
2930
void f_popup_hide(typval_T *argvars, typval_T *rettv);
3031
void popup_show(win_T *wp);
3132
void f_popup_show(typval_T *argvars, typval_T *rettv);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
|t+0&#ffffff0|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t|a|w|o|r|d> @43
2+
|~+0#4040ff13&| @23| +0#0000001#e0e0e08|w|r|d| @4|W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
3+
|~| @23| +0#0000001#ffd7ff255|a|n|o|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
4+
|~| @23| +0#0000001#ffd7ff255|n|o|a|w|r|d| @1|W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
5+
|~| @23| +0#0000001#ffd7ff255|t|h|a|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |4| +0#0000000&@26

0 commit comments

Comments
 (0)