129 lines
3.7 KiB
Lua
129 lines
3.7 KiB
Lua
local cmp = require("cmp")
|
|
-- require("ui").load_highlight "cmp"
|
|
|
|
vim.o.completeopt = "menu,menuone,noselect"
|
|
|
|
local function border(hl_name)
|
|
return {
|
|
{ "╭", hl_name },
|
|
{ "─", hl_name },
|
|
{ "╮", hl_name },
|
|
{ "│", hl_name },
|
|
{ "╯", hl_name },
|
|
{ "─", hl_name },
|
|
{ "╰", hl_name },
|
|
{ "│", hl_name },
|
|
}
|
|
end
|
|
|
|
local options = {
|
|
window = {
|
|
completion = {
|
|
border = border "CmpBorder",
|
|
winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None",
|
|
scrollbar = false,
|
|
},
|
|
documentation = {
|
|
border = border "CmpDocBorder",
|
|
},
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
require("luasnip").lsp_expand(args.body)
|
|
end,
|
|
},
|
|
|
|
formatting = {
|
|
format = function(_, vim_item)
|
|
local icons = {
|
|
Namespace = "",
|
|
Text = " ",
|
|
Method = " ",
|
|
Function = " ",
|
|
Constructor = " ",
|
|
Field = "ﰠ ",
|
|
Variable = " ",
|
|
Class = "ﴯ ",
|
|
Interface = " ",
|
|
Module = " ",
|
|
Property = "ﰠ ",
|
|
Unit = "塞 ",
|
|
Value = " ",
|
|
Enum = " ",
|
|
Keyword = " ",
|
|
Snippet = " ",
|
|
Color = " ",
|
|
File = " ",
|
|
Reference = " ",
|
|
Folder = " ",
|
|
EnumMember = " ",
|
|
Constant = " ",
|
|
Struct = "פּ ",
|
|
Event = " ",
|
|
Operator = " ",
|
|
TypeParameter = " ",
|
|
Table = "",
|
|
Object = " ",
|
|
Tag = "",
|
|
Array = "[]",
|
|
Boolean = " ",
|
|
Number = " ",
|
|
Null = "ﳠ",
|
|
String = " ",
|
|
Calendar = "",
|
|
Watch = " ",
|
|
Package = "",
|
|
}
|
|
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
|
|
return vim_item
|
|
end,
|
|
},
|
|
|
|
mapping = {
|
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
["<C-e>"] = cmp.mapping.close(),
|
|
["<CR>"] = cmp.mapping.confirm {
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = false,
|
|
},
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item({behavior = ' elect'})
|
|
elseif require("luasnip").expand_or_jumpable() then
|
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
|
|
else
|
|
fallback()
|
|
end
|
|
end, {
|
|
"i",
|
|
"s",
|
|
}),
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
elseif require("luasnip").jumpable(-1) then
|
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
|
|
else
|
|
fallback()
|
|
end
|
|
end, {
|
|
"i",
|
|
"s",
|
|
}),
|
|
},
|
|
sources = {
|
|
{ name = "luasnip" },
|
|
{ name = "nvim_lsp" },
|
|
{ name = "buffer" },
|
|
{ name = "nvim_lua" },
|
|
{ name = "path" },
|
|
{ name = "crates" },
|
|
},
|
|
}
|
|
|
|
cmp.setup(options)
|