nvim: plugins: Drop luasnip and use snippy

Our snippet usage is not extensive. Use snippy which is a more
minimalistic plugin.
This commit is contained in:
Sanchayan Maity 2023-02-02 22:16:49 +05:30
parent b3b1ba1a45
commit dd0adf5212
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3
3 changed files with 21 additions and 65 deletions

View file

@ -1,63 +0,0 @@
--[[
Companion plugin for the LuaSnip snippet engine. Defines a completion
function which can be used for built-in insert mode completion (e.g. omni
completion). See 'ins-completion' for details. After completion the snippet
is expanded.
https://github.com/potamides/dotfiles/blob/master/.config/nvim/plugin/snipcomp.lua
--]]
-- lazy load LuaSnip, only useful when LuaSnip wasn't already loaded elsewhere
local luasnip = setmetatable({}, {__index = function(_, key) return require("luasnip")[key] end})
vim.luasnip = {}
-- https://github.com/hrsh7th/nvim-cmp/issues/180#issuecomment-915405589
require'luasnip'.config.set_config { history = true }
require('luasnip.loaders.from_vscode').lazy_load {}
local function snippet2completion(snippet)
return {
word = snippet.trigger,
menu = snippet.name,
info = vim.trim(table.concat(vim.tbl_flatten({snippet.dscr or "", "", snippet:get_docstring()}), "\n")),
dup = true,
user_data = "luasnip"
}
end
local function snippetfilter(line_to_cursor, base)
return function(s)
return not s.hidden and vim.startswith(s.trigger, base) and s.show_condition(line_to_cursor)
end
end
-- Set 'completefunc' or 'omnifunc' to 'v:lua.vim.luasnip.completefunc' to get
-- completion.
function vim.luasnip.completefunc(findstart, base)
local line, col = vim.api.nvim_get_current_line(), vim.api.nvim_win_get_cursor(0)[2]
local line_to_cursor = line:sub(1, col)
if findstart == 1 then
return vim.fn.match(line_to_cursor, '\\k*$')
end
local snippets = vim.list_extend(vim.list_slice(luasnip.get_snippets("all")), luasnip.get_snippets(vim.bo.filetype))
snippets = vim.tbl_filter(snippetfilter(line_to_cursor, base), snippets)
snippets = vim.tbl_map(snippet2completion, snippets)
table.sort(snippets, function(s1, s2) return s1.word < s2.word end)
return snippets
end
function vim.luasnip.completion_expand(item)
if item.user_data == "luasnip" and luasnip.expandable() then
luasnip.expand()
end
end
vim.cmd([[
augroup luasnip_completion_expand
autocmd!
autocmd CompleteDone * call v:lua.vim.luasnip.completion_expand(v:completed_item)
augroup END
]])
vim.o.completefunc = 'v:lua.vim.luasnip.completefunc'

View file

@ -0,0 +1,19 @@
local snippy_id = vim.api.nvim_create_augroup("snippy", { clear = true })
vim.api.nvim_create_autocmd("CompleteDone", {
group = snippy_id,
callback = function()
require("snippy").complete_done()
end,
})
require("snippy").setup({
mappings = {
is = {
["<tab>"] = "next",
["<s-tab>"] = "previous",
},
},
})
vim.keymap.set('i', '<C-x><C-u>', '<cmd>lua require(\'snippy\').complete()<CR>', { noremap = true, unique = true, silent = true })

View file

@ -16,9 +16,9 @@ local init = function ()
use 'rmagatti/auto-session'
-- Snippets
use {
'L3MON4D3/LuaSnip',
'dcampos/nvim-snippy',
requires = {
'rafamadriz/friendly-snippets',
'honza/vim-snippets',
}
}
-- Git support