vim-patch:9.1.1512: completion: can only complete from keyword characters (#34798)

Problem:  completion: can only complete from keyword characters
Solution: remove this restriction, allow completion functions when
          called from i_CTRL-N/i_CTRL-P to be triggered from non-keyword
          characters (Girish Palya)

Previously, functions specified in the `'complete'` option were
restricted to starting completion only from keyword characters (as
introduced in PR 17065). This change removes that restriction.

With this change, user-defined functions (e.g., `omnifunc`, `userfunc`)
used in `'complete'` can now initiate completion even when triggered
from non-keyword characters. This makes it easier to reuse existing
functions alongside other sources without having to consider whether the
cursor is on a keyword or non-keyword character, or worry about where
the replacement should begin (i.e., the `findstart=1` return value).

The logic for both the “collection” and “filtering” phases now fully
respects each source’s specified start column. This also extends to
fuzzy matching, making completions more predictable.

Internally, this builds on previously merged infrastructure that tracks
per-source metadata. This PR focuses on applying that metadata to
compute the leader string and insertion text appropriately for each
match.

Also, a memory corruption has been fixed in prepare_cpt_compl_funcs().

closes: vim/vim#17651

ba11e78f1d

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-07-06 06:09:28 +08:00
committed by GitHub
parent 887255362f
commit 85e6feedb0
6 changed files with 274 additions and 69 deletions

View File

@ -1033,15 +1033,12 @@ vim.bo.cms = vim.bo.commentstring
--- name of a function or a `Funcref`. For `Funcref` values,
--- spaces must be escaped with a backslash ('\'), and commas with
--- double backslashes ('\\') (see `option-backslash`).
--- Unlike other sources, functions can provide completions starting
--- from a non-keyword character before the cursor, and their
--- start position for replacing text may differ from other sources.
--- If the Dict returned by the {func} includes {"refresh": "always"},
--- the function will be invoked again whenever the leading text
--- changes.
--- Completion matches are always inserted at the keyword
--- boundary, regardless of the column returned by {func} when
--- a:findstart is 1. This ensures compatibility with other
--- completion sources.
--- To make further modifications to the inserted text, {func}
--- can make use of `CompleteDonePre`.
--- If generating matches is potentially slow, `complete_check()`
--- should be used to avoid blocking and preserve editor
--- responsiveness.