2022-12-30 17:30:52 +01:00
return {
-- auto completion
{
" hrsh7th/nvim-cmp " ,
2023-01-16 20:39:12 +01:00
version = false , -- last release is way too old
2022-12-30 17:30:52 +01:00
event = " InsertEnter " ,
dependencies = {
" hrsh7th/cmp-nvim-lsp " ,
" hrsh7th/cmp-buffer " ,
" hrsh7th/cmp-path " ,
} ,
2024-03-28 21:32:09 +01:00
-- Not all LSP servers add brackets when completing a function.
-- To better deal with this, LazyVim adds a custom option to cmp,
-- that you can configure. For example:
--
-- ```lua
-- opts = {
-- auto_brackets = { "python" }
-- }
-- ```
2023-01-08 15:05:34 +01:00
opts = function ( )
2023-06-16 14:51:19 +02:00
vim.api . nvim_set_hl ( 0 , " CmpGhostText " , { link = " Comment " , default = true } )
2022-12-30 17:30:52 +01:00
local cmp = require ( " cmp " )
2023-06-28 11:24:54 +02:00
local defaults = require ( " cmp.config.default " ) ( )
2024-06-16 15:17:53 +02:00
local auto_select = true
2023-01-08 15:05:34 +01:00
return {
2024-03-28 21:32:09 +01:00
auto_brackets = { } , -- configure any filetype to auto add brackets
2023-01-04 08:21:44 +01:00
completion = {
2024-06-16 15:17:53 +02:00
completeopt = " menu,menuone,noinsert " .. ( auto_select and " " or " ,noselect " ) ,
2023-01-04 08:21:44 +01:00
} ,
2024-06-16 15:17:53 +02:00
preselect = auto_select and cmp.PreselectMode . Item or cmp.PreselectMode . None ,
2022-12-30 17:30:52 +01:00
mapping = cmp.mapping . preset.insert ( {
[ " <C-b> " ] = cmp.mapping . scroll_docs ( - 4 ) ,
[ " <C-f> " ] = cmp.mapping . scroll_docs ( 4 ) ,
2024-09-18 08:20:01 +02:00
[ " <C-n> " ] = cmp.mapping . select_next_item ( { behavior = cmp.SelectBehavior . Insert } ) ,
[ " <C-p> " ] = cmp.mapping . select_prev_item ( { behavior = cmp.SelectBehavior . Insert } ) ,
2022-12-30 17:30:52 +01:00
[ " <C-Space> " ] = cmp.mapping . complete ( ) ,
2024-06-16 15:17:53 +02:00
[ " <CR> " ] = LazyVim.cmp . confirm ( { select = auto_select } ) ,
[ " <C-y> " ] = LazyVim.cmp . confirm ( { select = true } ) ,
2024-05-19 22:46:09 +02:00
[ " <S-CR> " ] = LazyVim.cmp . confirm ( { behavior = cmp.ConfirmBehavior . Replace } ) , -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
2023-10-09 09:51:53 +02:00
[ " <C-CR> " ] = function ( fallback )
cmp.abort ( )
fallback ( )
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
[ " <tab> " ] = function ( fallback )
return LazyVim.cmp . map ( { " snippet_forward " , " ai_accept " } , fallback ) ( )
end ,
2022-12-30 17:30:52 +01:00
} ) ,
2023-10-09 10:05:57 +02:00
sources = cmp.config . sources ( {
{ name = " nvim_lsp " } ,
{ name = " path " } ,
} , {
{ name = " buffer " } ,
} ) ,
2022-12-31 17:03:39 +01:00
formatting = {
2024-06-29 22:04:40 +03:00
format = function ( entry , item )
2024-06-16 15:17:53 +02:00
local icons = LazyVim.config . icons.kinds
2022-12-31 17:03:39 +01:00
if icons [ item.kind ] then
item.kind = icons [ item.kind ] .. item.kind
end
2024-07-01 00:14:00 +03:00
local widths = {
abbr = vim.g . cmp_widths and vim.g . cmp_widths.abbr or 40 ,
menu = vim.g . cmp_widths and vim.g . cmp_widths.menu or 30 ,
}
for key , width in pairs ( widths ) do
if item [ key ] and vim.fn . strdisplaywidth ( item [ key ] ) > width then
item [ key ] = vim.fn . strcharpart ( item [ key ] , 0 , width - 1 ) .. " … "
end
2024-06-29 22:04:40 +03:00
end
2024-07-01 00:14:00 +03:00
2022-12-31 17:03:39 +01:00
return item
end ,
} ,
2023-01-02 09:49:22 +01:00
experimental = {
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
-- only show ghost text when we show ai completions
ghost_text = vim.g . ai_cmp and {
2023-06-16 14:51:19 +02:00
hl_group = " CmpGhostText " ,
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
} or false ,
2023-01-02 09:49:22 +01:00
} ,
2023-06-28 11:24:54 +02:00
sorting = defaults.sorting ,
2023-01-08 15:05:34 +01:00
}
2022-12-30 17:30:52 +01:00
end ,
2024-06-16 15:17:53 +02:00
main = " lazyvim.util.cmp " ,
2022-12-30 17:30:52 +01:00
} ,
2024-01-22 08:39:07 +01:00
-- snippets
2024-06-01 20:46:56 +02:00
{
" nvim-cmp " ,
2024-10-23 12:44:27 +03:00
optional = true ,
2024-06-01 20:46:56 +02:00
dependencies = {
{
" garymjr/nvim-snippets " ,
opts = {
friendly_snippets = true ,
2024-01-22 08:39:07 +01:00
} ,
2024-06-01 20:46:56 +02:00
dependencies = { " rafamadriz/friendly-snippets " } ,
} ,
} ,
opts = function ( _ , opts )
opts.snippet = {
expand = function ( item )
return LazyVim.cmp . expand ( item.body )
2024-01-22 08:39:07 +01:00
end ,
2024-05-16 18:03:58 +02:00
}
2024-06-08 00:12:59 +03:00
if LazyVim.has ( " nvim-snippets " ) then
table.insert ( opts.sources , { name = " snippets " } )
end
2024-06-01 20:46:56 +02:00
end ,
} ,
2024-01-22 08:39:07 +01:00
2022-12-30 17:30:52 +01:00
-- auto pairs
{
" echasnovski/mini.pairs " ,
2022-12-30 18:19:57 +01:00
event = " VeryLazy " ,
2024-04-11 17:23:17 +02:00
opts = {
2024-06-16 10:33:20 +02:00
modes = { insert = true , command = true , terminal = false } ,
2024-06-15 12:05:55 +02:00
-- skip autopair when next character is one of these
skip_next = [=[[%w%%%'%[%"%.%`%$]]=] ,
2024-06-15 18:52:25 +02:00
-- skip autopair when the cursor is inside these treesitter nodes
skip_ts = { " string " } ,
2024-06-15 12:05:55 +02:00
-- skip autopair when next character is closing pair
-- and there are more closing pairs than opening pairs
skip_unbalanced = true ,
-- better deal with markdown code blocks
markdown = true ,
2024-04-11 17:23:17 +02:00
} ,
2024-06-15 12:05:55 +02:00
config = function ( _ , opts )
2024-06-15 18:52:25 +02:00
LazyVim.mini . pairs ( opts )
2024-06-15 12:05:55 +02:00
end ,
2022-12-30 17:30:52 +01:00
} ,
-- comments
2023-09-26 13:24:03 +02:00
{
2024-05-21 19:31:40 +02:00
" folke/ts-comments.nvim " ,
event = " VeryLazy " ,
opts = { } ,
2024-05-18 12:05:19 +02:00
} ,
2024-05-18 21:52:16 +02:00
-- Better text-objects
{
" echasnovski/mini.ai " ,
event = " VeryLazy " ,
opts = function ( )
local ai = require ( " mini.ai " )
return {
n_lines = 500 ,
custom_textobjects = {
o = ai.gen_spec . treesitter ( { -- code block
a = { " @block.outer " , " @conditional.outer " , " @loop.outer " } ,
i = { " @block.inner " , " @conditional.inner " , " @loop.inner " } ,
} ) ,
f = ai.gen_spec . treesitter ( { a = " @function.outer " , i = " @function.inner " } ) , -- function
c = ai.gen_spec . treesitter ( { a = " @class.outer " , i = " @class.inner " } ) , -- class
t = { " <([%p%w]-)%f[^<%w][^<>]->.-</%1> " , " ^<.->().*()</[^/]->$ " } , -- tags
d = { " %f[%d]%d+ " } , -- digits
e = { -- Word with case
{ " %u[%l%d]+%f[^%l%d] " , " %f[%S][%l%d]+%f[^%l%d] " , " %f[%P][%l%d]+%f[^%l%d] " , " ^[%l%d]+%f[^%l%d] " } ,
" ^().*()$ " ,
} ,
g = LazyVim.mini . ai_buffer , -- buffer
u = ai.gen_spec . function_call ( ) , -- u for "Usage"
U = ai.gen_spec . function_call ( { name_pattern = " [%w_] " } ) , -- without dot in function name
} ,
}
end ,
2024-07-15 15:06:34 +08:00
config = function ( _ , opts )
require ( " mini.ai " ) . setup ( opts )
LazyVim.on_load ( " which-key.nvim " , function ( )
vim.schedule ( function ( )
LazyVim.mini . ai_whichkey ( opts )
end )
end )
end ,
2024-05-18 21:52:16 +02:00
} ,
2024-06-02 09:33:52 +02:00
{
" folke/lazydev.nvim " ,
ft = " lua " ,
2024-06-04 09:39:35 +02:00
cmd = " LazyDev " ,
2024-06-04 08:43:31 +02:00
opts = {
library = {
2024-11-24 23:03:03 +01:00
{ path = " ${3rd}/luv/library " , words = { " vim%.uv " } } ,
2024-06-04 08:43:31 +02:00
{ path = " LazyVim " , words = { " LazyVim " } } ,
2024-11-07 15:54:47 +01:00
{ path = " snacks.nvim " , words = { " Snacks " } } ,
2024-06-04 08:43:31 +02:00
{ path = " lazy.nvim " , words = { " LazyVim " } } ,
} ,
} ,
2024-06-02 09:33:52 +02:00
} ,
-- Add lazydev source to cmp
{
" hrsh7th/nvim-cmp " ,
2024-10-23 12:44:27 +03:00
optional = true ,
2024-06-02 09:33:52 +02:00
opts = function ( _ , opts )
table.insert ( opts.sources , { name = " lazydev " , group_index = 0 } )
end ,
} ,
2022-12-30 17:30:52 +01:00
}