feat(nvim): add copilot-cmp

dev-docs
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 = lspkind-nvim; }
{ 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")
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({
formatting = {
format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations
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
symbol_map = {},
symbol_map = {
Copilot = "",
},
}),
},
snippet = {
@ -24,8 +34,8 @@ cmp.setup({
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
@ -46,6 +56,7 @@ cmp.setup({
{ name = "async_path", priority = 1 },
{ name = "buffer", priority = 1 },
{ name = "luasnip", priority = 2 },
{ name = "copilot", group_index = 3 },
{ name = "nvim_lsp", priority = 4 },
},
})