feat(nvim): add copilot-cmp

This commit is contained in:
Moritz Böhme 2023-09-17 09:36:22 +02:00
parent bfbc3ad24f
commit 7078b97ee9
Signed by: moritz
GPG key ID: 970C6E89EB0547A9
2 changed files with 31 additions and 3 deletions

View file

@ -89,6 +89,23 @@ with builtins;
{ plugin = friendly-snippets; } { plugin = friendly-snippets; }
{ plugin = lspkind-nvim; } { plugin = lspkind-nvim; }
{ plugin = luasnip; } { plugin = luasnip; }
{
plugin = copilot-cmp;
opts = { };
dependencies = [
{
plugin = copilot-lua;
opts = {
suggestion = { enabled = false; };
panel = { enabled = false; };
};
conf = /* lua */ ''
require("copilot").setup(opts)
vim.cmd("Copilot disable")
'';
}
];
}
]; ];
} }
{ {

View file

@ -2,13 +2,23 @@ local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
end
cmp.setup({ cmp.setup({
formatting = { formatting = {
format = require("lspkind").cmp_format({ format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations mode = "symbol", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters maxwidth = 50, -- prevent the popup from showing more than provided characters
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
symbol_map = {}, symbol_map = {
Copilot = "",
},
}), }),
}, },
snippet = { snippet = {
@ -24,8 +34,8 @@ cmp.setup({
["<C-e>"] = cmp.mapping.abort(), ["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), ["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() and has_words_before() then
cmp.select_next_item() cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
else else
@ -46,6 +56,7 @@ cmp.setup({
{ name = "async_path", priority = 1 }, { name = "async_path", priority = 1 },
{ name = "buffer", priority = 1 }, { name = "buffer", priority = 1 },
{ name = "luasnip", priority = 2 }, { name = "luasnip", priority = 2 },
{ name = "copilot", group_index = 3 },
{ name = "nvim_lsp", priority = 4 }, { name = "nvim_lsp", priority = 4 },
}, },
}) })