diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index af69afc3..249b7baf 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -106,10 +106,22 @@ return { table.insert(opts.sources, { name = "snippets" }) end end, + -- stylua: ignore + keys = { + { + "", + function() + return vim.snippet.active({ direction = 1 }) and "lua vim.snippet.jump(1)" + or LazyVim.cmp.ai_accept() + or "" + end, + expr = true, silent = true, mode = "i", + }, + }, init = function() -- Neovim enabled snippet navigation mappings by default in v0.11 if vim.fn.has("nvim-0.11") == 0 then - vim.keymap.set({ "i", "s" }, "", function() + vim.keymap.set({ "s" }, "", function() return vim.snippet.active({ direction = 1 }) and "lua vim.snippet.jump(1)" or "" end, { expr = true, silent = true }) vim.keymap.set({ "i", "s" }, "", function() diff --git a/lua/lazyvim/plugins/extras/ai/codeium.lua b/lua/lazyvim/plugins/extras/ai/codeium.lua index e6bf6d0b..9fdec062 100644 --- a/lua/lazyvim/plugins/extras/ai/codeium.lua +++ b/lua/lazyvim/plugins/extras/ai/codeium.lua @@ -9,24 +9,34 @@ return { enable_cmp_source = vim.g.ai_cmp, virtual_text = { enabled = not vim.g.ai_cmp, - accept_fallback = vim.g.ai_suggest_accept, + accept_fallback = "", 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, + accept = "", + next = "", + prev = "", }, }, }, + config = function(_, opts) + LazyVim.cmp.ai_accept = function() + if require("codeium.virtual_text").get_current_completion_item() then + LazyVim.create_undo() + vim.api.nvim_input(require("codeium.virtual_text").accept()) + return true + end + end + if opts.virtual_text.key_bindings.accept == "" then + opts.virtual_text.key_bindings.accept = false + end + require("codeium").setup(opts) + end, }, + -- codeium cmp source { "nvim-cmp", optional = true, dependencies = { "codeium.nvim" }, - ---@param opts cmp.ConfigSchema opts = function(_, opts) table.insert(opts.sources, 1, { name = "codeium", diff --git a/lua/lazyvim/plugins/extras/ai/copilot.lua b/lua/lazyvim/plugins/extras/ai/copilot.lua index 8fb0492c..53d38cf0 100644 --- a/lua/lazyvim/plugins/extras/ai/copilot.lua +++ b/lua/lazyvim/plugins/extras/ai/copilot.lua @@ -8,15 +8,12 @@ return { event = "InsertEnter", opts = { suggestion = { - enabled = true, + enabled = not vim.g.ai_cmp, 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, + accept = "", + next = "", + prev = "", }, }, panel = { enabled = false }, @@ -25,7 +22,24 @@ return { help = true, }, }, + config = function(_, opts) + LazyVim.cmp.ai_accept = function() + if require("copilot.suggestion").is_visible() then + LazyVim.create_undo() + require("copilot.suggestion").accept() + return "" + end + end + -- tab is handled by nvim-cmp / blink.cmp + local key = opts.suggestion.keymap.accept + if key == "" then + opts.suggestion.keymap.accept = false + end + require("copilot").setup(opts) + end, }, + + -- lualine { "nvim-lualine/lualine.nvim", optional = true, @@ -72,22 +86,17 @@ return { { "zbirenbaum/copilot-cmp", enabled = vim.g.ai_cmp, -- only enable if wanted - dependencies = "copilot.lua", opts = {}, config = function(_, opts) local copilot_cmp = require("copilot_cmp") copilot_cmp.setup(opts) -- attach cmp source whenever copilot attaches -- fixes lazy-loading issues with the copilot cmp source - LazyVim.lsp.on_attach(function(client) + LazyVim.lsp.on_attach(function() copilot_cmp._on_insert_enter({}) end, "copilot") end, specs = { - { - "zbirenbaum/copilot.lua", - opts = { suggestion = { enabled = false } }, - }, { "nvim-cmp", ---@param opts cmp.ConfigSchema @@ -104,31 +113,18 @@ return { }, }, + -- blink.cmp { "saghen/blink.cmp", optional = true, opts = { - windows = { - ghost_text = { - enabled = false, - }, - }, - keymap = { - [vim.g.ai_suggest_accept] = { - function(cmp) - if cmp.is_in_snippet() then - return cmp.accept() - elseif require("copilot.suggestion").is_visible() then - LazyVim.create_undo() - require("copilot.suggestion").accept() - return true - else - return cmp.select_and_accept() - end - end, - "snippet_forward", - "fallback", - }, + windows = { ghost_text = { enabled = false } }, + }, + specs = { + -- blink has no copilot source, so force enable suggestions + { + "zbirenbaum/copilot.lua", + opts = { suggestion = { enabled = true } }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/coding/blink.lua b/lua/lazyvim/plugins/extras/coding/blink.lua index 9c9b7be1..3b054c27 100644 --- a/lua/lazyvim/plugins/extras/coding/blink.lua +++ b/lua/lazyvim/plugins/extras/coding/blink.lua @@ -38,7 +38,7 @@ return { auto_show = true, }, ghost_text = { - enabled = true, + enabled = vim.g.ai_cmp, }, }, @@ -59,6 +59,13 @@ return { keymap = { preset = "enter", + [""] = { + "snippet_forward", + function() + return LazyVim.cmp.ai_accept() + end, + "fallback", + }, }, }, ---@param opts blink.cmp.Config diff --git a/lua/lazyvim/plugins/extras/coding/luasnip.lua b/lua/lazyvim/plugins/extras/coding/luasnip.lua index 47bd80c4..8f2aa70f 100644 --- a/lua/lazyvim/plugins/extras/coding/luasnip.lua +++ b/lua/lazyvim/plugins/extras/coding/luasnip.lua @@ -12,34 +12,34 @@ 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", }, }, + + -- 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 = { { "", function() - return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + return require("luasnip").jumpable(1) and "luasnip-jump-next" + or LazyVim.cmp.ai_accept() + or "" end, expr = true, silent = true, mode = "i", }, @@ -51,4 +51,6 @@ return { "garymjr/nvim-snippets", enabled = false, }, + + -- TODO: blink.cmp integration } diff --git a/lua/lazyvim/util/cmp.lua b/lua/lazyvim/util/cmp.lua index 5eff81fa..1c2ebc4c 100644 --- a/lua/lazyvim/util/cmp.lua +++ b/lua/lazyvim/util/cmp.lua @@ -1,6 +1,9 @@ ---@class lazyvim.util.cmp local M = {} +---@return string? +function M.ai_accept() end + ---@alias Placeholder {n:number, text:string} ---@param snippet string