2023-02-19 23:01:47 +01:00
|
|
|
function leave_snippet()
|
2023-03-27 14:42:59 +02:00
|
|
|
if
|
2023-05-18 11:51:48 +02:00
|
|
|
((vim.v.event.old_mode == 's' and vim.v.event.new_mode == 'n') or vim.v.event.old_mode == 'i')
|
|
|
|
and require('luasnip').session.current_nodes[vim.api.nvim_get_current_buf()]
|
|
|
|
and not require('luasnip').session.jump_active
|
2023-02-19 23:01:47 +01:00
|
|
|
then
|
|
|
|
require('luasnip').unlink_current()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-27 14:42:20 +02:00
|
|
|
vim.api.nvim_command [[
|
2023-02-19 23:01:47 +01:00
|
|
|
autocmd ModeChanged * lua leave_snippet()
|
2023-03-27 14:42:59 +02:00
|
|
|
]]
|
2023-02-19 23:01:47 +01:00
|
|
|
|
2023-05-20 00:49:12 +02:00
|
|
|
vim.cmd 'highlight! link CmpPmenu Pmenu'
|
|
|
|
vim.cmd 'highlight! link CmpPmenuBorder Pmenu'
|
|
|
|
vim.cmd 'highlight! CmpPmenu guibg=#282828'
|
|
|
|
vim.cmd 'highlight! CmpPmenuBorder guifg=#615750'
|
|
|
|
|
2023-02-19 23:01:47 +01:00
|
|
|
return {
|
|
|
|
{
|
|
|
|
'hrsh7th/nvim-cmp',
|
|
|
|
dependencies = {
|
|
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
|
|
'L3MON4D3/LuaSnip',
|
2023-03-23 23:07:09 +01:00
|
|
|
'saadparwaiz1/cmp_luasnip',
|
2023-05-21 21:39:20 +02:00
|
|
|
'rafamadriz/friendly-snippets',
|
2023-02-19 23:01:47 +01:00
|
|
|
},
|
2023-03-23 23:07:09 +01:00
|
|
|
config = function()
|
2023-02-19 23:01:47 +01:00
|
|
|
-- nvim-cmp setup
|
|
|
|
local cmp = require 'cmp'
|
|
|
|
local luasnip = require 'luasnip'
|
2023-05-21 21:39:20 +02:00
|
|
|
require('luasnip.loaders.from_vscode').lazy_load()
|
|
|
|
|
2023-05-20 00:49:12 +02:00
|
|
|
local border = require('utils').nvim_open_win_border
|
2023-02-19 23:01:47 +01:00
|
|
|
|
|
|
|
luasnip.config.setup {}
|
|
|
|
|
2023-05-20 00:49:12 +02:00
|
|
|
local highlight_opts = 'Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None'
|
|
|
|
|
2023-02-19 23:01:47 +01:00
|
|
|
cmp.setup {
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
2023-03-27 14:42:59 +02:00
|
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
2023-02-19 23:01:47 +01:00
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
|
|
['<C-Space>'] = cmp.mapping.complete {},
|
|
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
},
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
2023-03-27 14:42:59 +02:00
|
|
|
elseif luasnip.jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
2023-02-19 23:01:47 +01:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'luasnip' },
|
2023-05-16 11:19:10 +02:00
|
|
|
{ name = 'crates' },
|
2023-02-19 23:01:47 +01:00
|
|
|
},
|
2023-03-27 14:42:20 +02:00
|
|
|
window = {
|
|
|
|
completion = {
|
2023-05-20 00:49:12 +02:00
|
|
|
border = border 'CmpBorder',
|
|
|
|
side_padding = 1,
|
|
|
|
winhighlight = highlight_opts,
|
|
|
|
},
|
|
|
|
documentation = {
|
|
|
|
border = border 'CmpDocBorder',
|
|
|
|
winhighlight = highlight_opts,
|
2023-03-27 14:42:20 +02:00
|
|
|
},
|
|
|
|
},
|
2023-02-19 23:01:47 +01:00
|
|
|
}
|
2023-03-27 14:42:59 +02:00
|
|
|
end,
|
2023-02-19 23:01:47 +01:00
|
|
|
},
|
|
|
|
}
|