mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-12-12 17:18:22 -05:00
198 lines
6.7 KiB
Lua
198 lines
6.7 KiB
Lua
local M = {}
|
|
|
|
function M.cmp_conf()
|
|
local cmp = require('cmp')
|
|
local luasnip = require('luasnip')
|
|
|
|
local has_words_before = function()
|
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
|
return not vim.api.nvim_get_current_line():sub(1, cursor[2]):match('^%s$')
|
|
end
|
|
|
|
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 = '',
|
|
Struct = 'פּ',
|
|
Event = '',
|
|
Operator = '',
|
|
TypeParameter = ''
|
|
}
|
|
-- 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]',
|
|
-- treesitter = '[TS]',
|
|
nvim_lsp = '[LSP]',
|
|
-- cmp_tabnine = '[TN]',
|
|
latex_symbols = '[TEX]',
|
|
-- tmux = '[TMUX]',
|
|
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(),
|
|
-- Change choice nodes for luasnip
|
|
['<C-h>'] = cmp.mapping(function(fallback)
|
|
if luasnip.choice_active() then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-prev-choice', true, true, true), '', true)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {'i', 's'}),
|
|
['<C-l>'] = cmp.mapping(function(fallback)
|
|
if luasnip.choice_active() then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-next-choice', true, true, true), '', true)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {'i', 's'}),
|
|
-- supertab-like mapping
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
if vim.fn.pumvisible() == 1 then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true)
|
|
elseif has_words_before() and luasnip.expand_or_jumpable() then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '', true)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {'i', 's'}),
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
if vim.fn.pumvisible() == 1 then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n', true)
|
|
elseif luasnip.jumpable(-1) then
|
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '', true)
|
|
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'},
|
|
-- {name = 'treesitter'},
|
|
{name = 'nvim_lsp'},
|
|
-- {name = 'cmp_tabnine'},
|
|
{name = 'conjure'},
|
|
{name = 'latex_symbols'},
|
|
-- {name = 'tmux'},
|
|
{name = 'orgmode'}
|
|
}
|
|
}
|
|
end
|
|
|
|
-- 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
|
|
|
|
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
|
|
})
|
|
end
|
|
|
|
function M.snippets_conf()
|
|
local types = require('luasnip.util.types')
|
|
|
|
require('luasnip').config.set_config({
|
|
updateevents = 'TextChanged, TextChangedI',
|
|
history = true,
|
|
ext_opts = {
|
|
[types.choiceNode] = {
|
|
active = {
|
|
virt_text = {{'●', 'Orange'}}
|
|
}
|
|
},
|
|
[types.insertNode] = {
|
|
active = {
|
|
virt_text = {{'●', 'Blue'}}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
-- Loading vscode-like snippets from 'friendly-snippets'
|
|
require('luasnip/loaders/from_vscode').load()
|
|
end
|
|
|
|
-- 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
|
|
|
|
function M.autotag_conf()
|
|
require('nvim-ts-autotag').setup({
|
|
filetypes = {
|
|
'html', 'javascript', 'javascriptreact', 'typescript',
|
|
'typescriptreact', 'svelte', 'vue'
|
|
}
|
|
})
|
|
end
|
|
|
|
return M
|