pojokcodeid.nvim-lazy/lua/plugins/cmp.lua

120 lines
3.5 KiB
Lua
Raw Normal View History

2024-05-21 14:20:50 +07:00
local cmprg = vim.g.pcode_cmprg
local cmpcalc = vim.g.pcode_cmpcalc
local cmptag = vim.g.pcode_cmptag
local lspghost_text = vim.g.pcode_lspghost_text
local icons = vim.g.pcode_icons.ui
2023-02-22 07:55:38 +07:00
return {
2024-03-09 08:06:10 +07:00
{ "hrsh7th/cmp-nvim-lsp", event = "InsertEnter", lazy = true },
{ "hrsh7th/cmp-buffer", event = "InsertEnter", lazy = true },
{ "hrsh7th/cmp-path", event = "InsertEnter", lazy = true },
{ "saadparwaiz1/cmp_luasnip", event = "InsertEnter", lazy = true },
{ "hrsh7th/cmp-nvim-lua", event = "InsertEnter", lazy = true },
{ "lukas-reineke/cmp-rg", lazy = true, enabled = cmprg }, -- experimental
{ "hrsh7th/cmp-calc", lazy = true, enabled = cmpcalc }, -- experimental
{ "quangnguyen30192/cmp-nvim-tags", lazy = true, enabled = cmptag }, -- experimental
2023-03-08 13:52:16 +07:00
{
"hrsh7th/nvim-cmp",
2024-03-09 08:06:10 +07:00
lazy = true,
2023-03-08 13:52:16 +07:00
version = false, -- last release is way too old
event = "InsertEnter",
opts = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
2023-02-22 07:55:38 +07:00
2023-03-08 13:52:16 +07:00
local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
2023-02-22 07:55:38 +07:00
2023-03-08 13:52:16 +07:00
return {
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
2023-03-13 22:55:09 +07:00
["<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",
}),
2023-03-08 13:52:16 +07:00
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = "nvim_lua" },
{ name = "rg" }, -- experimental
{ name = "calc" }, -- experimental
{ name = "tags" }, --experimental
2023-02-22 07:55:38 +07:00
}),
2023-03-08 13:52:16 +07:00
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
2024-05-21 14:20:50 +07:00
vim_item.kind = string.format("%s", vim.g.pcode_icons["kind"][vim_item.kind])
2023-03-08 13:52:16 +07:00
vim_item.menu = ({
nvim_lsp = "(LSP)",
luasnip = "(Snippet)",
buffer = "(Buffer)",
path = "(Path)",
})[entry.source.name]
return vim_item
end,
},
window = {
2024-03-10 20:32:59 +07:00
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
-- remove border window from cmp
completion = {
2024-04-14 23:40:59 +07:00
border = icons.Border,
2024-03-15 23:10:04 +07:00
winhighlight = "Normal:bg,FloatBorder:BorderBG,CursorLine:PmenuSel,Search:None",
2024-03-11 12:29:09 +07:00
scrollbar = true,
2024-03-10 20:32:59 +07:00
},
documentation = {
2024-04-14 23:40:59 +07:00
border = icons.Border,
2024-03-15 23:10:04 +07:00
winhighlight = "Normal:bg,FloatBorder:BorderBG,CursorLine:PmenuSel,Search:None",
2024-03-11 12:29:09 +07:00
scrollbar = true,
2024-03-10 20:32:59 +07:00
},
2023-03-08 13:52:16 +07:00
},
experimental = {
ghost_text = lspghost_text,
native_menu = false,
},
}
end,
},
2023-02-22 07:55:38 +07:00
}