2023-02-17 16:35:40 +00:00
|
|
|
local cmp = require "cmp"
|
|
|
|
local luasnip = require "luasnip"
|
2023-03-07 15:03:52 +00:00
|
|
|
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
2023-01-31 13:42:24 +00:00
|
|
|
|
2023-02-13 12:57:12 +00:00
|
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
2023-01-31 13:42:24 +00:00
|
|
|
|
2023-02-17 16:35:40 +00:00
|
|
|
cmp.setup {
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
|
|
|
["<C-u>"] = cmp.mapping.scroll_docs(-4), -- Up
|
|
|
|
["<C-d>"] = cmp.mapping.scroll_docs(4), -- Down
|
|
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
|
|
["<CR>"] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
},
|
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
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 = {
|
|
|
|
{ name = "nvim_lsp" },
|
2023-03-23 11:05:49 +00:00
|
|
|
{ name = "luasnip" },
|
2023-02-17 16:35:40 +00:00
|
|
|
},
|
|
|
|
}
|
2023-01-31 13:42:24 +00:00
|
|
|
|
|
|
|
-- Set configuration for specific filetype.
|
2023-03-23 11:05:49 +00:00
|
|
|
cmp.setup.filetype("python", {
|
|
|
|
sources = {
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-02-13 12:57:12 +00:00
|
|
|
cmp.setup.filetype("gitcommit", {
|
2023-02-17 16:35:40 +00:00
|
|
|
sources = {
|
2023-03-23 11:05:49 +00:00
|
|
|
{ name = "nvim_lsp" },
|
2023-02-17 16:35:40 +00:00
|
|
|
{ name = "git" },
|
2023-03-16 16:25:51 +00:00
|
|
|
{ name = "spell" },
|
2023-02-17 16:35:40 +00:00
|
|
|
{ name = "commit" },
|
|
|
|
{ name = "buffer" },
|
2023-03-16 16:25:51 +00:00
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "latex_symbols" },
|
2023-02-17 16:35:40 +00:00
|
|
|
},
|
2023-01-31 13:42:24 +00:00
|
|
|
})
|
|
|
|
|
2023-02-13 12:57:12 +00:00
|
|
|
cmp.setup.filetype("markdown", {
|
2023-02-17 16:35:40 +00:00
|
|
|
sources = {
|
2023-03-23 11:05:49 +00:00
|
|
|
{ name = "nvim_lsp" },
|
2023-02-17 16:35:40 +00:00
|
|
|
{ name = "spell" },
|
|
|
|
{ name = "buffer" },
|
2023-03-16 16:25:51 +00:00
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "latex_symbols" },
|
2023-02-17 16:35:40 +00:00
|
|
|
},
|
2023-01-31 13:42:24 +00:00
|
|
|
})
|
|
|
|
|
2023-02-13 12:57:12 +00:00
|
|
|
cmp.setup.cmdline("/", {
|
2023-02-17 16:35:40 +00:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = {
|
2023-03-23 11:05:49 +00:00
|
|
|
{ name = "nvim_lsp" },
|
2023-02-17 16:35:40 +00:00
|
|
|
{ name = "buffer" },
|
|
|
|
},
|
2023-01-31 13:42:24 +00:00
|
|
|
})
|
|
|
|
|
2023-02-13 12:57:12 +00:00
|
|
|
cmp.setup.cmdline(":", {
|
2023-02-17 16:35:40 +00:00
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
|
|
sources = {
|
2023-03-23 11:05:49 +00:00
|
|
|
{ name = "nvim_lsp" },
|
2023-02-17 16:35:40 +00:00
|
|
|
{ name = "path" },
|
|
|
|
{ name = "cmdline" },
|
|
|
|
},
|
2023-01-31 13:42:24 +00:00
|
|
|
})
|
2023-03-07 15:03:52 +00:00
|
|
|
|
|
|
|
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|