diff options
author | Blaž Hrastnik <blaz@mxxn.io> | 2020-04-29 00:27:14 +0900 |
---|---|---|
committer | Blaž Hrastnik <blaz@mxxn.io> | 2020-04-29 11:15:49 +0900 |
commit | c477b19bdca0cc57e08f5fb93f647767ea84dd3e (patch) | |
tree | 8a931968ac4d76fd8684e829a9030303f0fb3a36 /src/nvim/edit.c | |
parent | c7d3630e214012667e855c30cde2808a5fe59650 (diff) | |
download | rneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.tar.gz rneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.tar.bz2 rneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.zip |
vim-patch:8.2.0084: complete item "user_data" can only be a string
Problem: Complete item "user_data" can only be a string.
Solution: Accept any type of variable. (closes vim/vim#5412)
https://github.com/vim/vim/commit/0892832bb6c7e322fcae8560eaad5a8140ee4a06
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a291ed0401..a4c4bf4ce8 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -143,6 +143,7 @@ struct compl_S { compl_T *cp_prev; char_u *cp_str; // matched text char_u *(cp_text[CPT_COUNT]); // text for the menu + typval_T cp_user_data; char_u *cp_fname; // file containing the match, allocated when // cp_flags has CP_FREE_FNAME int cp_flags; // CP_ values @@ -2291,7 +2292,7 @@ int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, flags |= CP_ICASE; } - return ins_compl_add(str, len, fname, NULL, false, dir, flags, false); + return ins_compl_add(str, len, fname, NULL, false, NULL, dir, flags, false); } /// Add a match to the list of matches @@ -2315,6 +2316,7 @@ static int ins_compl_add(char_u *const str, int len, char_u *const fname, char_u *const *const cptext, const bool cptext_allocated, + typval_T *user_data, const Direction cdir, int flags_arg, const bool adup) FUNC_ATTR_NONNULL_ARG(1) { @@ -2403,6 +2405,10 @@ static int ins_compl_add(char_u *const str, int len, } } + if (user_data != NULL) { + match->cp_user_data = *user_data; + } + /* * Link the new match structure in the list of matches. */ @@ -2521,7 +2527,7 @@ static void ins_compl_add_matches(int num_matches, char_u **matches, int icase) int dir = compl_direction; for (int i = 0; i < num_matches && add_r != FAIL; i++) { - if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, dir, + if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, icase ? CP_ICASE : 0, false)) == OK) { // If dir was BACKWARD then honor it just once. dir = FORWARD; @@ -2596,7 +2602,7 @@ void set_completion(colnr_T startcol, list_T *list) if (p_ic) { flags |= CP_ICASE; } - if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, 0, + if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, flags, false) != OK) { return; } @@ -3120,6 +3126,7 @@ static void ins_compl_free(void) for (int i = 0; i < CPT_COUNT; i++) { xfree(match->cp_text[i]); } + tv_clear(&match->cp_user_data); xfree(match); } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); compl_first_match = compl_curr_match = NULL; @@ -3215,8 +3222,11 @@ void get_complete_info(list_T *what_list, dict_T *retdict) (char *)EMPTY_IF_NULL(match->cp_text[CPT_KIND])); tv_dict_add_str(di, S_LEN("info"), (char *)EMPTY_IF_NULL(match->cp_text[CPT_INFO])); - tv_dict_add_str(di, S_LEN("user_data"), - (char *)EMPTY_IF_NULL(match->cp_text[CPT_USER_DATA])); + if (match->cp_user_data.v_type == VAR_UNKNOWN) { + tv_dict_add_str(di, S_LEN("user_data"), ""); + } else { + tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data); + } } match = match->cp_next; } while (match != NULL && match != compl_first_match); @@ -3930,15 +3940,16 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir) bool empty = false; int flags = 0; char *(cptext[CPT_COUNT]); + typval_T user_data; + user_data.v_type = VAR_UNKNOWN; if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) { word = tv_dict_get_string(tv->vval.v_dict, "word", false); cptext[CPT_ABBR] = tv_dict_get_string(tv->vval.v_dict, "abbr", 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_INFO] = tv_dict_get_string(tv->vval.v_dict, "info", true); - cptext[CPT_USER_DATA] = tv_dict_get_string(tv->vval.v_dict, - "user_data", true); + tv_dict_get_tv(tv->vval.v_dict, "user_data", &user_data); if (tv_dict_get_number(tv->vval.v_dict, "icase")) { flags |= CP_ICASE; @@ -3960,7 +3971,7 @@ int ins_compl_add_tv(typval_T *const tv, const Direction dir) return FAIL; } return ins_compl_add((char_u *)word, -1, NULL, - (char_u **)cptext, true, dir, flags, dup); + (char_u **)cptext, true, &user_data, dir, flags, dup); } // Get the next expansion(s), using "compl_pattern". @@ -4450,9 +4461,11 @@ static dict_T *ins_compl_dict_alloc(compl_T *match) tv_dict_add_str( dict, S_LEN("info"), (const char *)EMPTY_IF_NULL(match->cp_text[CPT_INFO])); - tv_dict_add_str( - dict, S_LEN("user_data"), - (const char *)EMPTY_IF_NULL(match->cp_text[CPT_USER_DATA])); + if (match->cp_user_data.v_type == VAR_UNKNOWN) { + tv_dict_add_str(dict, S_LEN("user_data"), ""); + } else { + tv_dict_add_tv(dict, S_LEN("user_data"), &match->cp_user_data); + } return dict; } @@ -5155,7 +5168,7 @@ static int ins_complete(int c, bool enable_pum) if (p_ic) { flags |= CP_ICASE; } - if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, 0, + if (ins_compl_add(compl_orig_text, -1, NULL, NULL, false, NULL, 0, flags, false) != OK) { XFREE_CLEAR(compl_pattern); XFREE_CLEAR(compl_orig_text); |