2024-02-15 11:13:37 +00:00
|
|
|
return function()
|
2024-03-05 06:54:50 +00:00
|
|
|
local cmp = require "cmp"
|
2024-02-15 11:13:37 +00:00
|
|
|
|
2024-03-05 06:54:50 +00:00
|
|
|
cmp.setup {
|
|
|
|
snippet = {
|
|
|
|
-- Select the luasnip engine here. You can switch to another engine.
|
|
|
|
expand = function(args)
|
|
|
|
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
|
|
|
require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
|
|
|
|
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
|
|
|
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
window = {
|
|
|
|
completion = cmp.config.window.bordered {
|
|
|
|
border = "rounded",
|
|
|
|
winhighlight = "",
|
|
|
|
minwidth = 60,
|
|
|
|
},
|
|
|
|
documentation = cmp.config.window.bordered {
|
|
|
|
border = "rounded",
|
|
|
|
winhighlight = "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formatting = {
|
|
|
|
format = require("lspkind").cmp_format {
|
|
|
|
mode = "symbol_text",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
|
|
|
["<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 { select = true }, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
|
|
["<Tab>"] = function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
}, {
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "path" },
|
|
|
|
}),
|
|
|
|
}
|
2024-02-15 11:13:37 +00:00
|
|
|
|
2024-03-05 06:54:50 +00:00
|
|
|
-- `/` cmdline setup.
|
|
|
|
cmp.setup.cmdline("/", {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = {
|
|
|
|
{ name = "buffer" },
|
|
|
|
},
|
|
|
|
})
|
2024-02-15 11:13:37 +00:00
|
|
|
|
2024-03-05 06:54:50 +00:00
|
|
|
-- `:` cmdline setup.
|
|
|
|
cmp.setup.cmdline(":", {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = "path" },
|
|
|
|
}, {
|
|
|
|
{
|
|
|
|
name = "cmdline",
|
|
|
|
option = {
|
|
|
|
ignore_cmds = { "Man", "!" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
})
|
2024-02-15 11:13:37 +00:00
|
|
|
|
2024-03-05 06:54:50 +00:00
|
|
|
-- If you want insert `(` after select function or method item
|
|
|
|
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
|
|
|
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
2024-02-15 11:13:37 +00:00
|
|
|
end
|