mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
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.
This commit is contained in:
parent
c22db72435
commit
fbf881f80b
9 changed files with 230 additions and 99 deletions
|
@ -1,4 +1,8 @@
|
|||
return {
|
||||
-- disable builtin snippet support
|
||||
{ "garymjr/nvim-snippets", enabled = false },
|
||||
|
||||
-- add luasnip
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
lazy = true,
|
||||
|
@ -12,43 +16,56 @@ return {
|
|||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-cmp",
|
||||
dependencies = {
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
opts = function(_, opts)
|
||||
opts.snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
}
|
||||
table.insert(opts.sources, { name = "luasnip" })
|
||||
end,
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
history = true,
|
||||
delete_check_events = "TextChanged",
|
||||
},
|
||||
},
|
||||
|
||||
-- add snippet_forward action
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
opts = function()
|
||||
LazyVim.cmp.actions.snippet_forward = function()
|
||||
if require("luasnip").jumpable(1) then
|
||||
require("luasnip").jump(1)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
-- nvim-cmp integration
|
||||
{
|
||||
"nvim-cmp",
|
||||
optional = true,
|
||||
dependencies = { "saadparwaiz1/cmp_luasnip" },
|
||||
opts = function(_, opts)
|
||||
opts.snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
}
|
||||
table.insert(opts.sources, { name = "luasnip" })
|
||||
end,
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{
|
||||
"<tab>",
|
||||
function()
|
||||
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next" or "<tab>"
|
||||
end,
|
||||
expr = true, silent = true, mode = "i",
|
||||
},
|
||||
{ "<tab>", function() require("luasnip").jump(1) end, mode = "s" },
|
||||
{ "<s-tab>", function() require("luasnip").jump(-1) end, mode = { "i", "s" } },
|
||||
},
|
||||
},
|
||||
|
||||
-- blink.cmp integration
|
||||
{
|
||||
"garymjr/nvim-snippets",
|
||||
enabled = false,
|
||||
"saghen/blink.cmp",
|
||||
optional = true,
|
||||
opts = {
|
||||
accept = {
|
||||
expand_snippet = function(...)
|
||||
return require("luasnip").lsp_expand(...)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue