Files
neovim/test
zeertzjq 08b8fe5ab3 vim-patch:9.2.0030: completion: non-prefix matches shown when leader is NULL
Problem:  When 'autocomplete' fires before compl_leader is initialized,
          the prefix filter is bypassed. This allows non-prefix matches
          (e.g. from fuzzy omnifuncs) to be shown in the popup menu and
          incorrectly preinserted.
Solution: In get_leader_for_startcol(), if compl_leader.string is NULL,
          fall back to using compl_orig_text as a filter for matches
	  starting at or after the completion column (Hirohito Higashi).

When 'autocomplete' first fires, compl_leader is NULL because
ins_compl_start() has not set it yet.  This caused the prefix filter in
ins_compl_build_pum(), find_next_completion_match() and
find_common_prefix() to be bypassed, allowing non-prefix fuzzy omnifunc
matches to appear in the PUM and be preinserted.

Extend get_leader_for_startcol() to fall back to compl_orig_text when
compl_leader.string is NULL: if the match's cpt source startcol is less
than compl_col the match includes pre-compl_col text, so return
&compl_leader (NULL string) to signal "pass through"; otherwise return
&compl_orig_text so callers filter by the original text.  The compl_col
<= 0 guard is kept only for the prepend-text path to avoid it
interfering with the NULL-leader fallback when compl_col is zero.

With this change all callers of get_leader_for_startcol() automatically
receive the correct filter string without additional helpers.

Also update Test_autocomplete_trigger Test 9 to reflect the new
behavior: 'faberge' is no longer shown when completing 'foo' because
it does not start with the current prefix.

Add Test_autocomplete_preinsert_null_leader() to verify that only
prefix-matching candidates appear in the PUM and are preinserted.

fixes:  vim/vim#19328
closes: vim/vim#19447

a04ae0210b

Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 08:58:41 +08:00
..