]> granicus.if.org Git - vim/commitdiff
patch 8.2.4608: getcompletion() does not work when 'wildoptions' has "fuzzy" v8.2.4608
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 22 Mar 2022 16:06:31 +0000 (16:06 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 22 Mar 2022 16:06:31 +0000 (16:06 +0000)
Problem:    getcompletion() does not work properly when 'wildoptions
            contains "fuzzy".
Solution:   Do not use addstar(). (Yegappan Lakshmanan, closes #9992,
            closes #9986)

runtime/doc/builtin.txt
src/cmdexpand.c
src/testdir/test_cmdline.vim
src/version.c

index 062ccc345d681cfd1a1a960e35722e7dc5a7cc38..602d9098e6511d7b7161e77bd01a2c14e26ba634 100644 (file)
@@ -3273,6 +3273,10 @@ getcompletion({pat}, {type} [, {filtered}])              *getcompletion()*
                is applied to filter the results.  Otherwise all the matches
                are returned. The 'wildignorecase' option always applies.
 
+               If the 'wildoptions' option contains 'fuzzy', then fuzzy
+               matching is used to get the completion matches. Otherwise
+               regular expression matching is used.
+
                If {type} is "cmdline", then the |cmdline-completion| result is
                returned.  For example, to complete the possible values after
                a ":call" command: >
index 5ba6b084d30872e94ec659af168bd3d1ea96b5e1..defc282dbb15a44045826413df49bdc31a557db8 100644 (file)
@@ -3707,7 +3707,12 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
 # endif
     }
 
-    pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
+    if (cmdline_fuzzy_completion_supported(&xpc))
+       // when fuzzy matching, don't modify the search string
+       pat = vim_strsave(xpc.xp_pattern);
+    else
+       pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
+
     if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
     {
        int     i;
index dc781f8e10cbda0dad87c36884d2285e2d07b296..299210b8783b8dbd8e100fb5ba5214ea0c4a778f 100644 (file)
@@ -552,6 +552,22 @@ func Test_getcompletion()
   call assert_fails('call getcompletion("abc", [])', 'E475:')
 endfunc
 
+" Test for getcompletion() with "fuzzy" in 'wildoptions'
+func Test_getcompletion_wildoptions()
+  let save_wildoptions = &wildoptions
+  set wildoptions&
+  let l = getcompletion('space', 'option')
+  call assert_equal([], l)
+  let l = getcompletion('ier', 'command')
+  call assert_equal([], l)
+  set wildoptions=fuzzy
+  let l = getcompletion('space', 'option')
+  call assert_true(index(l, 'backspace') >= 0)
+  let l = getcompletion('ier', 'command')
+  call assert_true(index(l, 'compiler') >= 0)
+  let &wildoptions = save_wildoptions
+endfunc
+
 func Test_complete_autoload_error()
   let save_rtp = &rtp
   let lines =<< trim END
index 2c2ac28bf3408ea8193f5d90ce5dc46d057fdda8..2180ebf264c919b9d37201f9b44a696b66be263c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4608,
 /**/
     4607,
 /**/