2021-09-12 02:30:11 +02:00
|
|
|
-- Author : swytch
|
|
|
|
-- Created : Saturday Sept. 11, 2021 22:12:33 CET
|
|
|
|
-- License : GPLv3
|
|
|
|
-- Description : cmp plugin config file
|
|
|
|
|
|
|
|
local cmp = require("cmp")
|
|
|
|
local luasnip = require("luasnip")
|
2021-10-30 15:29:14 +02:00
|
|
|
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
2021-09-12 02:30:11 +02:00
|
|
|
|
|
|
|
local check_backspace = function()
|
|
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
|
|
return col ~= 0 and
|
|
|
|
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:
|
|
|
|
sub(col, col):match('%s') == nil
|
|
|
|
end
|
|
|
|
|
2021-10-30 15:29:14 +02:00
|
|
|
-- If you want insert `(` after select function or method item
|
|
|
|
cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } }))
|
|
|
|
|
2021-09-12 02:30:11 +02:00
|
|
|
cmp.setup {
|
|
|
|
completion = {
|
|
|
|
autocomplete = false
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = "path" },
|
2021-11-20 16:02:59 +01:00
|
|
|
{ name = "luasnip" },
|
2021-09-12 02:30:11 +02:00
|
|
|
{ name = "nvim_lsp" },
|
2021-11-20 16:02:59 +01:00
|
|
|
{ name = "buffer" },
|
2021-09-12 02:30:11 +02:00
|
|
|
{ name = "nvim_lua" },
|
|
|
|
{ name = "calc" },
|
|
|
|
{ name = "spell" },
|
2021-11-20 16:02:59 +01:00
|
|
|
{ name = "treesitter" },
|
2021-09-12 02:30:11 +02:00
|
|
|
},
|
|
|
|
formatting = {
|
|
|
|
format = function(entry, vim_item)
|
|
|
|
vim_item.menu = ({
|
|
|
|
nvim_lsp = "[lsp]",
|
|
|
|
nvim_lua = "[nvim]",
|
2021-11-20 16:02:59 +01:00
|
|
|
luasnip = "[snip]",
|
2021-09-12 02:30:11 +02:00
|
|
|
path = "[path]",
|
|
|
|
buffer = "[buff]",
|
|
|
|
calc = "[calc]",
|
|
|
|
spell = "[spel]",
|
|
|
|
treesitter = "[tree]",
|
|
|
|
})[entry.source.name]
|
|
|
|
return vim_item
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require("luasnip").lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = {
|
|
|
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
|
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
|
|
["<C-e>"] = cmp.mapping.close(),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
}),
|
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
2021-10-12 14:00:47 +02:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
2021-09-12 02:30:11 +02:00
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
elseif check_backspace() then
|
|
|
|
cmp.complete()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
2021-10-12 14:00:47 +02:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
2021-09-12 02:30:11 +02:00
|
|
|
elseif luasnip.jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
}
|
|
|
|
}
|