2023-03-09 16:26:45 +08:00
|
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
2022-08-07 21:00:11 +08:00
|
|
|
|
2023-03-09 16:26:45 +08:00
|
|
|
local luasnip = require("luasnip")
|
|
|
|
local cmp = require("cmp")
|
2022-08-07 21:00:11 +08:00
|
|
|
|
2023-11-11 16:53:57 +08:00
|
|
|
|
2023-03-09 16:26:45 +08:00
|
|
|
cmp.setup({
|
|
|
|
-- ... Your other configuration ...
|
|
|
|
snippet = {
|
|
|
|
-- REQUIRED - you must specify a snippet engine
|
|
|
|
expand = function(args)
|
|
|
|
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = {
|
2024-05-06 11:29:00 +08:00
|
|
|
["<C-n>"] = cmp.mapping(function(fallback)
|
2023-03-09 16:26:45 +08:00
|
|
|
if cmp.visible() then
|
2024-05-06 11:29:00 +08:00
|
|
|
cmp.select_next_item()
|
2023-03-09 16:26:45 +08:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
2024-05-06 11:29:00 +08:00
|
|
|
["<C-p>"] = cmp.mapping(function(fallback)
|
2023-03-09 16:26:45 +08:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
2023-10-13 20:04:56 +08:00
|
|
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
['<C-e>'] = cmp.mapping.abort(),
|
2024-05-06 11:29:00 +08:00
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
if luasnip.expandable() then
|
|
|
|
luasnip.expand()
|
|
|
|
else
|
2024-05-09 14:32:32 +08:00
|
|
|
cmp.confirm({ select = true })
|
2024-05-06 11:29:00 +08:00
|
|
|
end
|
|
|
|
elseif luasnip.locally_jumpable(1) then
|
|
|
|
luasnip.jump(1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
2024-05-09 14:32:32 +08:00
|
|
|
end, { "i", "s" }),
|
2024-05-06 11:29:00 +08:00
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if luasnip.locally_jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
2024-05-09 14:32:32 +08:00
|
|
|
end, { "i", "s" }),
|
2023-03-09 16:26:45 +08:00
|
|
|
},
|
|
|
|
sources = cmp.config.sources({
|
2024-05-26 13:38:42 +08:00
|
|
|
{ name = "luasnip" }, -- For luasnip users.
|
2023-03-09 16:26:45 +08:00
|
|
|
{ name = "nvim_lsp" },
|
2023-11-11 16:53:57 +08:00
|
|
|
{ name = 'nvim_lua' },
|
2023-03-09 16:26:45 +08:00
|
|
|
{ name = "treesitter" },
|
2023-10-13 20:04:56 +08:00
|
|
|
{ name = "async_path" },
|
2023-11-28 13:02:36 +08:00
|
|
|
{ name = "gitmoji" },
|
2023-10-13 20:04:56 +08:00
|
|
|
{ name = "buffer" },
|
2023-11-11 16:53:57 +08:00
|
|
|
}),
|
|
|
|
completion = {
|
|
|
|
completeopt = 'menu,menuone,noinsert'
|
|
|
|
}
|
2022-08-07 21:00:11 +08:00
|
|
|
})
|
|
|
|
|
2023-03-09 16:26:45 +08:00
|
|
|
cmp.setup.cmdline({ '/', '?' }, {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
2023-11-11 17:11:57 +08:00
|
|
|
completion = {
|
|
|
|
completeopt = 'menu,menuone,noselect'
|
|
|
|
},
|
2023-03-09 16:26:45 +08:00
|
|
|
sources = {
|
|
|
|
{ name = 'buffer' }
|
2023-11-11 17:11:57 +08:00
|
|
|
},
|
2022-08-07 21:00:11 +08:00
|
|
|
})
|
|
|
|
|
2023-03-09 16:26:45 +08:00
|
|
|
-- `:` cmdline setup.
|
|
|
|
cmp.setup.cmdline(':', {
|
|
|
|
mapping = cmp.mapping.preset.cmdline(),
|
2023-11-11 17:11:57 +08:00
|
|
|
completion = {
|
|
|
|
completeopt = 'menu,menuone,noselect'
|
|
|
|
},
|
2023-03-09 16:26:45 +08:00
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'path' }
|
|
|
|
}, {
|
|
|
|
{
|
|
|
|
name = 'cmdline',
|
|
|
|
option = {
|
2023-11-28 13:02:36 +08:00
|
|
|
ignore_cmds = {}
|
2023-03-09 16:26:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-08-07 21:00:11 +08:00
|
|
|
})
|