2023-06-19 09:54:39 +00:00
|
|
|
return {
|
2024-03-15 14:10:00 +00:00
|
|
|
{
|
|
|
|
"hrsh7th/nvim-cmp",
|
|
|
|
-- load cmp on InsertEnter
|
|
|
|
event = "InsertEnter",
|
|
|
|
-- these dependencies will only be loaded when cmp loads
|
|
|
|
-- dependencies are always lazy-loaded unless specified otherwise
|
|
|
|
dependencies = {
|
|
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
|
|
"hrsh7th/cmp-buffer",
|
2025-02-26 10:22:27 +00:00
|
|
|
"hrsh7th/cmp-path",
|
|
|
|
"hrsh7th/cmp-cmdline",
|
2024-03-15 14:10:00 +00:00
|
|
|
-- 'hrsh7th/cmp-vsnip',
|
|
|
|
-- 'hrsh7th/vim-vsnip',
|
|
|
|
-- 'hrsh7th/vim-vsnip-integ',
|
2025-02-26 10:22:27 +00:00
|
|
|
"L3MON4D3/LuaSnip",
|
|
|
|
"saadparwaiz1/cmp_luasnip",
|
|
|
|
"onsails/lspkind.nvim",
|
2024-03-15 14:10:00 +00:00
|
|
|
{
|
2025-02-26 10:22:27 +00:00
|
|
|
"zbirenbaum/copilot-cmp",
|
|
|
|
dependencies = {
|
|
|
|
"hrsh7th/nvim-cmp",
|
2024-03-15 14:10:00 +00:00
|
|
|
{
|
2025-02-26 10:22:27 +00:00
|
|
|
"zbirenbaum/copilot.lua",
|
2024-03-15 14:10:00 +00:00
|
|
|
opts = {
|
|
|
|
suggestion = { enabled = false },
|
|
|
|
panel = { enabled = false },
|
|
|
|
filetypes = {
|
|
|
|
mail = false,
|
|
|
|
text = false,
|
2025-02-26 10:22:27 +00:00
|
|
|
},
|
|
|
|
},
|
2024-03-15 14:10:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
config = function()
|
|
|
|
require("copilot_cmp").setup()
|
2025-02-26 10:22:27 +00:00
|
|
|
end,
|
2024-03-15 14:10:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
config = function()
|
2025-02-26 10:22:27 +00:00
|
|
|
local cmp = require("cmp")
|
|
|
|
local lspkind = require("lspkind")
|
|
|
|
local luasnip = require("luasnip")
|
2024-03-15 14:10:00 +00:00
|
|
|
local has_words_before = function()
|
|
|
|
unpack = unpack or table.unpack
|
|
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
2025-02-26 10:22:27 +00:00
|
|
|
return col ~= 0
|
|
|
|
and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
2024-03-15 14:10:00 +00:00
|
|
|
end
|
2023-06-19 09:54:39 +00:00
|
|
|
|
2024-03-15 14:10:00 +00:00
|
|
|
cmp.setup({
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
--vim.fn["vsnip#anonymous"](args.body)
|
2025-02-26 10:22:27 +00:00
|
|
|
require("luasnip").lsp_expand(args.body)
|
2024-03-15 14:10:00 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = {
|
2025-02-26 10:22:27 +00:00
|
|
|
["<C-y>"] = cmp.mapping.confirm({ select = true }),
|
|
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<C-e>"] = cmp.mapping.abort(),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({
|
2024-03-15 14:10:00 +00:00
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
}),
|
2025-02-26 10:22:27 +00:00
|
|
|
["<C-CR>"] = cmp.mapping({
|
2024-03-15 14:10:00 +00:00
|
|
|
i = function(fallback)
|
|
|
|
if cmp.visible() and cmp.get_active_entry() then
|
|
|
|
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
s = cmp.mapping.confirm({ select = true }),
|
|
|
|
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
|
|
|
|
}),
|
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
|
|
|
-- they way you will only jump inside the snippet region
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
elseif has_words_before() then
|
|
|
|
cmp.complete()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif luasnip.jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
},
|
|
|
|
sources = cmp.config.sources({
|
2025-02-26 10:22:27 +00:00
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "luasnip" },
|
2024-03-15 14:10:00 +00:00
|
|
|
{ name = "copilot" },
|
|
|
|
}, {
|
2025-02-26 10:22:27 +00:00
|
|
|
{ name = "buffer", option = { keyword_pattern = [[\k\+]] } },
|
2024-03-15 14:10:00 +00:00
|
|
|
--{ name = 'path' },
|
|
|
|
}),
|
|
|
|
formatting = {
|
|
|
|
format = lspkind.cmp_format({
|
2025-02-26 10:22:27 +00:00
|
|
|
mode = "symbol_text", -- show only symbol annotations
|
2024-03-15 14:10:00 +00:00
|
|
|
maxwidth = 80, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
|
2025-02-26 10:22:27 +00:00
|
|
|
ellipsis_char = "…", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
|
2024-03-15 14:10:00 +00:00
|
|
|
symbol_map = { Copilot = "" },
|
2025-02-26 10:22:27 +00:00
|
|
|
}),
|
2024-03-15 14:10:00 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
2023-06-19 09:54:39 +00:00
|
|
|
}
|