2022-06-20 13:49:53 +00:00
|
|
|
local has_words_before = function()
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2022-06-29 06:41:32 +00:00
|
|
|
local cmp = require("cmp")
|
2022-06-20 13:49:53 +00:00
|
|
|
local luasnip = require("luasnip")
|
|
|
|
|
|
|
|
cmp.setup({
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
2022-06-22 20:09:56 +00:00
|
|
|
luasnip.lsp_expand(args.body)
|
2022-06-20 13:49:53 +00:00
|
|
|
end
|
|
|
|
},
|
2022-06-29 06:41:32 +00:00
|
|
|
sources = cmp.config.sources({
|
2022-06-22 20:09:56 +00:00
|
|
|
{ name = "nvim_lsp" },
|
2022-07-21 13:51:18 +00:00
|
|
|
{ name = "nvim_lsp_signature_help" },
|
2022-06-22 20:09:56 +00:00
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "path" },
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "nvim-lua" },
|
|
|
|
{ name = "calc" },
|
2022-06-20 13:49:53 +00:00
|
|
|
}),
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
2022-06-29 06:41:32 +00: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(),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
2022-06-20 13:49:53 +00:00
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
elseif has_words_before() then
|
|
|
|
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" }),
|
|
|
|
}),
|
|
|
|
experimental = { ghost_text = true }
|
|
|
|
})
|
|
|
|
|
|
|
|
-- `/` cmdline setup.
|
2022-06-29 06:41:32 +00:00
|
|
|
cmp.setup.cmdline("/", {
|
|
|
|
sources = cmp.config.sources(
|
2022-07-04 06:52:35 +00:00
|
|
|
{ name = "buffer" }
|
2022-06-29 06:41:32 +00:00
|
|
|
)
|
|
|
|
})
|
2022-06-20 13:49:53 +00:00
|
|
|
|
|
|
|
-- `:` cmdline setup.
|
2022-06-29 06:41:32 +00:00
|
|
|
cmp.setup.cmdline(":", {
|
|
|
|
sources = cmp.config.sources(
|
2022-07-04 06:52:35 +00:00
|
|
|
{ name = "path" },
|
|
|
|
{ name = "cmdline" }
|
2022-06-29 06:41:32 +00:00
|
|
|
)
|
2022-06-20 13:49:53 +00:00
|
|
|
})
|