neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 15e42dd4498829e5315b9b0da7384bedf466d707
parent 5ce6685119419c08475a65b6e48b4487be5c6036
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Tue, 17 Jan 2023 12:38:16 +0800

vim-patch:8.2.4608: getcompletion() does not work when 'wildoptions' has "fuzzy"

Problem:    getcompletion() does not work properly when 'wildoptions
            contains "fuzzy".
Solution:   Do not use addstar(). (Yegappan Lakshmanan, closes vim/vim#9992,
            closes vim/vim#9986)

https://github.com/vim/vim/commit/e7dd0fa2c61fe71f12c72b0dcb7bb6415eb048fb

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>

Diffstat:
Mruntime/doc/builtin.txt | 4++++
Msrc/nvim/cmdexpand.c | 8+++++++-
Msrc/nvim/testdir/test_cmdline.vim | 16++++++++++++++++
3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt @@ -3000,6 +3000,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: > diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c @@ -3472,7 +3472,13 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } theend: - 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 = xstrdup(xpc.xp_pattern); + } else { + pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); + } + ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP); tv_list_alloc_ret(rettv, xpc.xp_numfiles); diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim @@ -650,6 +650,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_fullcommand() let tests = { \ '': '',