changeset 35796:a35a8ae0b315 v9.1.0618

patch 9.1.0618: cannot mark deprecated attributes in completion menu Commit: https://github.com/vim/vim/commit/508e7856ec4afc9d6038b14bb6893668268dccab Author: glepnir <glephunter@gmail.com> Date: Thu Jul 25 21:39:08 2024 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Thu, 25 Jul 2024 21:45:03 +0200
parents 1993d62ce019
children 9e1bbcb9481c
files runtime/doc/insert.txt runtime/doc/version9.txt src/cmdexpand.c src/insexpand.c src/popupmenu.c src/structs.h src/testdir/dumps/Test_pum_highlights_12.dump src/testdir/test_popup.vim src/version.c
diffstat 9 files changed, 97 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -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
@@ -1183,6 +1183,12 @@ items:
 	user_data	custom data which is associated with the item and
 			available in |v:completed_item|; it can be any type;
 			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
 an item does not meet these requirements then an error message is given and
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -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
@@ -41588,6 +41588,8 @@ Changed~
   |getcompletion()|
 - add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
   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 ~
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -359,6 +359,7 @@ cmdline_pum_create(
 	compl_match_array[i].pum_info = NULL;
 	compl_match_array[i].pum_extra = NULL;
 	compl_match_array[i].pum_kind = NULL;
+	compl_match_array[i].pum_extrahlattr = -1;
     }
 
     // Compute the popup menu starting column
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -114,6 +114,7 @@ struct compl_S
     int		cp_flags;	// CP_ values
     int		cp_number;	// sequence number
     int		cp_score;	// fuzzy match score
+    int		cp_extrahlattr;	// extra highlight group attr
 };
 
 // values for cp_flags
@@ -205,7 +206,7 @@ static int	  compl_selected_item = -1;
 
 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_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);
@@ -745,7 +746,7 @@ ins_compl_add_infercase(
     if (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);
     return res;
 }
@@ -778,7 +779,8 @@ ins_compl_add(
     typval_T	*user_data UNUSED,  // "user_data" entry or NULL
     int		cdir,
     int		flags_arg,
-    int		adup)		// accept duplicate match
+    int		adup,		    // accept duplicate match
+    int		extra_hlattr)
 {
     compl_T	*match;
     int		dir = (cdir == 0 ? compl_direction : cdir);
@@ -842,6 +844,7 @@ ins_compl_add(
     else
 	match->cp_fname = NULL;
     match->cp_flags = flags;
+    match->cp_extrahlattr = extra_hlattr;
 
     if (cptext != NULL)
     {
@@ -994,7 +997,7 @@ ins_compl_add_matches(
 
     for (i = 0; i < num_matches && add_r != FAIL; i++)
 	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
 	    dir = FORWARD;
     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_info = compl->cp_text[CPT_INFO];
 	    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)
 		compl_match_array[i++].pum_extra =
 		    compl->cp_text[CPT_MENU];
@@ -2856,6 +2860,8 @@ ins_compl_add_tv(typval_T *tv, int dir, 
     char_u	*(cptext[CPT_COUNT]);
     typval_T	user_data;
     int		status;
+    char_u	*extra_hlname;
+    int		extra_hlattr = -1;
 
     user_data.v_type = VAR_UNKNOWN;
     if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
@@ -2865,6 +2871,10 @@ ins_compl_add_tv(typval_T *tv, int dir, 
 	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_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);
 	if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL
 				  && dict_get_number(tv->vval.v_dict, "icase"))
@@ -2887,7 +2897,8 @@ ins_compl_add_tv(typval_T *tv, int dir, 
 	clear_tv(&user_data);
 	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)
 	clear_tv(&user_data);
     return status;
@@ -2974,7 +2985,7 @@ set_completion(colnr_T startcol, list_T 
 	flags |= CP_ICASE;
     if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
 					      -1, NULL, NULL, NULL, 0,
-					      flags | CP_FAST, FALSE) != OK)
+					      flags | CP_FAST, FALSE, -1) != OK)
 	return;
 
     ctrl_x_mode = CTRL_X_EVAL;
@@ -5177,7 +5188,7 @@ ins_compl_start(void)
     if (p_ic)
 	flags |= CP_ICASE;
     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);
 	compl_patternlen = 0;
--- a/src/popupmenu.c
+++ b/src/popupmenu.c
@@ -510,7 +510,8 @@ pum_screen_puts_with_attrs(
     int		cells UNUSED,
     char_u	*text,
     int		textlen,
-    int		*attrs)
+    int		*attrs,
+    int		extra_attr)
 {
     int		col_start = col;
     char_u	*ptr = text;
@@ -527,6 +528,8 @@ pum_screen_puts_with_attrs(
 	else
 #endif
 	    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);
 	col += mb_ptr2cells(ptr);
 	ptr += char_len;
@@ -628,6 +631,8 @@ pum_redraw(void)
 	{
 	    hlf = hlfs[round];
 	    attr = highlight_attr[hlf];
+	    if (pum_array[idx].pum_extrahlattr > 0)
+		attr = hl_combine_attr(attr, pum_array[idx].pum_extrahlattr);
 	    width = 0;
 	    s = NULL;
 	    switch (round)
@@ -698,7 +703,8 @@ pum_redraw(void)
 				    else
 					pum_screen_puts_with_attrs(row,
 						    col - cells + 1, cells, rt,
-						       (int)STRLEN(rt), attrs);
+						       (int)STRLEN(rt), attrs,
+						       pum_array[idx].pum_extrahlattr);
 
 				    vim_free(rt_start);
 				}
@@ -732,7 +738,8 @@ pum_redraw(void)
 				    screen_puts_len(st, size, row, col, attr);
 				else
 				    pum_screen_puts_with_attrs(row, col, cells,
-							      st, size, attrs);
+							      st, size, attrs,
+							      pum_array[idx].pum_extrahlattr);
 
 				vim_free(st);
 			    }
--- a/src/structs.h
+++ b/src/structs.h
@@ -4466,12 +4466,13 @@ typedef struct
  */
 typedef struct
 {
-    char_u	*pum_text;	// main menu text
-    char_u	*pum_kind;	// extra kind text (may be truncated)
-    char_u	*pum_extra;	// extra menu text (may be truncated)
-    char_u	*pum_info;	// extra info
-    int		pum_score;	// fuzzy match score
-    int		pum_idx;	// index of item before sorting by score
+    char_u	*pum_text;	  // main menu text
+    char_u	*pum_kind;	  // extra kind text (may be truncated)
+    char_u	*pum_extra;	  // extra menu text (may be truncated)
+    char_u	*pum_info;	  // extra info
+    int		pum_score;	  // fuzzy match score
+    int		pum_idx;	  // index of item before sorting by score
+    int		pum_extrahlattr;  // extra highlight group attr for combine
 } pumitem_T;
 
 /*
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_highlights_12.dump
@@ -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
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -1499,4 +1499,33 @@ func Test_pum_highlights_match()
   call StopVimInTerminal(buf)
 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
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    618,
+/**/
     617,
 /**/
     616,