nixvim
nixvim copied to clipboard
Temporary fix for jsregexp and therefore luasnip not working
Hey all,
I have been wanting to get luasnip's transformation and variable snippets to work in nixvim for some time now, but unfortunately, due to what I understand to be packaging issues, this is currently not possible out of the box.
However, after dissecting how luasnip loads jsregexp, I came up with this little one-liner that can be prepended to a neovim config using nixvim's extraConfigLuaPre
extraConfigLuaPre = ''
package.preload["jsregexp"] = package.loadlib("${pkgs.lua51Packages.jsregexp}/lib/lua/5.1/jsregexp/core.so", "luaopen_jsregexp_core");
'';
This method is similar to what luasnip does. luasnip will override the package loader for jsregexp.core to load its own, vendored version. However, if that does not work, it will fall back to loading the global jsregexp module. And for this load of the global module, we too provide an overriden loader, which will make sure the module gets loaded correctly.
Theoretically, this could also be altered to
extraConfigLuaPre = ''
package.preload["jsregexp"] = package.loadlib("${pkgs.lua51Packages.jsregexp}/lib/lua/5.1/jsregexp/core.so", "luaopen_jsregexp_core")
require("jsregexp")
package.preload["jsregexp"] = nil
'';
to clean up after loading and caching jsregexp. This would mirror luasnip even more closely. I don't believe this is crucial, but perhaps it would still be good practice, so we do not keep this behavior which others might not expect.
I've tested this locally on my machine and it works great with the example config that cmp suggests for using with luasnip! (If needed, I will gladly share my config 😊)
Perhaps this is not the most elegant solution and there would be better ways to accomplish this, but I'm not quite caught up on the developments on the issues that prevented this from working in the first place (I believe this is teto's domain?).
I just thought I'd share this, either for it to be added until the resolution of that or as a reference for others that face this problem in case it won't.
Thank you for making nixvim!