neovim: copilot in cmp

This commit is contained in:
2026-02-13 16:57:11 +01:00
parent 4637065e94
commit a39f1f7967
2 changed files with 55 additions and 31 deletions

View File

@@ -14,7 +14,19 @@ neovim.override {
configure = {
vimAlias = true;
viAlias = true;
customRC = ''
customRC =
lib.optionalString withCopilot (''
luafile ${writeText "copilot.lua" ''
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false }
})
require("copilot_cmp").setup()
''}
'')
+ ''
source ${./shared.vim}
source ${./init.vim}
let g:snippet_directory = '${vimPlugins.friendly-snippets}'
@@ -81,7 +93,10 @@ neovim.override {
}
)
]
++ lib.optional withCopilot vimPlugins.copilot-vim;
++ lib.optionals withCopilot [
vimPlugins.copilot-lua
vimPlugins.copilot-cmp
];
opt = [
csv
dhall-vim

View File

@@ -19,17 +19,23 @@ cmp.setup({
luasnip.lsp_expand(args.body)
end,
},
completion = {
autocomplete = { require("cmp.types").cmp.TriggerEvent.TextChanged },
},
mapping = {
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#super-tab-like-mapping
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
cmp.complete()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
@@ -41,8 +47,11 @@ cmp.setup({
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "copilot", priority = 1000 },
{ name = "nvim_lsp", priority = 800 },
{ name = "luasnip", priority = 700 },
{ name = "path", priority = 500 },
{ name = "buffer", priority = 300 },
}),
})