2021-07-04 16:22:16 +02:00
|
|
|
--if not package.loaded['compe'] then
|
|
|
|
-- return
|
|
|
|
-- end
|
2021-07-04 16:07:11 +02:00
|
|
|
|
2021-06-28 04:11:33 +02:00
|
|
|
local M = {}
|
2021-03-15 16:54:53 +01:00
|
|
|
|
2021-07-04 17:42:42 +02:00
|
|
|
vim.g.vsnip_snippet_dir = O.vnsip_dir
|
|
|
|
|
2021-06-28 04:11:33 +02:00
|
|
|
M.config = function()
|
2021-07-05 03:14:01 +02:00
|
|
|
opt = {
|
2021-03-27 06:59:28 +01:00
|
|
|
enabled = O.auto_complete,
|
2021-03-20 07:32:49 +01:00
|
|
|
autocomplete = true,
|
|
|
|
debug = false,
|
|
|
|
min_length = 1,
|
2021-07-05 03:14:01 +02:00
|
|
|
preselect = "enable",
|
2021-03-20 07:32:49 +01:00
|
|
|
throttle_time = 80,
|
|
|
|
source_timeout = 200,
|
|
|
|
incomplete_delay = 400,
|
|
|
|
max_abbr_width = 100,
|
|
|
|
max_kind_width = 100,
|
|
|
|
max_menu_width = 100,
|
|
|
|
documentation = true,
|
2021-03-10 05:55:11 +01:00
|
|
|
|
2021-03-20 07:32:49 +01:00
|
|
|
source = {
|
2021-07-05 03:14:01 +02:00
|
|
|
path = { kind = " (Path)" },
|
|
|
|
buffer = { kind = " (Buffer)" },
|
|
|
|
calc = { kind = " (Calc)" },
|
|
|
|
vsnip = { kind = " (Snippet)" },
|
|
|
|
nvim_lsp = { kind = " (LSP)" },
|
|
|
|
-- nvim_lua = {kind = " "},
|
|
|
|
nvim_lua = false,
|
|
|
|
spell = { kind = " (Spell)" },
|
|
|
|
tags = false,
|
2021-07-06 17:30:01 +02:00
|
|
|
-- vim_dadbod_completion = true,
|
2021-07-05 03:14:01 +02:00
|
|
|
-- snippets_nvim = {kind = " "},
|
|
|
|
-- ultisnips = {kind = " "},
|
|
|
|
-- treesitter = {kind = " "},
|
|
|
|
emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } },
|
|
|
|
-- for emoji press : (idk if that in compe tho)
|
|
|
|
},
|
|
|
|
}
|
2021-03-10 05:55:11 +01:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
require("compe").setup(opt)
|
2021-07-04 16:45:38 +02:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
local t = function(str)
|
|
|
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
|
|
|
end
|
2021-03-14 20:10:28 +01:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
local check_back_space = function()
|
|
|
|
local col = vim.fn.col "." - 1
|
|
|
|
if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then
|
|
|
|
return true
|
2021-03-14 20:10:28 +01:00
|
|
|
else
|
2021-07-05 03:14:01 +02:00
|
|
|
return false
|
2021-03-14 20:10:28 +01:00
|
|
|
end
|
2021-04-27 07:17:29 +02:00
|
|
|
end
|
2021-07-02 20:39:36 +02:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
-- Use (s-)tab to:
|
|
|
|
--- move to prev/next item in completion menuone
|
|
|
|
--- jump to prev/next snippet's placeholder
|
|
|
|
_G.tab_complete = function()
|
|
|
|
if vim.fn.pumvisible() == 1 then
|
|
|
|
return t "<C-n>"
|
|
|
|
elseif vim.fn.call("vsnip#available", { 1 }) == 1 then
|
|
|
|
return t "<Plug>(vsnip-expand-or-jump)"
|
|
|
|
elseif check_back_space() then
|
|
|
|
return t "<Tab>"
|
|
|
|
else
|
|
|
|
return vim.fn["compe#complete"]()
|
|
|
|
end
|
2021-04-27 07:17:29 +02:00
|
|
|
end
|
2021-03-10 05:55:11 +01:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
_G.s_tab_complete = function()
|
|
|
|
if vim.fn.pumvisible() == 1 then
|
|
|
|
return t "<C-p>"
|
|
|
|
elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then
|
|
|
|
return t "<Plug>(vsnip-jump-prev)"
|
|
|
|
else
|
|
|
|
return t "<S-Tab>"
|
|
|
|
end
|
|
|
|
end
|
2021-07-02 20:39:36 +02:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true })
|
|
|
|
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true })
|
|
|
|
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
|
|
|
|
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
|
2021-06-26 19:47:20 +02:00
|
|
|
|
2021-07-05 03:14:01 +02:00
|
|
|
vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true })
|
2021-07-05 20:47:27 +02:00
|
|
|
-- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true })
|
2021-07-05 03:14:01 +02:00
|
|
|
vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true })
|
|
|
|
vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true })
|
|
|
|
vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true })
|
2021-06-28 04:11:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|