feat(nvim): add copilot-cmp
parent
bfbc3ad24f
commit
7078b97ee9
|
@ -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")
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
{
|
||||
|
|
|
@ -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 },
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue