2024-12-13 22:54:52 +01:00
|
|
|
---@diagnostic disable: missing-fields
|
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
|
|
|
if lazyvim_docs then
|
|
|
|
-- set to `true` to follow the main branch
|
|
|
|
-- you need to have a working rust toolchain to build the plugin
|
|
|
|
-- in this case.
|
|
|
|
vim.g.lazyvim_blink_main = false
|
|
|
|
end
|
|
|
|
|
2024-11-02 09:54:55 +01:00
|
|
|
return {
|
2024-12-13 19:56:03 +01:00
|
|
|
{
|
|
|
|
"hrsh7th/nvim-cmp",
|
|
|
|
optional = true,
|
|
|
|
enabled = false,
|
|
|
|
},
|
2024-11-02 09:54:55 +01:00
|
|
|
{
|
|
|
|
"saghen/blink.cmp",
|
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
|
|
|
version = not vim.g.lazyvim_blink_main and "*",
|
|
|
|
build = vim.g.lazyvim_blink_main and "cargo build --release",
|
|
|
|
opts_extend = {
|
|
|
|
"sources.completion.enabled_providers",
|
|
|
|
"sources.compat",
|
2024-12-11 10:57:07 +01:00
|
|
|
"sources.default",
|
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
|
|
|
},
|
2024-11-02 09:54:55 +01:00
|
|
|
dependencies = {
|
|
|
|
"rafamadriz/friendly-snippets",
|
|
|
|
-- add blink.compat to dependencies
|
2024-11-24 22:03:43 +01:00
|
|
|
{
|
|
|
|
"saghen/blink.compat",
|
|
|
|
optional = true, -- make optional so it's only enabled if any extras need it
|
|
|
|
opts = {},
|
|
|
|
version = not vim.g.lazyvim_blink_main and "*",
|
|
|
|
},
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
event = "InsertEnter",
|
|
|
|
|
|
|
|
---@module 'blink.cmp'
|
|
|
|
---@type blink.cmp.Config
|
|
|
|
opts = {
|
2024-12-16 16:19:22 +01:00
|
|
|
snippets = {
|
|
|
|
expand = function(snippet, _)
|
|
|
|
return LazyVim.cmp.expand(snippet)
|
|
|
|
end,
|
|
|
|
},
|
2024-12-05 02:46:15 -05:00
|
|
|
appearance = {
|
2024-11-02 09:54:55 +01:00
|
|
|
-- sets the fallback highlight groups to nvim-cmp's highlight groups
|
|
|
|
-- useful for when your theme doesn't support blink.cmp
|
|
|
|
-- will be removed in a future release, assuming themes add support
|
|
|
|
use_nvim_cmp_as_default = false,
|
2024-12-05 02:46:15 -05:00
|
|
|
-- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
|
|
|
|
-- adjusts spacing to ensure icons are aligned
|
|
|
|
nerd_font_variant = "mono",
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
2024-11-28 07:38:49 +01:00
|
|
|
completion = {
|
2024-12-05 02:46:15 -05:00
|
|
|
accept = {
|
|
|
|
-- experimental auto-brackets support
|
|
|
|
auto_brackets = {
|
|
|
|
enabled = true,
|
|
|
|
},
|
|
|
|
},
|
2024-11-28 07:38:49 +01:00
|
|
|
menu = {
|
2024-12-03 12:06:58 -08:00
|
|
|
draw = {
|
2024-12-13 23:37:25 +02:00
|
|
|
treesitter = { "lsp" },
|
2024-12-03 12:06:58 -08:00
|
|
|
},
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
documentation = {
|
|
|
|
auto_show = true,
|
2024-11-28 07:38:49 +01:00
|
|
|
auto_show_delay_ms = 200,
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
ghost_text = {
|
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
|
|
|
enabled = vim.g.ai_cmp,
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
-- experimental signature help support
|
2024-12-05 02:46:15 -05:00
|
|
|
-- signature = { enabled = true },
|
|
|
|
|
2024-11-02 09:54:55 +01:00
|
|
|
sources = {
|
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
|
|
|
-- adding any nvim-cmp sources here will enable them
|
|
|
|
-- with blink.compat
|
|
|
|
compat = {},
|
2024-12-11 10:57:07 +01:00
|
|
|
default = { "lsp", "path", "snippets", "buffer" },
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
|
2025-02-15 23:51:17 +02:00
|
|
|
cmdline = {
|
2025-02-16 00:47:17 +02:00
|
|
|
enabled = false,
|
2025-02-15 23:51:17 +02:00
|
|
|
sources = {},
|
|
|
|
},
|
|
|
|
|
2024-11-02 09:54:55 +01:00
|
|
|
keymap = {
|
|
|
|
preset = "enter",
|
2024-12-14 07:42:24 +01:00
|
|
|
["<C-y>"] = { "select_and_accept" },
|
2024-11-02 09:54:55 +01: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.
2024-11-11 10:50:57 +01:00
|
|
|
---@param opts blink.cmp.Config | { sources: { compat: string[] } }
|
|
|
|
config = function(_, opts)
|
|
|
|
-- setup compat sources
|
2024-12-11 10:57:07 +01:00
|
|
|
local enabled = opts.sources.default
|
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
|
|
|
for _, source in ipairs(opts.sources.compat or {}) do
|
|
|
|
opts.sources.providers[source] = vim.tbl_deep_extend(
|
|
|
|
"force",
|
|
|
|
{ name = source, module = "blink.compat.source" },
|
|
|
|
opts.sources.providers[source] or {}
|
|
|
|
)
|
|
|
|
if type(enabled) == "table" and not vim.tbl_contains(enabled, source) then
|
|
|
|
table.insert(enabled, source)
|
|
|
|
end
|
|
|
|
end
|
2024-12-13 01:25:42 -05:00
|
|
|
|
2024-12-15 18:44:24 +01:00
|
|
|
-- add ai_accept to <Tab> key
|
|
|
|
if not opts.keymap["<Tab>"] then
|
|
|
|
if opts.keymap.preset == "super-tab" then -- super-tab
|
|
|
|
opts.keymap["<Tab>"] = {
|
2024-12-16 14:29:13 -05:00
|
|
|
require("blink.cmp.keymap.presets")["super-tab"]["<Tab>"][1],
|
2024-12-15 18:44:24 +01:00
|
|
|
LazyVim.cmp.map({ "snippet_forward", "ai_accept" }),
|
|
|
|
"fallback",
|
|
|
|
}
|
|
|
|
else -- other presets
|
|
|
|
opts.keymap["<Tab>"] = {
|
|
|
|
LazyVim.cmp.map({ "snippet_forward", "ai_accept" }),
|
|
|
|
"fallback",
|
|
|
|
}
|
|
|
|
end
|
2024-12-15 08:59:45 +01:00
|
|
|
end
|
|
|
|
|
2024-12-13 01:25:42 -05:00
|
|
|
-- Unset custom prop to pass blink.cmp validation
|
2024-12-13 00:25:51 +01:00
|
|
|
opts.sources.compat = nil
|
2024-12-03 12:06:58 -08:00
|
|
|
|
|
|
|
-- check if we need to override symbol kinds
|
|
|
|
for _, provider in pairs(opts.sources.providers or {}) do
|
|
|
|
---@cast provider blink.cmp.SourceProviderConfig|{kind?:string}
|
|
|
|
if provider.kind then
|
2024-12-11 21:29:08 -08:00
|
|
|
local CompletionItemKind = require("blink.cmp.types").CompletionItemKind
|
|
|
|
local kind_idx = #CompletionItemKind + 1
|
|
|
|
|
|
|
|
CompletionItemKind[kind_idx] = provider.kind
|
2024-12-13 22:54:52 +01:00
|
|
|
---@diagnostic disable-next-line: no-unknown
|
2024-12-11 21:29:08 -08:00
|
|
|
CompletionItemKind[provider.kind] = kind_idx
|
|
|
|
|
2024-12-03 12:06:58 -08:00
|
|
|
---@type fun(ctx: blink.cmp.Context, items: blink.cmp.CompletionItem[]): blink.cmp.CompletionItem[]
|
|
|
|
local transform_items = provider.transform_items
|
|
|
|
---@param ctx blink.cmp.Context
|
|
|
|
---@param items blink.cmp.CompletionItem[]
|
|
|
|
provider.transform_items = function(ctx, items)
|
|
|
|
items = transform_items and transform_items(ctx, items) or items
|
|
|
|
for _, item in ipairs(items) do
|
2024-12-11 21:29:08 -08:00
|
|
|
item.kind = kind_idx or item.kind
|
2024-12-03 12:06:58 -08:00
|
|
|
end
|
|
|
|
return items
|
|
|
|
end
|
2024-12-13 01:25:42 -05:00
|
|
|
|
|
|
|
-- Unset custom prop to pass blink.cmp validation
|
|
|
|
provider.kind = nil
|
2024-12-03 12:06:58 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
require("blink.cmp").setup(opts)
|
|
|
|
end,
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
-- add icons
|
|
|
|
{
|
|
|
|
"saghen/blink.cmp",
|
|
|
|
opts = function(_, opts)
|
2024-11-28 21:51:21 +01:00
|
|
|
opts.appearance = opts.appearance or {}
|
2025-01-17 04:00:30 -05:00
|
|
|
opts.appearance.kind_icons = vim.tbl_extend("force", opts.appearance.kind_icons or {}, LazyVim.config.icons.kinds)
|
2024-11-02 09:54:55 +01:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
|
|
|
|
-- lazydev
|
|
|
|
{
|
|
|
|
"saghen/blink.cmp",
|
|
|
|
opts = {
|
|
|
|
sources = {
|
2024-12-11 10:57:07 +01:00
|
|
|
-- add lazydev to your completion providers
|
|
|
|
default = { "lazydev" },
|
2024-11-02 09:54:55 +01:00
|
|
|
providers = {
|
|
|
|
lazydev = {
|
|
|
|
name = "LazyDev",
|
|
|
|
module = "lazydev.integrations.blink",
|
2024-12-16 08:17:09 +01:00
|
|
|
score_offset = 100, -- show at a higher priority than lsp
|
2024-11-02 09:54:55 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-16 15:32:07 +09:00
|
|
|
-- catppuccin support
|
|
|
|
{
|
|
|
|
"catppuccin",
|
|
|
|
optional = true,
|
|
|
|
opts = {
|
|
|
|
integrations = { blink_cmp = true },
|
|
|
|
},
|
|
|
|
},
|
2024-11-02 09:54:55 +01:00
|
|
|
}
|