You've already forked dotfiles
49 lines
1.9 KiB
Lua
49 lines
1.9 KiB
Lua
vim.pack.add({
|
|
'https://github.com/saadparwaiz1/cmp_luasnip',
|
|
'https://github.com/rafamadriz/friendly-snippets',
|
|
'https://github.com/L3MON4D3/LuaSnip'
|
|
})
|
|
|
|
local function luasnip_dependency_update()
|
|
local luasnip_lua_path = vim.api.nvim_get_runtime_file('lua/luasnip/init.lua', false)[1]
|
|
if not luasnip_lua_path then return end -- Short circuit if not found
|
|
local luasnip_root = vim.fn.fnamemodify(luasnip_lua_path, ':h:h:h')
|
|
local artifact = luasnip_root .. '/deps/jsregexp/jsregexp.so'
|
|
|
|
-- Verify the lib exists, (re)run the make install target
|
|
if vim.uv.fs_stat(artifact) then
|
|
vim.notify('Building LuaSnip jsregexp dependency...', vim.log.levels.INFO)
|
|
vim.system({ 'make', 'install_jsregexp' }, { cwd = luasnip_root }, function(out)
|
|
vim.schedule(function()
|
|
if out.code == 0 then
|
|
vim.notify('LuaSnip jsregexp built successfully!', vim.log.levels.INFO)
|
|
else
|
|
vim.notify('Failed to build LuaSnip jsregexp:\n' .. (out.stderr or out.stdout or ''),
|
|
vim.log.levels.ERROR)
|
|
end
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd('PackChanged', {
|
|
callback = function(args)
|
|
local name, kind = args.data.spec.name, args.data.kind
|
|
if name == 'luasnip' and kind == 'update' then
|
|
luasnip_dependency_update()
|
|
end
|
|
end
|
|
})
|
|
|
|
require('luasnip').setup {
|
|
enable_autosnippets = true,
|
|
}
|
|
|
|
require('luasnip.loaders.from_vscode').lazy_load()
|
|
require('luasnip.loaders.from_lua').lazy_load({ paths = "./snippets" })
|
|
|
|
-- TODO: Figure out keymappings that make sense
|
|
vim.keymap.set({ 'i' }, '<C-K>', function() require('luasnip').expand() end, { silent = true })
|
|
vim.keymap.set({ 'i', 's' }, '<C-L>', function() require('luasnip').jump(1) end, { silent = true })
|
|
vim.keymap.set({ 'i', 's' }, '<C-H>', function() require('luasnip').jump(-1) end, { silent = true })
|