mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 9.1.0618: cannot mark deprecated attributes in completion menu
Problem: cannot mark deprecated attributes in completion menu Solution: add hl_group to the Dictionary of supported completion fields (glepnir) closes: #15314 Signed-off-by: glepnir <glephunter@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
dc373d456b
commit
508e7856ec
@@ -1,4 +1,4 @@
|
|||||||
*insert.txt* For Vim version 9.1. Last change: 2024 Jul 13
|
*insert.txt* For Vim version 9.1. Last change: 2024 Jul 25
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@@ -1183,6 +1183,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
|
||||||
|
apply extra attributes to completion items in the
|
||||||
|
popupmenu. Is combined with |hl-PmenuSel| and
|
||||||
|
|hl-Pmenu| highlighting attributes to apply cterm and
|
||||||
|
gui properties, such as strikethrough 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
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
*version9.txt* For Vim version 9.1. Last change: 2024 Jul 15
|
*version9.txt* For Vim version 9.1. Last change: 2024 Jul 25
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@@ -41588,6 +41588,8 @@ Changed~
|
|||||||
|getcompletion()|
|
|getcompletion()|
|
||||||
- add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
|
- add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
|
||||||
behaviour/inconsistency (see |d-special| and |cw|).
|
behaviour/inconsistency (see |d-special| and |cw|).
|
||||||
|
- allow to specify additional attributes in the completion menu (allows to
|
||||||
|
mark deprecated attributes from LSP server) |complete-items|
|
||||||
|
|
||||||
*added-9.2*
|
*added-9.2*
|
||||||
Added ~
|
Added ~
|
||||||
|
@@ -359,6 +359,7 @@ cmdline_pum_create(
|
|||||||
compl_match_array[i].pum_info = NULL;
|
compl_match_array[i].pum_info = NULL;
|
||||||
compl_match_array[i].pum_extra = NULL;
|
compl_match_array[i].pum_extra = NULL;
|
||||||
compl_match_array[i].pum_kind = NULL;
|
compl_match_array[i].pum_kind = NULL;
|
||||||
|
compl_match_array[i].pum_extrahlattr = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the popup menu starting column
|
// Compute the popup menu starting column
|
||||||
|
@@ -114,6 +114,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 highlight group attr
|
||||||
};
|
};
|
||||||
|
|
||||||
// values for cp_flags
|
// values for cp_flags
|
||||||
@@ -205,7 +206,7 @@ static int compl_selected_item = -1;
|
|||||||
|
|
||||||
static int *compl_fuzzy_scores;
|
static int *compl_fuzzy_scores;
|
||||||
|
|
||||||
static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup);
|
static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup, int extrahl);
|
||||||
static void ins_compl_longest_match(compl_T *match);
|
static void ins_compl_longest_match(compl_T *match);
|
||||||
static void ins_compl_del_pum(void);
|
static void ins_compl_del_pum(void);
|
||||||
static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
|
static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
|
||||||
@@ -745,7 +746,7 @@ ins_compl_add_infercase(
|
|||||||
if (icase)
|
if (icase)
|
||||||
flags |= CP_ICASE;
|
flags |= CP_ICASE;
|
||||||
|
|
||||||
res = ins_compl_add(str, len, fname, NULL, NULL, dir, flags, FALSE);
|
res = ins_compl_add(str, len, fname, NULL, NULL, dir, flags, FALSE, -1);
|
||||||
vim_free(tofree);
|
vim_free(tofree);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -778,7 +779,8 @@ ins_compl_add(
|
|||||||
typval_T *user_data UNUSED, // "user_data" entry or NULL
|
typval_T *user_data UNUSED, // "user_data" entry or NULL
|
||||||
int cdir,
|
int cdir,
|
||||||
int flags_arg,
|
int flags_arg,
|
||||||
int adup) // accept duplicate match
|
int adup, // accept duplicate match
|
||||||
|
int extra_hlattr)
|
||||||
{
|
{
|
||||||
compl_T *match;
|
compl_T *match;
|
||||||
int dir = (cdir == 0 ? compl_direction : cdir);
|
int dir = (cdir == 0 ? compl_direction : cdir);
|
||||||
@@ -842,6 +844,7 @@ ins_compl_add(
|
|||||||
else
|
else
|
||||||
match->cp_fname = NULL;
|
match->cp_fname = NULL;
|
||||||
match->cp_flags = flags;
|
match->cp_flags = flags;
|
||||||
|
match->cp_extrahlattr = extra_hlattr;
|
||||||
|
|
||||||
if (cptext != NULL)
|
if (cptext != NULL)
|
||||||
{
|
{
|
||||||
@@ -994,7 +997,7 @@ ins_compl_add_matches(
|
|||||||
|
|
||||||
for (i = 0; i < num_matches && add_r != FAIL; i++)
|
for (i = 0; i < num_matches && add_r != FAIL; i++)
|
||||||
if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir,
|
if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir,
|
||||||
CP_FAST | (icase ? CP_ICASE : 0), FALSE)) == OK)
|
CP_FAST | (icase ? CP_ICASE : 0), FALSE, -1)) == OK)
|
||||||
// if dir was BACKWARD then honor it just once
|
// if dir was BACKWARD then honor it just once
|
||||||
dir = FORWARD;
|
dir = FORWARD;
|
||||||
FreeWild(num_matches, matches);
|
FreeWild(num_matches, matches);
|
||||||
@@ -1338,6 +1341,7 @@ ins_compl_build_pum(void)
|
|||||||
compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
|
compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
|
||||||
compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
|
compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
|
||||||
compl_match_array[i].pum_score = compl->cp_score;
|
compl_match_array[i].pum_score = compl->cp_score;
|
||||||
|
compl_match_array[i].pum_extrahlattr = compl->cp_extrahlattr;
|
||||||
if (compl->cp_text[CPT_MENU] != NULL)
|
if (compl->cp_text[CPT_MENU] != NULL)
|
||||||
compl_match_array[i++].pum_extra =
|
compl_match_array[i++].pum_extra =
|
||||||
compl->cp_text[CPT_MENU];
|
compl->cp_text[CPT_MENU];
|
||||||
@@ -2856,6 +2860,8 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
|
|||||||
char_u *(cptext[CPT_COUNT]);
|
char_u *(cptext[CPT_COUNT]);
|
||||||
typval_T user_data;
|
typval_T user_data;
|
||||||
int status;
|
int status;
|
||||||
|
char_u *extra_hlname;
|
||||||
|
int extra_hlattr = -1;
|
||||||
|
|
||||||
user_data.v_type = VAR_UNKNOWN;
|
user_data.v_type = VAR_UNKNOWN;
|
||||||
if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
|
if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
|
||||||
@@ -2865,6 +2871,10 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
|
|||||||
cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE);
|
cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE);
|
||||||
cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE);
|
cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE);
|
||||||
cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE);
|
cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE);
|
||||||
|
extra_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE);
|
||||||
|
if (extra_hlname != NULL && *extra_hlname != NUL)
|
||||||
|
extra_hlattr = syn_name2attr(extra_hlname);
|
||||||
|
|
||||||
dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
|
dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
|
||||||
if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL
|
if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL
|
||||||
&& dict_get_number(tv->vval.v_dict, "icase"))
|
&& dict_get_number(tv->vval.v_dict, "icase"))
|
||||||
@@ -2887,7 +2897,8 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
|
|||||||
clear_tv(&user_data);
|
clear_tv(&user_data);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
status = ins_compl_add(word, -1, NULL, cptext, &user_data, dir, flags, dup);
|
status = ins_compl_add(word, -1, NULL, cptext,
|
||||||
|
&user_data, dir, flags, dup, extra_hlattr);
|
||||||
if (status != OK)
|
if (status != OK)
|
||||||
clear_tv(&user_data);
|
clear_tv(&user_data);
|
||||||
return status;
|
return status;
|
||||||
@@ -2974,7 +2985,7 @@ set_completion(colnr_T startcol, list_T *list)
|
|||||||
flags |= CP_ICASE;
|
flags |= CP_ICASE;
|
||||||
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
||||||
-1, NULL, NULL, NULL, 0,
|
-1, NULL, NULL, NULL, 0,
|
||||||
flags | CP_FAST, FALSE) != OK)
|
flags | CP_FAST, FALSE, -1) != OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ctrl_x_mode = CTRL_X_EVAL;
|
ctrl_x_mode = CTRL_X_EVAL;
|
||||||
@@ -5177,7 +5188,7 @@ ins_compl_start(void)
|
|||||||
if (p_ic)
|
if (p_ic)
|
||||||
flags |= CP_ICASE;
|
flags |= CP_ICASE;
|
||||||
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
|
||||||
-1, NULL, NULL, NULL, 0, flags, FALSE) != OK)
|
-1, NULL, NULL, NULL, 0, flags, FALSE, -1) != OK)
|
||||||
{
|
{
|
||||||
VIM_CLEAR(compl_pattern);
|
VIM_CLEAR(compl_pattern);
|
||||||
compl_patternlen = 0;
|
compl_patternlen = 0;
|
||||||
|
@@ -510,7 +510,8 @@ pum_screen_puts_with_attrs(
|
|||||||
int cells UNUSED,
|
int cells UNUSED,
|
||||||
char_u *text,
|
char_u *text,
|
||||||
int textlen,
|
int textlen,
|
||||||
int *attrs)
|
int *attrs,
|
||||||
|
int extra_attr)
|
||||||
{
|
{
|
||||||
int col_start = col;
|
int col_start = col;
|
||||||
char_u *ptr = text;
|
char_u *ptr = text;
|
||||||
@@ -527,6 +528,8 @@ pum_screen_puts_with_attrs(
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
attr = attrs[col - col_start];
|
attr = attrs[col - col_start];
|
||||||
|
if (extra_attr > 0)
|
||||||
|
attr = hl_combine_attr(extra_attr, attr);
|
||||||
screen_puts_len(ptr, char_len, row, col, attr);
|
screen_puts_len(ptr, char_len, row, col, attr);
|
||||||
col += mb_ptr2cells(ptr);
|
col += mb_ptr2cells(ptr);
|
||||||
ptr += char_len;
|
ptr += char_len;
|
||||||
@@ -628,6 +631,8 @@ pum_redraw(void)
|
|||||||
{
|
{
|
||||||
hlf = hlfs[round];
|
hlf = hlfs[round];
|
||||||
attr = highlight_attr[hlf];
|
attr = highlight_attr[hlf];
|
||||||
|
if (pum_array[idx].pum_extrahlattr > 0)
|
||||||
|
attr = hl_combine_attr(attr, pum_array[idx].pum_extrahlattr);
|
||||||
width = 0;
|
width = 0;
|
||||||
s = NULL;
|
s = NULL;
|
||||||
switch (round)
|
switch (round)
|
||||||
@@ -698,7 +703,8 @@ pum_redraw(void)
|
|||||||
else
|
else
|
||||||
pum_screen_puts_with_attrs(row,
|
pum_screen_puts_with_attrs(row,
|
||||||
col - cells + 1, cells, rt,
|
col - cells + 1, cells, rt,
|
||||||
(int)STRLEN(rt), attrs);
|
(int)STRLEN(rt), attrs,
|
||||||
|
pum_array[idx].pum_extrahlattr);
|
||||||
|
|
||||||
vim_free(rt_start);
|
vim_free(rt_start);
|
||||||
}
|
}
|
||||||
@@ -732,7 +738,8 @@ pum_redraw(void)
|
|||||||
screen_puts_len(st, size, row, col, attr);
|
screen_puts_len(st, size, row, col, attr);
|
||||||
else
|
else
|
||||||
pum_screen_puts_with_attrs(row, col, cells,
|
pum_screen_puts_with_attrs(row, col, cells,
|
||||||
st, size, attrs);
|
st, size, attrs,
|
||||||
|
pum_array[idx].pum_extrahlattr);
|
||||||
|
|
||||||
vim_free(st);
|
vim_free(st);
|
||||||
}
|
}
|
||||||
|
@@ -4466,12 +4466,13 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char_u *pum_text; // main menu text
|
char_u *pum_text; // main menu text
|
||||||
char_u *pum_kind; // extra kind text (may be truncated)
|
char_u *pum_kind; // extra kind text (may be truncated)
|
||||||
char_u *pum_extra; // extra menu text (may be truncated)
|
char_u *pum_extra; // extra menu text (may be truncated)
|
||||||
char_u *pum_info; // extra info
|
char_u *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
|
||||||
} pumitem_T;
|
} pumitem_T;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
20
src/testdir/dumps/Test_pum_highlights_12.dump
Normal file
20
src/testdir/dumps/Test_pum_highlights_12.dump
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|a+0&#ffffff0|w|o|r|d|1> @68
|
||||||
|
|a+0#ff404010#e0e0e08|w|o|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
|
||||||
|
|a+0#0000001#ffd7ff255|w|o|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
|
||||||
|
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|-+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| |3| +0#0000000&@26
|
@@ -1499,4 +1499,33 @@ func Test_pum_highlights_match()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_pum_extrahl()
|
||||||
|
CheckScreendump
|
||||||
|
let lines =<< trim END
|
||||||
|
hi StrikeFake ctermfg=9
|
||||||
|
func CompleteFunc( findstart, base )
|
||||||
|
if a:findstart
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
return {
|
||||||
|
\ 'words': [
|
||||||
|
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'extrahl': 'StrikeFake' },
|
||||||
|
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
|
||||||
|
\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'extrahl': 'StrikeFake' },
|
||||||
|
\]}
|
||||||
|
endfunc
|
||||||
|
set completeopt=menu
|
||||||
|
set completefunc=CompleteFunc
|
||||||
|
END
|
||||||
|
call writefile(lines, 'Xscript', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S Xscript', {})
|
||||||
|
call TermWait(buf)
|
||||||
|
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
|
||||||
|
call TermWait(buf, 50)
|
||||||
|
call VerifyScreenDump(buf, 'Test_pum_highlights_12', {})
|
||||||
|
call term_sendkeys(buf, "\<C-E>\<Esc>u")
|
||||||
|
call TermWait(buf)
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
618,
|
||||||
/**/
|
/**/
|
||||||
617,
|
617,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user