99 lines
2.4 KiB
Lua
99 lines
2.4 KiB
Lua
|
local cmp = require "cmp"
|
||
|
local luasnip = require "luasnip"
|
||
|
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
|
||
|
|
||
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||
|
|
||
|
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" },
|
||
|
{ name = "luasnip" },
|
||
|
},
|
||
|
}
|
||
|
|
||
|
-- Set configuration for specific filetype.
|
||
|
cmp.setup.filetype("python", {
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.setup.filetype("nix", {
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.setup.filetype("gitcommit", {
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
{ name = "git" },
|
||
|
{ name = "spell" },
|
||
|
{ name = "commit" },
|
||
|
{ name = "buffer" },
|
||
|
{ name = "luasnip" },
|
||
|
{ name = "latex_symbols" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.setup.filetype("markdown", {
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
{ name = "spell" },
|
||
|
{ name = "buffer" },
|
||
|
{ name = "luasnip" },
|
||
|
{ name = "latex_symbols" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.setup.cmdline("/", {
|
||
|
mapping = cmp.mapping.preset.cmdline(),
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
{ name = "buffer" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.setup.cmdline(":", {
|
||
|
mapping = cmp.mapping.preset.cmdline(),
|
||
|
sources = {
|
||
|
{ name = "nvim_lsp" },
|
||
|
{ name = "path" },
|
||
|
{ name = "cmdline" },
|
||
|
},
|
||
|
})
|
||
|
|
||
|
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|