diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/insexpand.c | 36 | ||||
| -rw-r--r-- | src/nvim/popupmenu.c | 3 | ||||
| -rw-r--r-- | src/nvim/popupmenu.h | 1 |
3 files changed, 30 insertions, 10 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index d9cc398e45..dd014879eb 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -172,6 +172,7 @@ struct compl_S { int cp_number; ///< sequence number int cp_score; ///< fuzzy match score int cp_user_hlattr; ///< highlight attribute to combine with + int cp_user_kind_hlattr; ///< highlight attribute for kind }; /// state information used for getting the next set of insert completion @@ -764,7 +765,7 @@ int ins_compl_add_infercase(char *str_arg, int len, bool icase, char *fname, Dir flags |= CP_ICASE; } - int res = ins_compl_add(str, len, fname, NULL, false, NULL, dir, flags, false, -1); + int res = ins_compl_add(str, len, fname, NULL, false, NULL, dir, flags, false, -1, -1); xfree(tofree); return res; } @@ -804,7 +805,7 @@ static inline void free_cptext(char *const *const cptext) /// returned in case of error. 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, - int flags_arg, const bool adup, int user_hlattr) + int flags_arg, const bool adup, int user_hlattr, int user_kind_hlattr) FUNC_ATTR_NONNULL_ARG(1) { compl_T *match; @@ -871,6 +872,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons } match->cp_flags = flags; match->cp_user_hlattr = user_hlattr; + match->cp_user_kind_hlattr = user_kind_hlattr; if (cptext != NULL) { int i; @@ -1004,7 +1006,7 @@ static void ins_compl_add_matches(int num_matches, char **matches, int icase) for (int i = 0; i < num_matches && add_r != FAIL; i++) { if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, CP_FAST | (icase ? CP_ICASE : 0), - false, -1)) == OK) { + false, -1, -1)) == OK) { // If dir was BACKWARD then honor it just once. dir = FORWARD; } @@ -1272,6 +1274,7 @@ static int ins_compl_build_pum(void) 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_user_hlattr = comp->cp_user_hlattr; + compl_match_array[i].pum_user_kind_hlattr = comp->cp_user_kind_hlattr; if (comp->cp_text[CPT_MENU] != NULL) { compl_match_array[i++].pum_extra = comp->cp_text[CPT_MENU]; } else { @@ -2539,6 +2542,14 @@ theend: } } +static inline int get_user_highlight_attr(const char *hlname) +{ + if (hlname != NULL && *hlname != NUL) { + return syn_name2attr(hlname); + } + return -1; +} + /// Add a match to the list of matches from Vimscript object /// /// @param[in] tv Object to get matches from. @@ -2557,7 +2568,9 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) int flags = fast ? CP_FAST : 0; char *(cptext[CPT_COUNT]); char *user_hlname = NULL; + char *user_kind_hlname = NULL; int user_hlattr = -1; + int user_kind_hlattr = -1; typval_T user_data; user_data.v_type = VAR_UNKNOWN; @@ -2567,10 +2580,13 @@ 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_KIND] = tv_dict_get_string(tv->vval.v_dict, "kind", true); cptext[CPT_INFO] = tv_dict_get_string(tv->vval.v_dict, "info", true); + user_hlname = tv_dict_get_string(tv->vval.v_dict, "hl_group", false); - if (user_hlname != NULL && *user_hlname != NUL) { - user_hlattr = syn_name2attr(user_hlname); - } + user_hlattr = get_user_highlight_attr(user_hlname); + + user_kind_hlname = tv_dict_get_string(tv->vval.v_dict, "kind_hlgroup", false); + user_kind_hlattr = get_user_highlight_attr(user_kind_hlname); + tv_dict_get_tv(tv->vval.v_dict, "user_data", &user_data); if (tv_dict_get_number(tv->vval.v_dict, "icase")) { @@ -2592,7 +2608,7 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast) return FAIL; } int status = ins_compl_add((char *)word, -1, NULL, cptext, true, - &user_data, dir, flags, dup, user_hlattr); + &user_data, dir, flags, dup, user_hlattr, user_kind_hlattr); if (status != OK) { tv_clear(&user_data); } @@ -2685,7 +2701,7 @@ static void set_completion(colnr_T startcol, list_T *list) flags |= CP_ICASE; } if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, - flags | CP_FAST, false, -1) != OK) { + flags | CP_FAST, false, -1, -1) != OK) { return; } @@ -3430,7 +3446,7 @@ static void get_next_bufname_token(void) char *tail = path_tail(b->b_sfname); if (strncmp(tail, compl_orig_text, strlen(compl_orig_text)) == 0) { ins_compl_add(tail, (int)strlen(tail), NULL, NULL, false, NULL, 0, - p_ic ? CP_ICASE : 0, false, -1); + p_ic ? CP_ICASE : 0, false, -1, -1); } } } @@ -4468,7 +4484,7 @@ static int ins_compl_start(void) flags |= CP_ICASE; } if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, - flags, false, -1) != OK) { + flags, false, -1, -1) != OK) { XFREE_CLEAR(compl_pattern); compl_patternlen = 0; XFREE_CLEAR(compl_orig_text); diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index a259fbf09b..f836a1bf17 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -634,6 +634,9 @@ void pum_redraw(void) if (pum_array[idx].pum_user_hlattr > 0) { attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr); } + if (round == 1 && pum_array[idx].pum_user_kind_hlattr > 0) { + attr = hl_combine_attr(attr, pum_array[idx].pum_user_kind_hlattr); + } int width = 0; char *s = NULL; diff --git a/src/nvim/popupmenu.h b/src/nvim/popupmenu.h index 817e0ba0b1..f7eb0240ae 100644 --- a/src/nvim/popupmenu.h +++ b/src/nvim/popupmenu.h @@ -17,6 +17,7 @@ typedef struct { int pum_score; ///< fuzzy match score int pum_idx; ///< index of item before sorting by score int pum_user_hlattr; ///< highlight attribute to combine with + int pum_user_kind_hlattr; ///< highlight attribute for kind } pumitem_T; EXTERN ScreenGrid pum_grid INIT( = SCREEN_GRID_INIT); |
