Skip to content

Conversation

@girishji
Copy link
Contributor

@girishji girishji commented Jul 3, 2025

Allow functions in 'complete' to complete from non-keyword

Previously, functions specified in the 'complete' option were restricted to starting completion only from keyword characters during <C-N> / <C-P> completion (as introduced in PR #17065). This PR lifts 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.

The existing behavior — where <C-N> shows a menu of all words of at least 2 characters when triggered from a non-keyword — remains unchanged.

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.

@habamax
Copy link
Contributor

habamax commented Jul 3, 2025

As a side note, can we have an API (a function?) that can trigger completion instead of relying on feedkeys("\<C-n>", "n")? There is complete() but it sets the matches for insert mode completion, not reusing the sources defined in 'complete'...

@girishji
Copy link
Contributor Author

girishji commented Jul 3, 2025

As a side note, can we have an API (a function?) that can trigger completion instead of relying on feedkeys("\<C-n>", "n")? There is complete() but it sets the matches for insert mode completion, not reusing the sources defined in 'complete'...

It's possible. I'll think about it a bit. It has to be a separate PR though.

…cters

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().
@chrisbra
Copy link
Member

chrisbra commented Jul 3, 2025

So if I understand this correctly, i_CTRL-N/i_CTRL-P still only completes keywords (when not using functions as completion source), right? I think then this enhancement is fine. I was just worried this would introduce some backwards incompatibility. I think the help page does exactly this, but I figured I ask for confirmation anyhow ;)

@girishji
Copy link
Contributor Author

girishji commented Jul 3, 2025

So if I understand this correctly, i_CTRL-N/i_CTRL-P still only completes keywords (when not using functions as completion source), right? I think then this enhancement is fine. I was just worried this would introduce some backwards incompatibility. I think the help page does exactly this, but I figured I ask for confirmation anyhow ;)

Yes, you're absolutely right — i_CTRL-N/i_CTRL-P still complete only keywords when functions are not used as a completion source. So there's no backwards incompatibility here.

@chrisbra
Copy link
Member

chrisbra commented Jul 5, 2025

thanks

@chrisbra chrisbra closed this in ba11e78 Jul 5, 2025
@girishji
Copy link
Contributor Author

girishji commented Jul 5, 2025

Thanks.

@girishji girishji deleted the nonkeyword branch July 5, 2025 14:14
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Jul 5, 2025
…ters

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

vim/vim@ba11e78

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Jul 5, 2025
…ters

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

vim/vim@ba11e78

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Jul 5, 2025
…ters (#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

vim/vim@ba11e78

Co-authored-by: Girish Palya <girishji@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants