vim-patch:9.1.0629: Rename of pum hl_group is incomplete

Problem:  Rename of pum hl_group is incomplete in source.
Solution: Also rename the test function.  Rename to user_hlattr in code
          to avoid confusion with pum_extra.  Add test with matched text
          highlighting (zeertzjq).

closes: vim/vim#15348

4100852e09
This commit is contained in:
zeertzjq 2024-07-27 21:44:05 +08:00
parent 985c636aa6
commit b8b0e9db3f
7 changed files with 98 additions and 32 deletions

View File

@ -1177,12 +1177,12 @@ items:
user_data custom data which is associated with the item and user_data custom data which is associated with the item and
available in |v:completed_item|; it can be any type; available in |v:completed_item|; it can be any type;
defaults to an empty string defaults to an empty string
hl_group allows specifying an additional highlight group to hl_group an additional highlight group whose attributes are
apply extra attributes to completion items in the combined with |hl-PmenuSel| and |hl-Pmenu| or
popupmenu. Is combined with |hl-PmenuSel| and |hl-PmenuMatchSel| and |hl-PmenuMatch| highlight
|hl-Pmenu| highlighting attributes to apply cterm and attributes in the popup menu to apply cterm and gui
gui properties, such as strikethrough to the properties (with higher priority) like strikethrough
completion items. to the completion items
All of these except "icase", "equal", "dup" and "empty" must be a string. If All of these except "icase", "equal", "dup" and "empty" must be a string. If
an item does not meet these requirements then an error message is given and an item does not meet these requirements then an error message is given and

View File

@ -356,7 +356,7 @@ static int cmdline_pum_create(CmdlineInfo *ccline, expand_T *xp, char **matches,
.pum_info = NULL, .pum_info = NULL,
.pum_extra = NULL, .pum_extra = NULL,
.pum_kind = NULL, .pum_kind = NULL,
.pum_extrahlattr = -1, .pum_user_hlattr = -1,
}; };
} }

View File

