fix: Setting up luasnip a bit better with with dependency installation

properly working for jsregexp
This commit is contained in:
2026-06-04 17:39:58 -05:00
parent 2bcc1f866c
commit 82d843edbb
2 changed files with 34 additions and 10 deletions

View File

@@ -4,17 +4,41 @@ vim.pack.add({
'https://github.com/L3MON4D3/LuaSnip'
})
local luasnip_lua_path = vim.api.nvim_get_runtime_file('lua/luasnip/init.lua', false)[1]
if not luasnip_lua_path then return end
local luasnip_root = vim.fn.fnamemodify(luasnip_lua_path, ':h:h:h')
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'
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
if not args.data.active then vim.cmd.packadd('luasnip') end
vim.system({'make', 'install_jsregexp'}, { cwd = luasnip_root })
-- 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})
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,
}
-- local types = require('luasnip.util.types')
require('luasnip.loaders.from_vscode').lazy_load()
require('luasnip.loaders.from_lua').lazy_load({ paths = "./snippets" })