mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-11 18:04:32 +02:00
refactor: still not ideal...
This commit is contained in:
parent
b2e012cb83
commit
0270a39a7b
6 changed files with 89 additions and 59 deletions
|
@ -106,10 +106,22 @@ return {
|
|||
table.insert(opts.sources, { name = "snippets" })
|
||||
end
|
||||
end,
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{
|
||||
"<tab>",
|
||||
function()
|
||||
return vim.snippet.active({ direction = 1 }) and "<cmd>lua vim.snippet.jump(1)<cr>"
|
||||
or LazyVim.cmp.ai_accept()
|
||||
or "<Tab>"
|
||||
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" }, "<Tab>", function()
|
||||
vim.keymap.set({ "s" }, "<Tab>", function()
|
||||
return vim.snippet.active({ direction = 1 }) and "<cmd>lua vim.snippet.jump(1)<cr>" or "<Tab>"
|
||||
end, { expr = true, silent = true })
|
||||
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
|
||||
|
|
|
@ -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 = "<tab>",
|
||||
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 = "<tab>",
|
||||
next = "<M-]>",
|
||||
prev = "<M-[>",
|
||||
},
|
||||
},
|
||||
},
|
||||
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 == "<tab>" 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",
|
||||
|
|
|
@ -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 = "<tab>",
|
||||
next = "<M-]>",
|
||||
prev = "<M-[>",
|
||||
},
|
||||
},
|
||||
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 == "<tab>" 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 } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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",
|
||||
["<tab>"] = {
|
||||
"snippet_forward",
|
||||
function()
|
||||
return LazyVim.cmp.ai_accept()
|
||||
end,
|
||||
"fallback",
|
||||
},
|
||||
},
|
||||
},
|
||||
---@param opts blink.cmp.Config
|
||||
|
|
|
@ -12,11 +12,18 @@ return {
|
|||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
history = true,
|
||||
delete_check_events = "TextChanged",
|
||||
},
|
||||
},
|
||||
|
||||
-- nvim-cmp integration
|
||||
{
|
||||
"nvim-cmp",
|
||||
dependencies = {
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
optional = true,
|
||||
dependencies = { "saadparwaiz1/cmp_luasnip" },
|
||||
opts = function(_, opts)
|
||||
opts.snippet = {
|
||||
expand = function(args)
|
||||
|
@ -25,21 +32,14 @@ return {
|
|||
}
|
||||
table.insert(opts.sources, { name = "luasnip" })
|
||||
end,
|
||||
},
|
||||
},
|
||||
opts = {
|
||||
history = true,
|
||||
delete_check_events = "TextChanged",
|
||||
},
|
||||
},
|
||||
{
|
||||
"nvim-cmp",
|
||||
-- stylua: ignore
|
||||
keys = {
|
||||
{
|
||||
"<tab>",
|
||||
function()
|
||||
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next" or "<tab>"
|
||||
return require("luasnip").jumpable(1) and "<Plug>luasnip-jump-next"
|
||||
or LazyVim.cmp.ai_accept()
|
||||
or "<tab>"
|
||||
end,
|
||||
expr = true, silent = true, mode = "i",
|
||||
},
|
||||
|
@ -51,4 +51,6 @@ return {
|
|||
"garymjr/nvim-snippets",
|
||||
enabled = false,
|
||||
},
|
||||
|
||||
-- TODO: blink.cmp integration
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue