2021-09-02 17:53:53 -04:00
|
|
|
local M = {}
|
2021-07-11 21:20:58 -04:00
|
|
|
|
2021-09-02 17:53:53 -04:00
|
|
|
function M.cmp_conf()
|
|
|
|
local cmp = require('cmp')
|
|
|
|
local luasnip = require('luasnip')
|
2021-07-11 21:20:58 -04:00
|
|
|
|
2021-09-09 10:01:41 -04:00
|
|
|
local has_words_before = function()
|
2021-10-08 09:06:52 -04:00
|
|
|
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
|
2021-07-11 21:20:58 -04:00
|
|
|
end
|
2021-09-02 17:53:53 -04:00
|
|
|
|
|
|
|
cmp.setup {
|
|
|
|
formatting = {
|
|
|
|
format = function(entry, vim_item)
|
|
|
|
local lspkind_icons = {
|
|
|
|
Text = '',
|
|
|
|
Method = '',
|
|
|
|
Function = '',
|
|
|
|
Constructor = '',
|
|
|
|
Field = 'ﰠ',
|
|
|
|
Variable = '',
|
|
|
|
Class = 'ﴯ',
|
|
|
|
Interface = '',
|
|
|
|
Module = '',
|
|
|
|
Property = 'ﰠ',
|
|
|
|
Unit = '塞',
|
|
|
|
Value = '',
|
|
|
|
Enum = '',
|
|
|
|
Keyword = '',
|
|
|
|
Snippet = '',
|
|
|
|
Color = '',
|
|
|
|
File = '',
|
|
|
|
Reference = '',
|
|
|
|
Folder = '',
|
|
|
|
EnumMember = '',
|
|
|
|
Constant = '',
|
2021-09-29 09:55:01 -04:00
|
|
|
Struct = '',
|
2021-09-02 17:53:53 -04:00
|
|
|
Event = '',
|
|
|
|
Operator = '',
|
2021-09-29 09:55:01 -04:00
|
|
|
TypeParameter = ''
|
2021-09-02 17:53:53 -04:00
|
|
|
}
|
|
|
|
-- load lspkind icons
|
|
|
|
vim_item.kind = string.format('%s %s', lspkind_icons[vim_item.kind], vim_item.kind)
|
|
|
|
|
|
|
|
vim_item.menu = ({
|
|
|
|
luasnip = '[SNIP]',
|
|
|
|
path = '[PATH]',
|
|
|
|
buffer = '[BUF]',
|
|
|
|
-- calc = '[CALC]',
|
|
|
|
-- nuspell = '[SPELL]',
|
|
|
|
spell = '[SPELL]',
|
|
|
|
emoji = '[EMOJI]',
|
2021-09-26 16:37:04 -04:00
|
|
|
-- treesitter = '[TS]',
|
2021-09-02 17:53:53 -04:00
|
|
|
nvim_lsp = '[LSP]',
|
2021-09-26 16:37:04 -04:00
|
|
|
-- cmp_tabnine = '[TN]',
|
2021-09-02 17:53:53 -04:00
|
|
|
latex_symbols = '[TEX]',
|
2021-09-28 05:43:50 -04:00
|
|
|
-- tmux = '[TMUX]',
|
2021-09-28 12:45:58 -04:00
|
|
|
-- conjure = '[CJ]',
|
2021-09-02 17:53:53 -04:00
|
|
|
orgmode = '[ORG]'
|
|
|
|
})[entry.source.name]
|
|
|
|
|
|
|
|
return vim_item
|
|
|
|
end
|
|
|
|
},
|
|
|
|
mapping = {
|
|
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
['<C-e>'] = cmp.mapping.close(),
|
2021-09-04 07:16:28 -04:00
|
|
|
-- Change choice nodes for luasnip
|
|
|
|
['<C-h>'] = cmp.mapping(function(fallback)
|
|
|
|
if luasnip.choice_active() then
|
2021-10-08 09:06:52 -04:00
|
|
|
luasnip.change_choice(-1)
|
2021-09-04 07:16:28 -04:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, {'i', 's'}),
|
|
|
|
['<C-l>'] = cmp.mapping(function(fallback)
|
|
|
|
if luasnip.choice_active() then
|
2021-10-08 09:06:52 -04:00
|
|
|
luasnip.change_choice(1)
|
2021-09-04 07:16:28 -04:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, {'i', 's'}),
|
2021-09-02 17:53:53 -04:00
|
|
|
-- supertab-like mapping
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
2021-10-08 09:06:52 -04:00
|
|
|
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()
|
2021-09-02 17:53:53 -04:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, {'i', 's'}),
|
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
2021-10-08 09:06:52 -04:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
2021-09-02 17:53:53 -04:00
|
|
|
elseif luasnip.jumpable(-1) then
|
2021-10-08 09:06:52 -04:00
|
|
|
luasnip.jump(-1)
|
2021-09-02 17:53:53 -04:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, {'i', 's'})
|
|
|
|
},
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{name = 'luasnip'},
|
|
|
|
{name = 'path'},
|
|
|
|
{name = 'buffer'},
|
|
|
|
-- {name = 'calc'},
|
|
|
|
-- {name = 'nuspell'},
|
|
|
|
{name = 'spell'},
|
|
|
|
{name = 'emoji'},
|
2021-09-26 16:37:04 -04:00
|
|
|
-- {name = 'treesitter'},
|
2021-09-02 17:53:53 -04:00
|
|
|
{name = 'nvim_lsp'},
|
2021-09-26 16:37:04 -04:00
|
|
|
-- {name = 'cmp_tabnine'},
|
2021-09-02 17:53:53 -04:00
|
|
|
{name = 'latex_symbols'},
|
2021-09-28 05:43:50 -04:00
|
|
|
-- {name = 'tmux'},
|
2021-09-28 12:45:58 -04:00
|
|
|
-- {name = 'conjure'},
|
2021-09-02 17:53:53 -04:00
|
|
|
{name = 'orgmode'}
|
|
|
|
}
|
|
|
|
}
|
2021-07-11 21:20:58 -04:00
|
|
|
end
|
2021-09-02 17:53:53 -04:00
|
|
|
|
2021-09-26 16:37:04 -04:00
|
|
|
-- function M.tabnine_conf()
|
|
|
|
-- local tabnine = require('cmp_tabnine.config')
|
|
|
|
-- tabnine:setup({
|
|
|
|
-- max_lines = 1000,
|
|
|
|
-- max_num_results = 20,
|
|
|
|
-- sort = true,
|
|
|
|
-- run_on_every_keystroke = true
|
|
|
|
-- })
|
|
|
|
-- end
|
|
|
|
|
2021-09-02 17:53:53 -04:00
|
|
|
function M.autopairs_conf()
|
|
|
|
require('nvim-autopairs').setup {fast_wrap = {}}
|
|
|
|
require('nvim-autopairs.completion.cmp').setup({
|
|
|
|
map_cr = true, -- map <CR> on insert mode
|
|
|
|
map_complete = true, -- it will auto insert `(` after select function or method item
|
|
|
|
auto_select = true -- automatically select the first item
|
|
|
|
})
|
2021-07-11 21:20:58 -04:00
|
|
|
end
|
|
|
|
|
2021-09-02 17:53:53 -04:00
|
|
|
function M.snippets_conf()
|
2021-09-04 07:16:28 -04:00
|
|
|
local types = require('luasnip.util.types')
|
|
|
|
|
2021-09-02 17:53:53 -04:00
|
|
|
require('luasnip').config.set_config({
|
|
|
|
updateevents = 'TextChanged, TextChangedI',
|
2021-09-04 07:16:28 -04:00
|
|
|
history = true,
|
|
|
|
ext_opts = {
|
|
|
|
[types.choiceNode] = {
|
|
|
|
active = {
|
2021-09-04 14:08:00 -04:00
|
|
|
virt_text = {{'●', 'Orange'}}
|
2021-09-04 07:16:28 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[types.insertNode] = {
|
|
|
|
active = {
|
2021-09-04 14:08:00 -04:00
|
|
|
virt_text = {{'●', 'Blue'}}
|
2021-09-04 07:16:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 17:53:53 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Loading vscode-like snippets from 'friendly-snippets'
|
2021-09-03 21:06:28 -04:00
|
|
|
require('luasnip/loaders/from_vscode').load()
|
2021-09-02 17:53:53 -04:00
|
|
|
end
|
|
|
|
|
2021-09-27 14:23:34 -04:00
|
|
|
-- function M.coq_conf()
|
|
|
|
-- -- To add snippets from lsp servers, change lsp.lua:
|
|
|
|
-- -----
|
|
|
|
-- -- local coq = require('coq')
|
|
|
|
-- -- lspconf.<server>.setup(...) --> lspconf.<server>.setup(coq.lsp_ensure_capabilities(...))
|
|
|
|
-- vim.g.coq_settings = {
|
|
|
|
-- auto_start = true,
|
|
|
|
-- display = {
|
|
|
|
-- icons = {
|
|
|
|
-- mode = 'none'
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- end
|
2021-09-02 17:53:53 -04:00
|
|
|
|
|
|
|
function M.autotag_conf()
|
2021-09-26 16:37:04 -04:00
|
|
|
require('nvim-ts-autotag').setup({
|
|
|
|
filetypes = {
|
|
|
|
'html', 'javascript', 'javascriptreact', 'typescript',
|
|
|
|
'typescriptreact', 'svelte', 'vue'
|
|
|
|
}
|
|
|
|
})
|
2021-09-02 17:53:53 -04:00
|
|
|
end
|
2021-07-11 21:20:58 -04:00
|
|
|
|
2021-09-02 17:53:53 -04:00
|
|
|
return M
|