Repository: neovim
Issue: completion: better support for autocompletion (improve completion "primitives")
Labels: enhancement,plugin,completion

# Problem:

1. Nvim core could be improved to make it easier for plugins to implement reliable autocompletion.
    - _via @echasnovski in https://github.com/neovim/neovim/issues/24661#issuecomment-1764712654_ :
      > When it comes to auto-completion, my main struggles implementing 'mini.completion' (as far as I remember) were at least these ones:
      > - Finding a good way to automatically start timer to later trigger showing completion. The best approach was to use `InsertCharPre` event, but I vaguely remember it having annoying downsides. For example, the text is not up to date as it is *before* inserting character, not after. There are also some notes in code about it being not enough to track any manual text change (it is not triggered after `<CR>`). So `InsertCharPost` might be helpful here.
      > - Creating a custom completion dialog with `vim.fn.complete()` was problematic because it disappears after `<BS>`. So I had to resort to using more native `omnifunc`/`completefunc` and emulate them with `vim.api.nvim_feedkeys()`.
    - How can something like LSP provide "trigger chars" on-demand to the completion function?
    - LSP specifies a "re-trigger" mechanism. The server can indicate that the completion result set is incomplete. In that case the client should trigger again after the user entered more characters. [ref](https://github.com/neovim/neovim/pull/24661#pullrequestreview-1680339857)
    - Do we need a new option like 'completetriggers' which is a function that "resolves" the trigger chars on-demand?
        - Note: LSP has "context" fields which let the server distinguish between a auto-retrigger and a manual invocation from the user. This implies that a 'completetriggers' option is too simplistic.
    - debounce to avoid server overload. [ref](https://github.com/neovim/neovim/pull/24661#pullrequestreview-1680339857)
    - [more...](https://github.com/neovim/neovim/pull/20671#issuecomment-1288080374)
2. Nvim doesn't have autocompletion out of the box (user must explicitly invoke `ctrl-x ctrl-o` instead of just typing "trigger characters" such as `.`, `->`, …).
3. No standard interface for (passively) defining a "completion source". https://github.com/neovim/neovim/issues/32123

# Solution:

1. Provide primitives to fix (1).
2. Introduce primitive for defining a "completion source". https://github.com/neovim/neovim/issues/32123
3. After fixing (1), include a very minimal autocompletion plugin.    - [mini.completion](https://github.com/echasnovski/mini.completion) has been working well in my personal testing, so far.

From https://github.com/neovim/neovim/pull/24661#issuecomment-1764776159 : 

> Broadly speaking, for a working decently generalizable and user-friendly auto-completion functionality in core, there should be:
> 
> * Generalizable and user-friendly way to automatically start the completion. This can be as straightforward as a callback that is called on every user input. Inside it should take care of deciding whether to start completion (now or later) and actually starting it.
> * Generalizable and user-friendly way to display completion items. There is a `complete()`, but it has downsides described earlier. So a built-in 'completefunc' approach is the only option right with the balance of being usable without too much complications. Also, custom matching would be a welcome addition. I vaguely remember some work in vim/vim for this, but not sure the status of it.