mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-12 02:14:37 +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" })
|
table.insert(opts.sources, { name = "snippets" })
|
||||||
end
|
end
|
||||||
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()
|
init = function()
|
||||||
-- Neovim enabled snippet navigation mappings by default in v0.11
|
-- Neovim enabled snippet navigation mappings by default in v0.11
|
||||||
if vim.fn.has("nvim-0.11") == 0 then
|
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>"
|
return vim.snippet.active({ direction = 1 }) and "<cmd>lua vim.snippet.jump(1)<cr>" or "<Tab>"
|
||||||
end, { expr = true, silent = true })
|
end, { expr = true, silent = true })
|
||||||
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
|
vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
|
||||||
|
|
|
@ -9,24 +9,34 @@ return {
|
||||||
enable_cmp_source = vim.g.ai_cmp,
|
enable_cmp_source = vim.g.ai_cmp,
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
enabled = not vim.g.ai_cmp,
|
enabled = not vim.g.ai_cmp,
|
||||||
accept_fallback = vim.g.ai_suggest_accept,
|
accept_fallback = "<tab>",
|
||||||
key_bindings = {
|
key_bindings = {
|
||||||
accept = vim.g.ai_suggest_accept,
|
accept = "<tab>",
|
||||||
accept_word = vim.g.ai_suggest_accept_word,
|
next = "<M-]>",
|
||||||
accept_line = vim.g.ai_suggest_accept_line,
|
prev = "<M-[>",
|
||||||
next = vim.g.ai_suggest_next,
|
|
||||||
prev = vim.g.ai_suggest_prev,
|
|
||||||
clear = vim.g.ai_suggest_clear,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
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
|
-- codeium cmp source
|
||||||
{
|
{
|
||||||
"nvim-cmp",
|
"nvim-cmp",
|
||||||
optional = true,
|
optional = true,
|
||||||
dependencies = { "codeium.nvim" },
|
dependencies = { "codeium.nvim" },
|
||||||
---@param opts cmp.ConfigSchema
|
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
table.insert(opts.sources, 1, {
|
table.insert(opts.sources, 1, {
|
||||||
name = "codeium",
|
name = "codeium",
|
||||||
|
|
|
@ -8,15 +8,12 @@ return {
|
||||||
event = "InsertEnter",
|
event = "InsertEnter",
|
||||||
opts = {
|
opts = {
|
||||||
suggestion = {
|
suggestion = {
|
||||||
enabled = true,
|
enabled = not vim.g.ai_cmp,
|
||||||
auto_trigger = true,
|
auto_trigger = true,
|
||||||
keymap = {
|
keymap = {
|
||||||
accept = vim.g.ai_suggest_accept,
|
accept = "<tab>",
|
||||||
accept_word = vim.g.ai_suggest_accept_word,
|
next = "<M-]>",
|
||||||
accept_line = vim.g.ai_suggest_accept_line,
|
prev = "<M-[>",
|
||||||
next = vim.g.ai_suggest_next,
|
|
||||||
prev = vim.g.ai_suggest_prev,
|
|
||||||
dismiss = vim.g.ai_suggest_clear,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
panel = { enabled = false },
|
panel = { enabled = false },
|
||||||
|
@ -25,7 +22,24 @@ return {
|
||||||
help = true,
|
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",
|
"nvim-lualine/lualine.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
|
@ -72,22 +86,17 @@ return {
|
||||||
{
|
{
|
||||||
"zbirenbaum/copilot-cmp",
|
"zbirenbaum/copilot-cmp",
|
||||||
enabled = vim.g.ai_cmp, -- only enable if wanted
|
enabled = vim.g.ai_cmp, -- only enable if wanted
|
||||||
dependencies = "copilot.lua",
|
|
||||||
opts = {},
|
opts = {},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local copilot_cmp = require("copilot_cmp")
|
local copilot_cmp = require("copilot_cmp")
|
||||||
copilot_cmp.setup(opts)
|
copilot_cmp.setup(opts)
|
||||||
-- attach cmp source whenever copilot attaches
|
-- attach cmp source whenever copilot attaches
|
||||||
-- fixes lazy-loading issues with the copilot cmp source
|
-- 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({})
|
copilot_cmp._on_insert_enter({})
|
||||||
end, "copilot")
|
end, "copilot")
|
||||||
end,
|
end,
|
||||||
specs = {
|
specs = {
|
||||||
{
|
|
||||||
"zbirenbaum/copilot.lua",
|
|
||||||
opts = { suggestion = { enabled = false } },
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"nvim-cmp",
|
"nvim-cmp",
|
||||||
---@param opts cmp.ConfigSchema
|
---@param opts cmp.ConfigSchema
|
||||||
|
@ -104,31 +113,18 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- blink.cmp
|
||||||
{
|
{
|
||||||
"saghen/blink.cmp",
|
"saghen/blink.cmp",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = {
|
||||||
windows = {
|
windows = { ghost_text = { enabled = false } },
|
||||||
ghost_text = {
|
},
|
||||||
enabled = false,
|
specs = {
|
||||||
},
|
-- blink has no copilot source, so force enable suggestions
|
||||||
},
|
{
|
||||||
keymap = {
|
"zbirenbaum/copilot.lua",
|
||||||
[vim.g.ai_suggest_accept] = {
|
opts = { suggestion = { enabled = true } },
|
||||||
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",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,7 +38,7 @@ return {
|
||||||
auto_show = true,
|
auto_show = true,
|
||||||
},
|
},
|
||||||
ghost_text = {
|
ghost_text = {
|
||||||
enabled = true,
|
enabled = vim.g.ai_cmp,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -59,6 +59,13 @@ return {
|
||||||
|
|
||||||
keymap = {
|
keymap = {
|
||||||
preset = "enter",
|
preset = "enter",
|
||||||
|
["<tab>"] = {
|
||||||
|
"snippet_forward",
|
||||||
|
function()
|
||||||
|
return LazyVim.cmp.ai_accept()
|
||||||
|
end,
|
||||||
|
"fallback",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@param opts blink.cmp.Config
|
---@param opts blink.cmp.Config
|
||||||
|
|
|
@ -12,34 +12,34 @@ return {
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
end,
|
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 = {
|
opts = {
|
||||||
history = true,
|
history = true,
|
||||||
delete_check_events = "TextChanged",
|
delete_check_events = "TextChanged",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- nvim-cmp integration
|
||||||
{
|
{
|
||||||
"nvim-cmp",
|
"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
|
-- stylua: ignore
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<tab>",
|
"<tab>",
|
||||||
function()
|
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,
|
end,
|
||||||
expr = true, silent = true, mode = "i",
|
expr = true, silent = true, mode = "i",
|
||||||
},
|
},
|
||||||
|
@ -51,4 +51,6 @@ return {
|
||||||
"garymjr/nvim-snippets",
|
"garymjr/nvim-snippets",
|
||||||
enabled = false,
|
enabled = false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- TODO: blink.cmp integration
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
---@class lazyvim.util.cmp
|
---@class lazyvim.util.cmp
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@return string?
|
||||||
|
function M.ai_accept() end
|
||||||
|
|
||||||
---@alias Placeholder {n:number, text:string}
|
---@alias Placeholder {n:number, text:string}
|
||||||
|
|
||||||
---@param snippet string
|
---@param snippet string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue