diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-02-10 16:19:32 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-02-10 16:19:32 +0100 |
commit | 9b56a57cdae31f7a2c85d440392bf63d3253a158 (patch) | |
tree | c398e599f330084126ba3b9cdc3ef0e86ab8be1c /src | |
parent | b301f6b950975b9d7ae87a4f551b32bba63ccdcf (diff) | |
download | vim-git-9b56a57cdae31f7a2c85d440392bf63d3253a158.tar.gz |
patch 8.0.1493: completion items cannot be annotatedv8.0.1493
Problem: Completion items cannot be annotated.
Solution: Add a "user_data" entry to the completion item. (Ben Jackson,
coses #2608, closes #2508)
Diffstat (limited to 'src')
-rw-r--r-- | src/edit.c | 4 | ||||
-rw-r--r-- | src/structs.h | 11 | ||||
-rw-r--r-- | src/testdir/test_ins_complete.vim | 120 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 132 insertions, 5 deletions
diff --git a/src/edit.c b/src/edit.c index fa1d84bbc..a9e6343a8 100644 --- a/src/edit.c +++ b/src/edit.c @@ -4236,6 +4236,8 @@ ins_compl_add_tv(typval_T *tv, int dir) (char_u *)"kind", FALSE); cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict, (char_u *)"info", FALSE); + cptext[CPT_USER_DATA] = get_dict_string(tv->vval.v_dict, + (char_u *)"user_data", FALSE); if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL) icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase"); if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL) @@ -4758,6 +4760,8 @@ ins_compl_insert(int in_compl_func) EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_KIND])); dict_add_nr_str(dict, "info", 0L, EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_INFO])); + dict_add_nr_str(dict, "user_data", 0L, + EMPTY_IF_NULL(compl_shown_match->cp_text[CPT_USER_DATA])); } set_vim_var_dict(VV_COMPLETED_ITEM, dict); if (!in_compl_func) diff --git a/src/structs.h b/src/structs.h index 6aaccc511..abfb73176 100644 --- a/src/structs.h +++ b/src/structs.h @@ -3240,11 +3240,12 @@ typedef struct /* * Array indexes used for cptext argument of ins_compl_add(). */ -#define CPT_ABBR 0 /* "abbr" */ -#define CPT_MENU 1 /* "menu" */ -#define CPT_KIND 2 /* "kind" */ -#define CPT_INFO 3 /* "info" */ -#define CPT_COUNT 4 /* Number of entries */ +#define CPT_ABBR 0 /* "abbr" */ +#define CPT_MENU 1 /* "menu" */ +#define CPT_KIND 2 /* "kind" */ +#define CPT_INFO 3 /* "info" */ +#define CPT_USER_DATA 4 /* "user data" */ +#define CPT_COUNT 5 /* Number of entries */ typedef struct { UINT32_T total[2]; diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim index 652b1d9e4..020e22882 100644 --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -117,6 +117,126 @@ func Test_omni_dash() set omnifunc= endfunc +function! s:CompleteDone_CompleteFuncDict( findstart, base ) + if a:findstart + return 0 + endif + + return { + \ 'words': [ + \ { + \ 'word': 'aword', + \ 'abbr': 'wrd', + \ 'menu': 'extra text', + \ 'info': 'words are cool', + \ 'kind': 'W', + \ 'user_data': 'test' + \ } + \ ] + \ } +endfunction + +function! s:CompleteDone_CheckCompletedItemDict() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) + call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) + call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) + call assert_equal( 'W', v:completed_item[ 'kind' ] ) + call assert_equal( 'test', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunction + +function Test_CompleteDoneDict() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict() + + set completefunc=<SID>CompleteDone_CompleteFuncDict + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal( 'test', v:completed_item[ 'user_data' ] ) + call assert_true( s:called_completedone ) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +function! s:CompleteDone_CompleteFuncDictNoUserData( findstart, base ) + if a:findstart + return 0 + endif + + return { + \ 'words': [ + \ { + \ 'word': 'aword', + \ 'abbr': 'wrd', + \ 'menu': 'extra text', + \ 'info': 'words are cool', + \ 'kind': 'W' + \ } + \ ] + \ } +endfunction + +function! s:CompleteDone_CheckCompletedItemDictNoUserData() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) + call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) + call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) + call assert_equal( 'W', v:completed_item[ 'kind' ] ) + call assert_equal( '', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunction + +function Test_CompleteDoneDictNoUserData() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() + + set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal( '', v:completed_item[ 'user_data' ] ) + call assert_true( s:called_completedone ) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +function! s:CompleteDone_CompleteFuncList( findstart, base ) + if a:findstart + return 0 + endif + + return [ 'aword' ] +endfunction + +function! s:CompleteDone_CheckCompletedItemList() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( '', v:completed_item[ 'abbr' ] ) + call assert_equal( '', v:completed_item[ 'menu' ] ) + call assert_equal( '', v:completed_item[ 'info' ] ) + call assert_equal( '', v:completed_item[ 'kind' ] ) + call assert_equal( '', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunction + +function Test_CompleteDoneList() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() + + set completefunc=<SID>CompleteDone_CompleteFuncList + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal( '', v:completed_item[ 'user_data' ] ) + call assert_true( s:called_completedone ) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + " Check that when using feedkeys() typeahead does not interrupt searching for " completions. func Test_compl_feedkeys() diff --git a/src/version.c b/src/version.c index be5f864ec..261e3d7c6 100644 --- a/src/version.c +++ b/src/version.c @@ -772,6 +772,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1493, +/**/ 1492, /**/ 1491, |