mirror of
https://github.com/prurigro/darkcloud-nvimconfig.git
synced 2024-11-25 12:41:26 -05:00
56 lines
1.9 KiB
Lua
56 lines
1.9 KiB
Lua
|
if (vim.g.enablecompletion == 1) then
|
||
|
local snippy = require("snippy")
|
||
|
local cmp = require"cmp"
|
||
|
|
||
|
local has_words_before = function()
|
||
|
unpack = unpack or table.unpack
|
||
|
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
|
||
|
|
||
|
cmp.setup({
|
||
|
snippet = {
|
||
|
expand = function(args)
|
||
|
require "snippy".expand_snippet(args.body)
|
||
|
end
|
||
|
},
|
||
|
window = {
|
||
|
completion = cmp.config.window.bordered(),
|
||
|
documentation = cmp.config.window.bordered(),
|
||
|
},
|
||
|
mapping = cmp.mapping.preset.insert({
|
||
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||
|
if cmp.visible() then
|
||
|
cmp.select_next_item()
|
||
|
elseif snippy.can_expand_or_advance() then
|
||
|
snippy.expand_or_advance()
|
||
|
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 snippy.can_jump(-1) then
|
||
|
snippy.previous()
|
||
|
else
|
||
|
fallback()
|
||
|
end
|
||
|
end, { "i", "s" }),
|
||
|
|
||
|
["<Leader>"] = cmp.mapping.abort(),
|
||
|
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||
|
}),
|
||
|
sources = cmp.config.sources({
|
||
|
{ name = "buffer" },
|
||
|
{ name = "treesitter" },
|
||
|
{ name = "omni" },
|
||
|
{ name = "tags", option = { current_buffer_only = true } },
|
||
|
{ name = "snippy" },
|
||
|
})
|
||
|
})
|
||
|
end
|