@ -171,7 +171,7 @@ struct compl_S {
int cp_flags; ///< CP_ values int cp_flags; ///< CP_ values
int cp_number; ///< sequence number int cp_number; ///< sequence number
int cp_score; ///< fuzzy match score int cp_score; ///< fuzzy match score
int cp_extrahlattr; ///< extra extra highlight group attr int cp_user_hlattr; ///< highlight attribute to combine with
}; };
/// state information used for getting the next set of insert completion /// state information used for getting the next set of insert completion
@ -804,7 +804,7 @@ static inline void free_cptext(char *const *const cptext)
/// returned in case of error. /// returned in case of error.
static int ins_compl_add(char *const str, int len, char *const fname, char *const *const cptext, static int ins_compl_add(char *const str, int len, char *const fname, char *const *const cptext,
const bool cptext_allocated, typval_T *user_data, const Direction cdir, const bool cptext_allocated, typval_T *user_data, const Direction cdir,
int flags_arg, const bool adup, int extra_hlattr) int flags_arg, const bool adup, int user_hlattr)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
compl_T *match; compl_T *match;
@ -870,7 +870,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
match->cp_fname = NULL; match->cp_fname = NULL;
} }
match->cp_flags = flags; match->cp_flags = flags;
match->cp_extrahlattr = extra_hlattr; match->cp_user_hlattr = user_hlattr;
if (cptext != NULL) { if (cptext != NULL) {
int i; int i;
@ -1271,7 +1271,7 @@ static int ins_compl_build_pum(void)
compl_match_array[i].pum_kind = comp->cp_text[CPT_KIND]; compl_match_array[i].pum_kind = comp->cp_text[CPT_KIND];
compl_match_array[i].pum_info = comp->cp_text[CPT_INFO]; compl_match_array[i].pum_info = comp->cp_text[CPT_INFO];
compl_match_array[i].pum_score = comp->cp_score; compl_match_array[i].pum_score = comp->cp_score;
compl_match_array[i].pum_extrahlattr = comp->cp_extrahlattr; compl_match_array[i].pum_user_hlattr = comp->cp_user_hlattr;
if (comp->cp_text[CPT_MENU] != NULL) { if (comp->cp_text[CPT_MENU] != NULL) {
compl_match_array[i++].pum_extra = comp->cp_text[CPT_MENU]; compl_match_array[i++].pum_extra = comp->cp_text[CPT_MENU];
} else { } else {
@ -2556,8 +2556,8 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
bool empty = false; bool empty = false;
int flags = fast ? CP_FAST : 0; int flags = fast ? CP_FAST : 0;
char *(cptext[CPT_COUNT]); char *(cptext[CPT_COUNT]);
char *extra_hlname = NULL; char *user_hlname = NULL;
int extra_hlattr = -1; int user_hlattr = -1;
typval_T user_data; typval_T user_data;
user_data.v_type = VAR_UNKNOWN; user_data.v_type = VAR_UNKNOWN;
@ -2567,9 +2567,9 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
cptext[CPT_MENU] = tv_dict_get_string(tv->vval.v_dict, "menu", true); cptext[CPT_MENU] = tv_dict_get_string(tv->vval.v_dict, "menu", true);
cptext[CPT_KIND] = tv_dict_get_string(tv->vval.v_dict, "kind", true); cptext[CPT_KIND] = tv_dict_get_string(tv->vval.v_dict, "kind", true);
cptext[CPT_INFO] = tv_dict_get_string(tv->vval.v_dict, "info", true); cptext[CPT_INFO] = tv_dict_get_string(tv->vval.v_dict, "info", true);
extra_hlname = tv_dict_get_string(tv->vval.v_dict, "hl_group", false); user_hlname = tv_dict_get_string(tv->vval.v_dict, "hl_group", false);
if (extra_hlname != NULL && *extra_hlname != NUL) { if (user_hlname != NULL && *user_hlname != NUL) {
extra_hlattr = syn_name2attr(extra_hlname); user_hlattr = syn_name2attr(user_hlname);
} }
tv_dict_get_tv(tv->vval.v_dict, "user_data", &user_data); tv_dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
@ -2592,7 +2592,7 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
return FAIL; return FAIL;
} }
int status = ins_compl_add((char *)word, -1, NULL, cptext, true, int status = ins_compl_add((char *)word, -1, NULL, cptext, true,
&user_data, dir, flags, dup, extra_hlattr); &user_data, dir, flags, dup, user_hlattr);
if (status != OK) { if (status != OK) {
tv_clear(&user_data); tv_clear(&user_data);
} }

View File

@ -440,7 +440,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
/// Computes attributes of text on the popup menu. /// Computes attributes of text on the popup menu.
/// Returns attributes for every cell, or NULL if all attributes are the same. /// Returns attributes for every cell, or NULL if all attributes are the same.
static int *pum_compute_text_attrs(char *text, hlf_T hlf, int extra_hlattr) static int *pum_compute_text_attrs(char *text, hlf_T hlf, int user_hlattr)
{ {
if ((hlf != HLF_PSI && hlf != HLF_PNI) if ((hlf != HLF_PSI && hlf != HLF_PNI)
|| (win_hl_attr(curwin, HLF_PMSI) == win_hl_attr(curwin, HLF_PSI) || (win_hl_attr(curwin, HLF_PMSI) == win_hl_attr(curwin, HLF_PSI)
@ -486,8 +486,9 @@ static int *pum_compute_text_attrs(char *text, hlf_T hlf, int extra_hlattr)
} else if (matched_start && ptr < text + leader_len) { } else if (matched_start && ptr < text + leader_len) {
new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI); new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI);
} }
if (extra_hlattr > 0) {
new_attr = hl_combine_attr(new_attr, extra_hlattr); if (user_hlattr > 0) {
new_attr = hl_combine_attr(new_attr, user_hlattr);
} }
int char_cells = utf_ptr2cells(ptr); int char_cells = utf_ptr2cells(ptr);
@ -630,8 +631,8 @@ void pum_redraw(void)
for (int round = 0; round < 3; round++) { for (int round = 0; round < 3; round++) {
hlf = hlfs[round]; hlf = hlfs[round];
attr = win_hl_attr(curwin, (int)hlf); attr = win_hl_attr(curwin, (int)hlf);
if (pum_array[idx].pum_extrahlattr > 0) { if (pum_array[idx].pum_user_hlattr > 0) {
attr = hl_combine_attr(attr, pum_array[idx].pum_extrahlattr); attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr);
} }
int width = 0; int width = 0;
char *s = NULL; char *s = NULL;
@ -666,7 +667,8 @@ void pum_redraw(void)
*p = saved; *p = saved;
} }
int *attrs = pum_compute_text_attrs(st, hlf, pum_array[idx].pum_extrahlattr); int user_hlattr = pum_array[idx].pum_user_hlattr;
int *attrs = pum_compute_text_attrs(st, hlf, user_hlattr);
if (pum_rl) { if (pum_rl) {
char *rt = reverse_text(st); char *rt = reverse_text(st);

View File

@ -16,7 +16,7 @@ typedef struct {
char *pum_info; ///< extra info char *pum_info; ///< extra info
int pum_score; ///< fuzzy match score int pum_score; ///< fuzzy match score
int pum_idx; ///< index of item before sorting by score int pum_idx; ///< index of item before sorting by score
int pum_extrahlattr; ///< extra highlight group attr for combine int pum_user_hlattr; ///< highlight attribute to combine with
} pumitem_T; } pumitem_T;
EXTERN ScreenGrid pum_grid INIT( = SCREEN_GRID_INIT); EXTERN ScreenGrid pum_grid INIT( = SCREEN_GRID_INIT);

View File

@ -1181,6 +1181,26 @@ describe('builtin popupmenu', function()
mn = { foreground = Screen.colors.Blue, background = Screen.colors.Plum1 }, mn = { foreground = Screen.colors.Blue, background = Screen.colors.Plum1 },
ds = { foreground = Screen.colors.DarkRed, background = Screen.colors.Grey }, ds = { foreground = Screen.colors.DarkRed, background = Screen.colors.Grey },
dn = { foreground = Screen.colors.DarkRed, background = Screen.colors.Plum1 }, dn = { foreground = Screen.colors.DarkRed, background = Screen.colors.Plum1 },
ums = {
foreground = Screen.colors.Blue,
background = Screen.colors.Grey,
underline = true,
},
umn = {
foreground = Screen.colors.Blue,
background = Screen.colors.Plum1,
underline = true,
},
uds = {
foreground = Screen.colors.DarkRed,
background = Screen.colors.Grey,
underline = true,
},
udn = {
foreground = Screen.colors.DarkRed,
background = Screen.colors.Plum1,
underline = true,
},
}) })
screen:attach({ ext_multigrid = multigrid }) screen:attach({ ext_multigrid = multigrid })
end) end)
@ -4934,10 +4954,9 @@ describe('builtin popupmenu', function()
feed('<C-E><Esc>') feed('<C-E><Esc>')
end) end)
-- oldtest: Test_pum_extrahl() -- oldtest: Test_pum_user_hl_group()
it('custom hl_group override', function() it('custom hl_group override', function()
exec([[ exec([[
hi StrikeFake guifg=DarkRed
func CompleteFunc( findstart, base ) func CompleteFunc( findstart, base )
if a:findstart if a:findstart
return 0 return 0
@ -4951,8 +4970,15 @@ describe('builtin popupmenu', function()
endfunc endfunc
set completeopt=menu set completeopt=menu
set completefunc=CompleteFunc set completefunc=CompleteFunc
hi StrikeFake guifg=DarkRed
func HlMatch()
hi PmenuMatchSel guifg=Blue guibg=Grey gui=underline
hi PmenuMatch guifg=Blue guibg=Plum1 gui=underline
endfunc
]]) ]])
feed('<ESC>iaw<C-X><C-U>')
feed('Saw<C-X><C-U>')
screen:expect([[ screen:expect([[
aword1^ | aword1^ |
{ds:aword1 W extra text 1 }{1: }| {ds:aword1 W extra text 1 }{1: }|
@ -4961,6 +4987,29 @@ describe('builtin popupmenu', function()
{1:~ }|*15 {1:~ }|*15
{2:-- }{5:match 1 of 3} | {2:-- }{5:match 1 of 3} |
]]) ]])
feed('<C-E><Esc>')
command('call HlMatch()')
feed('Saw<C-X><C-U>')
screen:expect([[
aword1^ |
{uds:aw}{ds:ord1 W extra text 1 }{1: }|
{umn:aw}{n:ord2 W extra text 2 }{1: }|
{dn: W extra text 3 }{1: }|
{1:~ }|*15
{2:-- }{5:match 1 of 3} |
]])
feed('<C-N>')
screen:expect([[
aword2^ |
{udn:aw}{dn:ord1 W extra text 1 }{1: }|
{ums:aw}{s:ord2 W extra text 2 }{1: }|
{dn: W extra text 3 }{1: }|
{1:~ }|*15
{2:-- }{5:match 2 of 3} |
]])
feed('<C-E><Esc>')
end) end)
end end
end end

View File

@ -1506,10 +1506,9 @@ func Test_pum_highlights_match()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
func Test_pum_extrahl() func Test_pum_user_hl_group()
CheckScreendump CheckScreendump
let lines =<< trim END let lines =<< trim END
hi StrikeFake ctermfg=9
func CompleteFunc( findstart, base ) func CompleteFunc( findstart, base )
if a:findstart if a:findstart
return 0 return 0
@ -1523,15 +1522,31 @@ func Test_pum_extrahl()
endfunc endfunc
set completeopt=menu set completeopt=menu
set completefunc=CompleteFunc set completefunc=CompleteFunc
hi StrikeFake ctermfg=9
func HlMatch()
hi PmenuMatchSel ctermfg=6 ctermbg=7 cterm=underline
hi PmenuMatch ctermfg=4 ctermbg=225 cterm=underline
endfunc
END END
call writefile(lines, 'Xscript', 'D') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {}) let buf = RunVimInTerminal('-S Xscript', {})
call TermWait(buf) call TermWait(buf)
call term_sendkeys(buf, "iaw\<C-X>\<C-u>") call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
call TermWait(buf, 50)
call VerifyScreenDump(buf, 'Test_pum_highlights_12', {}) call VerifyScreenDump(buf, 'Test_pum_highlights_12', {})
call term_sendkeys(buf, "\<C-E>\<Esc>u") call term_sendkeys(buf, "\<C-E>\<Esc>")
call TermWait(buf) call TermWait(buf)
call term_sendkeys(buf, ":call HlMatch()\<CR>")
call TermWait(buf)
call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
call VerifyScreenDump(buf, 'Test_pum_highlights_13', {})
call term_sendkeys(buf, "\<C-N>")
call VerifyScreenDump(buf, 'Test_pum_highlights_14', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc