2021-09-30 17:58:22 +00:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.config_cmp()
|
|
|
|
local cmp = require("cmp")
|
2022-01-02 15:42:18 +00:00
|
|
|
local luasnip = require("luasnip")
|
2021-12-15 17:37:51 +00:00
|
|
|
cmp.setup({
|
2021-09-30 17:58:22 +00:00
|
|
|
completion = {
|
2022-02-25 17:10:12 +00:00
|
|
|
completeopt = "menuone,noinsert",
|
2021-09-30 17:58:22 +00:00
|
|
|
autocomplete = false,
|
|
|
|
},
|
2022-01-03 06:43:24 +00:00
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require("luasnip").lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
2021-09-30 17:58:22 +00:00
|
|
|
sources = {
|
2021-12-15 17:37:51 +00:00
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "spell" },
|
2024-11-22 19:40:48 +00:00
|
|
|
-- TODO: Refactor to use the lazy opt expansion feature
|
2023-10-20 23:59:19 +00:00
|
|
|
{ name = "obsidian" },
|
|
|
|
{ name = "obsidian_new" },
|
2024-11-22 19:40:48 +00:00
|
|
|
{ name = "lazydev" },
|
2021-08-25 23:21:50 +00:00
|
|
|
},
|
2022-04-21 20:03:22 +00:00
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
-- Scroll docs with readline back - forward
|
2024-06-12 19:36:30 +00:00
|
|
|
["<C-U>"] = cmp.mapping.scroll_docs(-4),
|
|
|
|
["<C-D>"] = cmp.mapping.scroll_docs(4),
|
2022-04-21 20:03:22 +00:00
|
|
|
-- Expand snippets with Tab
|
2022-01-02 15:42:18 +00:00
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end),
|
2022-04-21 20:03:22 +00:00
|
|
|
-- Start and cycle completions with C-Space
|
2021-12-15 17:37:51 +00:00
|
|
|
["<C-Space>"] = cmp.mapping(function()
|
2021-12-11 00:54:29 +00:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
cmp.complete()
|
|
|
|
end
|
2022-04-21 20:03:22 +00:00
|
|
|
end),
|
|
|
|
-- Confirm completion with Enter
|
2021-12-15 17:37:51 +00:00
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
2022-04-21 20:03:22 +00:00
|
|
|
}),
|
2021-12-15 17:37:51 +00:00
|
|
|
})
|
2021-09-30 17:58:22 +00:00
|
|
|
|
|
|
|
-- Add a plug mapping to use in C-Space binding
|
2023-10-20 23:59:19 +00:00
|
|
|
local utils = require("utils")
|
2024-05-29 20:16:28 +00:00
|
|
|
utils.keymap_set("i", "<Plug>(cmp_complete)", function()
|
|
|
|
require("cmp").complete()
|
|
|
|
end, { desc = "Autocomplete" })
|
2021-08-25 23:21:50 +00:00
|
|
|
end
|
|
|
|
|
2021-09-30 17:58:22 +00:00
|
|
|
return M
|