nvim: copilot.lua as cmp source

This commit is contained in:
Daniel Lundin 2022-12-03 17:21:07 +01:00
parent fe346c2d10
commit 481f545b90
3 changed files with 60 additions and 32 deletions

View file

@ -260,9 +260,20 @@ return require("packer").startup(function()
-- copilot
use({
"github/copilot.vim",
"zbirenbaum/copilot.lua",
event = "VimEnter",
config = function()
require("plugins/copilot")
vim.defer_fn(function()
require("plugins/copilot")
end, 100)
end,
})
use({
"zbirenbaum/copilot-cmp",
after = { "copilot.lua" },
config = function()
require("copilot_cmp").setup()
end,
})
end)

View file

@ -1,15 +1,39 @@
local map = function(type, key, value, opts)
local options = { noremap = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(type, key, value, options)
end
local copilot = require("copilot")
map("i", "<C-J>", [[copilot#Accept("<CR>")]], { noremap = true, silent = true, expr = true })
vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true
vim.g.copilot_tab_fallback = ""
vim.g.copilot_no_tab_map = true
copilot.setup({
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>",
},
},
suggestion = {
enabled = true,
auto_trigger = false,
debounce = 75,
keymap = {
accept = "<C-j>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
},
filetypes = {
yaml = false,
markdown = false,
help = false,
gitcommit = false,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
copilot_node_command = "node", -- Node version must be < 18
server_opts_overrides = {},
})

View file

@ -43,6 +43,10 @@ cmp.setup({
["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-u>"] = cmp.mapping.scroll_docs(4),
["<Escape>"] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
["<C-e>"] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
@ -73,14 +77,9 @@ cmp.setup({
},
sources = cmp.config.sources({
{
name = "buffer",
priority = 1,
},
{
name = "luasnip",
priority = 4,
},
{ name = "buffer", priority = 1 },
{ name = "luasnip", priority = 4 },
{ name = "copilot", group_index = 5 },
{
name = "tmux",
priority = 2,
@ -89,13 +88,7 @@ cmp.setup({
trigger_characters = {},
},
},
{
name = "nvim_lsp",
priority = 3,
},
{
name = "nvim_lsp_signature_help",
priority = 4,
},
{ name = "nvim_lsp", priority = 3 },
{ name = "nvim_lsp_signature_help", priority = 4 },
}),
})