To: vim_dev@googlegroups.com Subject: Patch 8.0.1493 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1493 Problem: Completion items cannot be annotated. Solution: Add a "user_data" entry to the completion item. (Ben Jackson, coses #2608, closes #2508) Files: runtime/doc/insert.txt, src/edit.c, src/structs.h, src/testdir/test_ins_complete.vim *** ../vim-8.0.1492/runtime/doc/insert.txt 2016-09-12 12:45:26.000000000 +0200 --- runtime/doc/insert.txt 2018-02-10 16:08:08.282077462 +0100 *************** *** 1102,1109 **** item with the same word is already present. empty when non-zero this match will be added even when it is an empty string ! All of these except 'icase', 'dup' and 'empty' must be a string. If an item does not meet these requirements then an error message is given and further items in the list are not used. You can mix string and Dictionary items in the returned list. --- 1103,1112 ---- item with the same word is already present. empty when non-zero this match will be added even when it is an empty string + user_data custom data which is associated with the item and + available in |v:completed_item| ! All of these except "icase", "dup" and "empty" must be a string. If an item does not meet these requirements then an error message is given and further items in the list are not used. You can mix string and Dictionary items in the returned list. *************** *** 1195,1200 **** --- 1198,1205 ---- The 'pumheight' option can be used to set a maximum height. The default is to use all space available. + The 'pumwidth' option can be used to set a minimum width. The default is 15 + characters. There are three states: 1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P. *** ../vim-8.0.1492/src/edit.c 2018-02-09 15:05:58.678406526 +0100 --- src/edit.c 2018-02-10 16:10:06.401264278 +0100 *************** *** 4236,4241 **** --- 4236,4243 ---- (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,4763 **** --- 4760,4767 ---- 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) *** ../vim-8.0.1492/src/structs.h 2017-11-25 15:19:45.097464854 +0100 --- src/structs.h 2018-02-10 16:10:24.757137849 +0100 *************** *** 3240,3250 **** /* * 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 */ typedef struct { UINT32_T total[2]; --- 3240,3251 ---- /* * 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_USER_DATA 4 /* "user data" */ ! #define CPT_COUNT 5 /* Number of entries */ typedef struct { UINT32_T total[2]; *** ../vim-8.0.1492/src/testdir/test_ins_complete.vim 2018-02-09 15:05:58.682406498 +0100 --- src/testdir/test_ins_complete.vim 2018-02-10 16:12:08.084425905 +0100 *************** *** 117,122 **** --- 117,242 ---- 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 CompleteDone_CheckCompletedItemDict() + + set completefunc=CompleteDone_CompleteFuncDict + execute "normal a\\\" + 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 CompleteDone_CheckCompletedItemDictNoUserData() + + set completefunc=CompleteDone_CompleteFuncDictNoUserData + execute "normal a\\\" + 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 CompleteDone_CheckCompletedItemList() + + set completefunc=CompleteDone_CompleteFuncList + execute "normal a\\\" + 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() *** ../vim-8.0.1492/src/version.c 2018-02-10 15:38:31.026211917 +0100 --- src/version.c 2018-02-10 16:06:47.182635341 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1493, /**/ -- CUSTOMER: You're not fooling anyone y'know. Look, isn't there something you can do? DEAD PERSON: I feel happy... I feel happy. [whop] CUSTOMER: Ah, thanks very much. MORTICIAN: Not at all. See you on Thursday. CUSTOMER: Right. The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///