Skip to content
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

Completions prefetching #706

Open
1 of 7 tasks
Saghen opened this issue Dec 21, 2024 · 3 comments
Open
1 of 7 tasks

Completions prefetching #706

Saghen opened this issue Dec 21, 2024 · 3 comments
Labels
feature New feature or request sources Specific source provider or the system as a whole

Comments

@Saghen
Copy link
Owner

Saghen commented Dec 21, 2024

Feature Description

Prefetching can reduce latency to 0ms, removing the final bottleneck for blink.cmp's latency, the LSP itself!

With #697 merged, we now have a reliable way to pass the source of a completion request upstream, meaning completion.trigger.prefetch_on_insert = true seems to work reliably. Some ideas of when to prefetch:

  • InsertEnter
  • CursorHold? Only in insert mode?
  • After pressing c in normal mode?
  • After deleting characters onto a trigger character (a.b| -> a.|)
  • After typing , (for function arguments)
  • After pressing some trigger characters ((, [, etc) regardless of source's trigger characters, by language
  • Other ideas?

CC @stefanboca

@Saghen Saghen added feature New feature or request sources Specific source provider or the system as a whole labels Dec 21, 2024
@stefanboca
Copy link
Collaborator

stefanboca commented Dec 23, 2024

Possibly on CmdlineEnter or CmdwinEnter for cmdline prefetching? #305 and #665 should also probably allow prefetching somehow, although I'm not sure if that's already handled by InsertEnter.

@milanglacier
Copy link
Contributor

milanglacier commented Jan 25, 2025

After pressing c in normal mode?

This may not be a good idea. Pressing c following a huge text object or motion may change the whole buffer content a lot, making the prefetched completion items unusable.

After deleting characters onto a trigger character (a.b| -> a.|)

This makes sense and it seems that this is the default behavior of nvim-cmp

CursorHold

Is cursorhold autocmd repeatedly triggered? Some AI related sources are expensive and may not want to be silently triggered at background.

@Saghen
Copy link
Owner Author

Saghen commented Feb 1, 2025

Just added the idea of prefetching after , since that's the typical case for typing functions. Also after some characters like ( and [, which aren't ideal for showing the menu, but are for prefetching. In general, since prefetching doesn't show the menu, we can be much more liberal with when we trigger it

Pressing c following a huge text object or motion may change the whole buffer content a lot, making the prefetched completion items unusable

It may but in this case the completions will be thrown away so this should be harmless. I believe on average the prefetched completions would be useful, but we'd need to test this

Is cursorhold autocmd repeatedly triggered? Some AI related sources are expensive and may not want to be silently triggered at background.

Good point, we should make prefetching opt-in for the sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request sources Specific source provider or the system as a whole
Projects
None yet
Development

No branches or pull requests

3 participants