L3MON4D3 / LuaSnip

Snippet Engine for Neovim written in Lua.
Apache License 2.0
3.38k stars 242 forks source link

jsregexp and lazy.nvim setup #791

Closed blakedietz closed 1 year ago

blakedietz commented 1 year ago

I originally posted this question on the neovim subreddit. But after further sleuthing and some pointers from someone else, I ran into this section of the documentation.

If this fails, first open an issue :P, and then try installing the jsregexp-luarock. This is also possible via packer.nvim, although actual usage may require a small workaround, see https://github.com/wbthomason/packer.nvim/issues/593 or https://github.com/wbthomason/packer.nvim/issues/358.

Alternatively, jsregexp can be cloned locally, maked, and the resulting jsregexp.so placed in some place where nvim can find it (probably ~/.config/nvim/lua/).

If jsregexp is not available, transformations are replaced by a simple copy.

I was wondering if you happen to have recommendations for installing jsregexp with LazyVim.

Problem

I'm using LuaSnip with some VSCode snippets I wrote. Expanding snippets works except for usages of VSCode variable transforms.

The snippets with pascal case transforms work fine in VSCode, but not in neovim, so I'm guessing there are three potential causes.

Potential root causes

It's always best to assume it's you before you assume it's something else.

Expected

When using one of my snippets with variable transforms for pascal case, the correct parts of the snippet are converted to pascal case.

Actual

When using one of my snippets with variable transforms for pascal case the snippet expands correctly, but does not convert variables to pascal case where specified.

Assumptions

Configuration

I use a custom flavor of lazy.nvim starter.

There are two areas that impact configurations that I'm aware of.

SuperTab

I'm using some SuperTab configurations that are ripped directly from example.lua here. This impacts both LuaSnip and SuperTab.

LuaSnip

Then I configure LuaSnip to use the snippets I have on my local machine here.

As far as the actual file that's being used by LuaSnip, that's here.

I don't expect you to read the generated JSON as it is, so I wrote the smallest reproducible snippet below.

Example

{
  "Phoenix: Context change": {
    "body": ["$1", "${1/(.*)/${1:/upcase}/}"],
    "description": "prefixes: plvs,pctx,pctxch",
    "prefix": ["plvs", "pctx", "pctxch"],
    "scope": "elixir,phoenix-heex,html"
  }
}
Output for VSCode
foo_bar
FooBar
Output for neovim
foo_bar
foo_bar
leiserfg commented 1 year ago

Are you using adding build = "make install_jsregexp" to your lazy config for LuaSnip?

blakedietz commented 1 year ago

Yes.

Here's what the config looks like: https://github.com/blakedietz/dotfiles-lazyvim-nvim/blob/e7f18f3fd10d699cd012d7becdaebc24c5238d86/lua/plugins/elixir.lua#L51.

leiserfg commented 1 year ago

Check here

blakedietz commented 1 year ago

After fighting with some issues I ended up getting it working! Thanks for the recommendations. A couple of questions and thoughts.

Questions

Major version

Is version supposed to literally be copied and pasted? If so, it doesn't seem to work. I was getting an error.

{
  "L3MON4D3/LuaSnip",
  -- follow latest release.
  version = "<CurrentMajor>.*",
  -- install jsregexp (optional!).
  build = "make install_jsregexp"
}

Some steps to remedy

I was having some issues after setting the value for version as above literally (without replacing). After running LazyVim install I had to go into my ~/.local/share/nvim/lazy directory and delete a handful of LuaSnip plugin and related plugin directories by hand in order to get everything to work again.

Thank you for the help. I've opened a pr against LazyVim to include this by default, as it feels like something that should be the default instead of the exception.

blakedietz commented 1 year ago

Closing as this fixed the issue.