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
|
|
|
|
2022-04-29 00:18:25 +02:00
|
|
|
local has_words_before = function()
|
2022-04-27 21:58:12 +02:00
|
|
|
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
|
2021-09-12 02:30:11 +02:00
|
|
|
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 = '' } }))
|
|
|
|
|
2022-05-01 14:43:00 +02:00
|
|
|
-- Custom item icons
|
|
|
|
local icons = {
|
2022-05-01 18:30:12 +02:00
|
|
|
Class = "",
|
|
|
|
Color = "",
|
|
|
|
Constant = "µ",
|
|
|
|
Constructor = "",
|
|
|
|
Enum = "",
|
|
|
|
EnumMember = "",
|
|
|
|
Event = "",
|
|
|
|
Field = "",
|
|
|
|
File = "",
|
|
|
|
Folder = "",
|
|
|
|
Function = "",
|
|
|
|
Keyword = "",
|
|
|
|
Interface = "",
|
|
|
|
Method = "",
|
|
|
|
Module = "",
|
|
|
|
Operator = "",
|
|
|
|
Property = "",
|
|
|
|
Reference = "",
|
|
|
|
Snippet = "",
|
|
|
|
Struct = "",
|
|
|
|
Text = "",
|
|
|
|
TypeParameter = "",
|
|
|
|
Unit = "",
|
|
|
|
Value = "",
|
|
|
|
Variable = "",
|
2022-05-01 14:43:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 02:30:11 +02:00
|
|
|
cmp.setup {
|
2022-04-27 21:58:12 +02:00
|
|
|
completion = {
|
|
|
|
autocomplete = false
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = "path" },
|
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "nvim_lua" },
|
|
|
|
{ name = "calc" },
|
|
|
|
{ name = "spell" },
|
|
|
|
{ name = "treesitter" },
|
|
|
|
},
|
|
|
|
formatting = {
|
|
|
|
format = function(entry, vim_item)
|
2022-05-01 18:30:12 +02:00
|
|
|
vim_item.kind = string.format("%s %s", icons[vim_item.kind],
|
|
|
|
vim_item.kind)
|
2022-04-27 21:58:12 +02:00
|
|
|
vim_item.menu = ({
|
|
|
|
nvim_lsp = "[lsp]",
|
|
|
|
nvim_lua = "[nvim]",
|
|
|
|
luasnip = "[snip]",
|
|
|
|
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)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
2022-04-29 00:18:53 +02:00
|
|
|
elseif luasnip.expand_or_locally_jumpable() then
|
2022-04-27 21:58:12 +02:00
|
|
|
luasnip.expand_or_jump()
|
2022-04-29 00:18:25 +02:00
|
|
|
elseif has_words_before() then
|
2022-04-27 21:58:12 +02:00
|
|
|
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" }),
|
2022-05-01 18:30:12 +02:00
|
|
|
},
|
|
|
|
view = {
|
|
|
|
entries = {name = 'custom', selection_order = 'near_cursor' }
|
|
|
|
},
|
2021-09-12 02:30:11 +02:00
|
|
|
}
|