mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-11 18:04:32 +02:00
refactor: use actions
This commit is contained in:
parent
3f404079dc
commit
f40a2a1faa
7 changed files with 100 additions and 64 deletions
|
@ -9,26 +9,26 @@ return {
|
|||
enable_cmp_source = vim.g.ai_cmp,
|
||||
virtual_text = {
|
||||
enabled = not vim.g.ai_cmp,
|
||||
accept_fallback = "<tab>",
|
||||
key_bindings = {
|
||||
accept = "<tab>",
|
||||
accept = false, -- handled by nvim-cmp / blink.cmp
|
||||
next = "<M-]>",
|
||||
prev = "<M-[>",
|
||||
},
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
LazyVim.cmp.ai_accept = function()
|
||||
},
|
||||
|
||||
-- add ai_accept action
|
||||
{
|
||||
"Exafunction/codeium.nvim",
|
||||
opts = function()
|
||||
LazyVim.cmp.actions.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 == "<tab>" then
|
||||
opts.virtual_text.key_bindings.accept = false
|
||||
end
|
||||
require("codeium").setup(opts)
|
||||
end,
|
||||
},
|
||||
|
||||
|
@ -65,7 +65,7 @@ return {
|
|||
},
|
||||
dependencies = {
|
||||
"codeium.nvim",
|
||||
vim.g.ai_cmp and { "saghen/blink.compat" } or {},
|
||||
vim.g.ai_cmp and "saghen/blink.compat" or nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ return {
|
|||
enabled = not vim.g.ai_cmp,
|
||||
auto_trigger = true,
|
||||
keymap = {
|
||||
accept = "<tab>",
|
||||
accept = false, -- handled by nvim-cmp / blink.cmp
|
||||
next = "<M-]>",
|
||||
prev = "<M-[>",
|
||||
},
|
||||
|
@ -22,20 +22,19 @@ return {
|
|||
help = true,
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
LazyVim.cmp.ai_accept = function()
|
||||
},
|
||||
|
||||
-- add ai_accept action
|
||||
{
|
||||
"zbirenbaum/copilot.lua",
|
||||
opts = function()
|
||||
LazyVim.cmp.actions.ai_accept = function()
|
||||
if require("copilot.suggestion").is_visible() then
|
||||
LazyVim.create_undo()
|
||||
require("copilot.suggestion").accept()
|
||||
return ""
|
||||
return true
|
||||
end
|
||||
end
|
||||
-- tab is handled by nvim-cmp / blink.cmp
|
||||
local key = opts.suggestion.keymap.accept
|
||||
if key == "<tab>" then
|
||||
opts.suggestion.keymap.accept = false
|
||||
end
|
||||
require("copilot").setup(opts)
|
||||
end,
|
||||
},
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
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
|
||||
|
||||
return {
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
|
@ -5,7 +12,8 @@ return {
|
|||
},
|
||||
{
|
||||
"saghen/blink.cmp",
|
||||
version = "*",
|
||||
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",
|
||||
|
@ -59,11 +67,8 @@ return {
|
|||
|
||||
keymap = {
|
||||
preset = "enter",
|
||||
["<tab>"] = {
|
||||
"snippet_forward",
|
||||
function()
|
||||
return LazyVim.cmp.ai_accept()
|
||||
end,
|
||||
["<Tab>"] = {
|
||||
LazyVim.cmp.map({ "snippet_forward", "ai_accept" }),
|
||||
"fallback",
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
return {
|
||||
-- disable builtin snippet support
|
||||
{ "garymjr/nvim-snippets", enabled = false },
|
||||
|
||||
-- add luasnip
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
lazy = true,
|
||||
|
@ -19,6 +23,19 @@ return {
|
|||
},
|
||||
},
|
||||
|
||||
-- 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",
|
||||
|
@ -34,23 +51,21 @@ return {
|
|||
end,
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{
|
||||
"<tab>",
|
||||
function()
|
||||
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next"
|
||||
or LazyVim.cmp.ai_accept()
|
||||
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" } },
|
||||
},
|
||||
},
|
||||
{
|
||||
"garymjr/nvim-snippets",
|
||||
enabled = false,
|
||||
},
|
||||
|
||||
-- TODO: blink.cmp integration
|
||||
-- blink.cmp integration
|
||||
{
|
||||
"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