LazyVim.LazyVim/lua/lazyvim/util
Folke Lemaitre fbf881f80b
feat(ai): better completion/suggestions of AI engines (#4752)
## Description

The whole completion / snippets / AI is very tricky:
- multiple snippet engines
- native snippets on > 0.11 set their own keymaps, but not on 0.10
- multiple completion engines, like `nvim-cmp` and `blink.cmp`
- multiple ai completion engines that have a different API
- user's preference of showing ai suggestions as completion or not
- none of the ai completion engines currently set undo points, which is
bad

Solution:
- [x] added `LazyVim.cmp.actions`, where snippet engines and ai engines
can register their action.
- [x] an action returns `true` if it succeeded, or `false|nil` otherwise
- [x] in a completion engine, we then try running multiple actions and
use the fallback if needed
- [x] so `<tab>` runs `{"snippet_forward", "ai_accept", "fallback"}`
- [x] added `vim.g.ai_cmp`. When `true` we try to integrate the AI
source in the completion engine.
- [x] when `false`, `<tab>` should be used to insert the AI suggestion
- [x] when `false`, the completion engine's ghost text is disabled
- [x] luasnip support for blink (only works with blink `main`)
- [x] create undo points when accepting AI suggestions 

## Test Matrix

| completion   | snippets     | ai          | ai_cmp | tested? |
|--------------|--------------|-------------|--------|---------|
| nvim-cmp     | native       | copilot     | true   |       |
| nvim-cmp     | native       | copilot     | false  |       |
| nvim-cmp     | native       | codeium     | true   |       |
| nvim-cmp     | native       | codeium     | false  |       |
| nvim-cmp     | luasnip      | copilot     | true   |       |
| nvim-cmp     | luasnip      | copilot     | false  |       |
| nvim-cmp     | luasnip      | codeium     | true   |       |
| nvim-cmp     | luasnip      | codeium     | false  |       |
| blink.cmp    | native       | copilot     | true   |       |
| blink.cmp    | native       | copilot     | false  |       |
| blink.cmp    | native       | codeium     | true   |       |
| blink.cmp    | native       | codeium     | false  |       |
| blink.cmp    | luasnip      | copilot     | true   |       |
| blink.cmp    | luasnip      | copilot     | false  |       |
| blink.cmp    | luasnip      | codeium     | true   |       |
| blink.cmp    | luasnip      | codeium     | false  |       |


## Related Issue(s)

- [ ] Closes #4702

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

## Checklist

- [ ] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2024-11-11 10:50:57 +01:00
..
cmp.lua feat(ai): better completion/suggestions of AI engines (#4752) 2024-11-11 10:50:57 +01:00
deprecated.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
extras.lua fix(extras): don't load pkgs when parsing specs for LazyExtras 2024-06-29 10:19:01 +02:00
format.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
init.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
inject.lua feat(util): set_upvalue 2024-05-16 21:25:51 +02:00
json.lua feat(ai): move ai related extras from coding to ai (#4751) 2024-11-10 11:27:21 +01:00
lsp.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
lualine.lua feat(ai): better completion/suggestions of AI engines (#4752) 2024-11-11 10:50:57 +01:00
mini.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
news.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
pick.lua fix(pick): get rid of "auto" picker and set better defaults for telescope find_files (#4024) 2024-07-14 07:52:00 +02:00
plugin.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
root.lua feat(root): provide vim.g.root_lsp_ignore to ignore LSP servers (#4332) 2024-10-03 15:55:25 +02:00
terminal.lua feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706) 2024-11-07 15:54:47 +01:00
ui.lua perf(ui): only enable treesitter folds if the buffer has treesitter highlighting 2024-11-09 23:33:05 +01:00