mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-12 10:24:37 +02:00
feat(ai): better completion/suggestions of AI engines
This commit is contained in:
parent
86904d2fb1
commit
b2e012cb83
6 changed files with 110 additions and 37 deletions
|
@ -11,6 +11,20 @@ vim.g.autoformat = true
|
||||||
-- enabled with `:LazyExtras`
|
-- enabled with `:LazyExtras`
|
||||||
vim.g.lazyvim_picker = "auto"
|
vim.g.lazyvim_picker = "auto"
|
||||||
|
|
||||||
|
-- if the completion engine supports the AI source,
|
||||||
|
-- use that instead of inline suggestions
|
||||||
|
vim.g.ai_cmp = true
|
||||||
|
|
||||||
|
-- if `vim.g.ai_cmp` is false, or the completion engine does
|
||||||
|
-- not support the AI source, use inline suggestions
|
||||||
|
-- with the keymaps below
|
||||||
|
vim.g.ai_suggest_accept = "<tab>"
|
||||||
|
vim.g.ai_suggest_accept_word = false
|
||||||
|
vim.g.ai_suggest_accept_line = false
|
||||||
|
vim.g.ai_suggest_next = "<M-]>"
|
||||||
|
vim.g.ai_suggest_prev = "<M-[>"
|
||||||
|
vim.g.ai_suggest_clear = "<C-]>"
|
||||||
|
|
||||||
-- LazyVim root dir detection
|
-- LazyVim root dir detection
|
||||||
-- Each entry can be:
|
-- Each entry can be:
|
||||||
-- * the name of a detector function like `lsp` or `cwd`
|
-- * the name of a detector function like `lsp` or `cwd`
|
||||||
|
|
|
@ -72,9 +72,10 @@ return {
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
experimental = {
|
experimental = {
|
||||||
ghost_text = {
|
-- only show ghost text when we show ai completions
|
||||||
|
ghost_text = vim.g.ai_cmp and {
|
||||||
hl_group = "CmpGhostText",
|
hl_group = "CmpGhostText",
|
||||||
},
|
} or false,
|
||||||
},
|
},
|
||||||
sorting = defaults.sorting,
|
sorting = defaults.sorting,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,31 @@
|
||||||
return {
|
return {
|
||||||
|
|
||||||
-- codeium cmp source
|
|
||||||
{
|
|
||||||
"nvim-cmp",
|
|
||||||
dependencies = {
|
|
||||||
-- codeium
|
-- codeium
|
||||||
{
|
{
|
||||||
"Exafunction/codeium.nvim",
|
"Exafunction/codeium.nvim",
|
||||||
cmd = "Codeium",
|
cmd = "Codeium",
|
||||||
build = ":Codeium Auth",
|
build = ":Codeium Auth",
|
||||||
opts = {},
|
opts = {
|
||||||
|
enable_cmp_source = vim.g.ai_cmp,
|
||||||
|
virtual_text = {
|
||||||
|
enabled = not vim.g.ai_cmp,
|
||||||
|
accept_fallback = vim.g.ai_suggest_accept,
|
||||||
|
key_bindings = {
|
||||||
|
accept = vim.g.ai_suggest_accept,
|
||||||
|
accept_word = vim.g.ai_suggest_accept_word,
|
||||||
|
accept_line = vim.g.ai_suggest_accept_line,
|
||||||
|
next = vim.g.ai_suggest_next,
|
||||||
|
prev = vim.g.ai_suggest_prev,
|
||||||
|
clear = vim.g.ai_suggest_clear,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
-- codeium cmp source
|
||||||
|
{
|
||||||
|
"nvim-cmp",
|
||||||
|
optional = true,
|
||||||
|
dependencies = { "codeium.nvim" },
|
||||||
---@param opts cmp.ConfigSchema
|
---@param opts cmp.ConfigSchema
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
table.insert(opts.sources, 1, {
|
table.insert(opts.sources, 1, {
|
||||||
|
@ -30,4 +44,18 @@ return {
|
||||||
table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.cmp_source("codeium"))
|
table.insert(opts.sections.lualine_x, 2, LazyVim.lualine.cmp_source("codeium"))
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"saghen/blink.cmp",
|
||||||
|
optional = true,
|
||||||
|
opts = {
|
||||||
|
sources = {
|
||||||
|
compat = vim.g.ai_cmp and { "codeium" } or nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dependencies = {
|
||||||
|
"codeium.nvim",
|
||||||
|
vim.g.ai_cmp and { "saghen/blink.compat" } or {},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,20 @@ return {
|
||||||
"zbirenbaum/copilot.lua",
|
"zbirenbaum/copilot.lua",
|
||||||
cmd = "Copilot",
|
cmd = "Copilot",
|
||||||
build = ":Copilot auth",
|
build = ":Copilot auth",
|
||||||
|
event = "InsertEnter",
|
||||||
opts = {
|
opts = {
|
||||||
suggestion = { enabled = false },
|
suggestion = {
|
||||||
|
enabled = true,
|
||||||
|
auto_trigger = true,
|
||||||
|
keymap = {
|
||||||
|
accept = vim.g.ai_suggest_accept,
|
||||||
|
accept_word = vim.g.ai_suggest_accept_word,
|
||||||
|
accept_line = vim.g.ai_suggest_accept_line,
|
||||||
|
next = vim.g.ai_suggest_next,
|
||||||
|
prev = vim.g.ai_suggest_prev,
|
||||||
|
dismiss = vim.g.ai_suggest_clear,
|
||||||
|
},
|
||||||
|
},
|
||||||
panel = { enabled = false },
|
panel = { enabled = false },
|
||||||
filetypes = {
|
filetypes = {
|
||||||
markdown = true,
|
markdown = true,
|
||||||
|
@ -55,9 +67,11 @@ return {
|
||||||
-- copilot cmp source
|
-- copilot cmp source
|
||||||
{
|
{
|
||||||
"nvim-cmp",
|
"nvim-cmp",
|
||||||
dependencies = {
|
optional = true,
|
||||||
|
dependencies = { -- this will only be evaluated if nvim-cmp is enabled
|
||||||
{
|
{
|
||||||
"zbirenbaum/copilot-cmp",
|
"zbirenbaum/copilot-cmp",
|
||||||
|
enabled = vim.g.ai_cmp, -- only enable if wanted
|
||||||
dependencies = "copilot.lua",
|
dependencies = "copilot.lua",
|
||||||
opts = {},
|
opts = {},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
|
@ -69,8 +83,13 @@ return {
|
||||||
copilot_cmp._on_insert_enter({})
|
copilot_cmp._on_insert_enter({})
|
||||||
end, "copilot")
|
end, "copilot")
|
||||||
end,
|
end,
|
||||||
|
specs = {
|
||||||
|
{
|
||||||
|
"zbirenbaum/copilot.lua",
|
||||||
|
opts = { suggestion = { enabled = false } },
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
|
"nvim-cmp",
|
||||||
---@param opts cmp.ConfigSchema
|
---@param opts cmp.ConfigSchema
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
table.insert(opts.sources, 1, {
|
table.insert(opts.sources, 1, {
|
||||||
|
@ -80,23 +99,14 @@ return {
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"saghen/blink.cmp",
|
"saghen/blink.cmp",
|
||||||
optional = true,
|
optional = true,
|
||||||
specs = {
|
|
||||||
{
|
|
||||||
"zbirenbaum/copilot.lua",
|
|
||||||
event = "InsertEnter",
|
|
||||||
opts = {
|
|
||||||
suggestion = {
|
|
||||||
enabled = true,
|
|
||||||
auto_trigger = true,
|
|
||||||
keymap = { accept = false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
opts = {
|
opts = {
|
||||||
windows = {
|
windows = {
|
||||||
ghost_text = {
|
ghost_text = {
|
||||||
|
@ -104,7 +114,7 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
keymap = {
|
keymap = {
|
||||||
["<Tab>"] = {
|
[vim.g.ai_suggest_accept] = {
|
||||||
function(cmp)
|
function(cmp)
|
||||||
if cmp.is_in_snippet() then
|
if cmp.is_in_snippet() then
|
||||||
return cmp.accept()
|
return cmp.accept()
|
||||||
|
|
|
@ -6,7 +6,10 @@ return {
|
||||||
{
|
{
|
||||||
"saghen/blink.cmp",
|
"saghen/blink.cmp",
|
||||||
version = "*",
|
version = "*",
|
||||||
opts_extend = { "sources.completion.enabled_providers" },
|
opts_extend = {
|
||||||
|
"sources.completion.enabled_providers",
|
||||||
|
"sources.compat",
|
||||||
|
},
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"rafamadriz/friendly-snippets",
|
"rafamadriz/friendly-snippets",
|
||||||
-- add blink.compat to dependencies
|
-- add blink.compat to dependencies
|
||||||
|
@ -45,6 +48,9 @@ return {
|
||||||
-- experimental signature help support
|
-- experimental signature help support
|
||||||
-- trigger = { signature_help = { enabled = true } }
|
-- trigger = { signature_help = { enabled = true } }
|
||||||
sources = {
|
sources = {
|
||||||
|
-- adding any nvim-cmp sources here will enable them
|
||||||
|
-- with blink.compat
|
||||||
|
compat = {},
|
||||||
completion = {
|
completion = {
|
||||||
-- remember to enable your providers here
|
-- remember to enable your providers here
|
||||||
enabled_providers = { "lsp", "path", "snippets", "buffer" },
|
enabled_providers = { "lsp", "path", "snippets", "buffer" },
|
||||||
|
@ -55,6 +61,20 @@ return {
|
||||||
preset = "enter",
|
preset = "enter",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
---@param opts blink.cmp.Config
|
||||||
|
config = function(_, opts)
|
||||||
|
for _, source in ipairs(opts.sources.compat or {}) do
|
||||||
|
opts.sources.providers[source] = opts.sources.providers[source]
|
||||||
|
or {
|
||||||
|
name = source,
|
||||||
|
module = "blink.compat.source",
|
||||||
|
}
|
||||||
|
if not vim.tbl_contains(opts.sources.completion.enabled_providers, source) then
|
||||||
|
table.insert(opts.sources.completion.enabled_providers, source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
require("blink.cmp").setup(opts)
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- add icons
|
-- add icons
|
||||||
|
|
|
@ -7,7 +7,7 @@ function M.cmp_source(name, icon)
|
||||||
if not package.loaded["cmp"] then
|
if not package.loaded["cmp"] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for _, s in ipairs(require("cmp").core.sources) do
|
for _, s in ipairs(require("cmp").core.sources or {}) do
|
||||||
if s.name == name then
|
if s.name == name then
|
||||||
if s.source:is_available() then
|
if s.source:is_available() then
|
||||||
started = true
|
started = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue