Skip to content

feat: extract word from completion item for auto-insert preview #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

jdrouhard
Copy link
Contributor

Use a modified version of nvim-cmp's word extraction algorithm from expanded snippets for use in auto-insert preview textEdits.

For example, if a snippet expansion results in something like:

my_neat_function(int arg1, double arg2)

Then the floating window will show the above for that completion, but when selecting it, the buffer will only insert my_neat_function. This allows using the snippet completion item without actually accepting it by just selecting it in the preview window and then continuing to type.

So one could type "my_n", Ctrl-N/Tab (or whatever your keymap is) to select my_neat_function, and then just continue with typing the ( and args manually. Of course, accepting the completion will still work as expected by expanding the snippet.

jdrouhard and others added 2 commits November 17, 2024 09:25
Use a modified version of nvim-cmp's word extraction algorithm from
expanded snippets for use in auto-insert preview textEdits.

For example, if a snippet expansion results in something like:

```
my_neat_function(int arg1, double arg2)
```

Then the floating window will show the above for that completion, but
when selecting it, the buffer will only insert `my_neat_function`. This
allows using the snippet completion item without actually _accepting_ it
by just selecting it in the preview window and then continuing to type.

So one could type "my_n", Ctrl-N/Tab (or whatever your keymap is) to
select `my_neat_function`, and then just continue with typing the ( and
args manually. Of course, accepting the completion will still work as
expected by expanding the snippet.
@Saghen Saghen merged commit 285f6f4 into Saghen:main Nov 20, 2024
@Saghen
Copy link
Owner

Saghen commented Nov 20, 2024

Works great, thanks!

@jdrouhard jdrouhard deleted the auto-insert-preview-word branch November 20, 2024 21:04
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.

2 participants