LunarVim/lua/core/compe.lua

113 lines
2.9 KiB
Lua
Raw Normal View History

2021-06-28 04:11:33 +02:00
local M = {}
2021-07-13 03:11:43 +02:00
M.config = function()
lvim.builtin.compe = {
2021-07-13 03:11:43 +02:00
enabled = true,
autocomplete = true,
debug = false,
min_length = 1,
preselect = "enable",
throttle_time = 80,
source_timeout = 200,
incomplete_delay = 400,
max_abbr_width = 100,
max_kind_width = 100,
max_menu_width = 100,
2021-07-31 21:47:08 +02:00
documentation = {
border = "single",
winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
2021-08-01 18:21:06 +02:00
max_width = 120,
min_width = 60,
max_height = math.floor(vim.o.lines * 0.3),
min_height = 1,
2021-07-31 21:47:08 +02:00
},
-- documentation = true,
2021-03-15 16:54:53 +01:00
2021-07-13 03:11:43 +02:00
source = {
path = { kind = "  (Path)" },
buffer = { kind = "  (Buffer)" },
calc = { kind = "  (Calc)" },
vsnip = { kind = "  (Snippet)" },
nvim_lsp = { kind = "  (LSP)" },
nvim_lua = false,
spell = { kind = "  (Spell)" },
tags = false,
vim_dadbod_completion = false,
snippets_nvim = false,
ultisnips = false,
treesitter = false,
emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } },
-- for emoji press : (idk if that in compe tho)
},
keymap = {
values = {
insert_mode = {
["<Tab>"] = 'pumvisible() ? "<C-n>" : "<Tab>"',
["<S-Tab>"] = 'pumvisible() ? "<C-p>" : "<S-Tab>"',
["<C-Space>"] = "compe#complete()",
["<C-e>"] = "compe#close('<C-e>')",
["<C-f>"] = "compe#scroll({ 'delta': +4 })",
["<C-d>"] = "compe#scroll({ 'delta': -4 })",
},
},
opts = {
insert_mode = { noremap = true, silent = true, expr = true },
},
},
2021-07-13 03:11:43 +02:00
}
end
M.setup = function()
vim.g.vsnip_snippet_dir = lvim.vsnip_dir
2021-07-07 02:42:29 +02:00
local status_ok, compe = pcall(require, "compe")
if not status_ok then
return
end
2021-03-10 05:55:11 +01:00
compe.setup(lvim.builtin.compe)
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-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
local keymap = require "keymappings"
keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts)
2021-06-28 04:11:33 +02:00
end
return M