garymjr / nvim-snippets

Snippet support using native neovim snippets
MIT License
215 stars 13 forks source link

latex snippets from friendly-snippets should be loaded for `.tex` files + robustness on snippet errors #23

Closed pitkling closed 3 months ago

pitkling commented 3 months ago

The LaTeX snippets from friendly-snippets are not loaded by nvim-snippets when editing LaTeX files (e.g., main.tex). Other file type specific snippets work fine (e.g., lua). Also, the LaTeX snippets from friendly-snippets work in LuaSnip. I'm using nvim-snippets together with nvim-cmp.

It seems the problem is that friendly-snippets has LaTeX snippets in latex.json and inside the latex subdirectory. Those are not loaded by nvim-snippets when opening a tex file like main.tex. Note that neovim uses filetype tex for LaTeX files. This can be fixed by loading nvim-snippets with:

extended_filetypes = {
    tex = { 'latex' },
}

I think this should be default for the tex filetype.

Anyway, even with the above fix the LaTeX snippets cause errors when nvim-snippets tries to load them. I assume these might be errors in the corresponding LaTeX snippets (in that case I will report them to friendly-snippets). But I'm not too familiar with the snippet syntax, so I might be wrong. Anyway, even if they are snippet-errors it would be great if nvim-snippets would handle such problems more gracefully. The problematic LaTeX snippets from friendly-snippets are

After deleting those manually, the remaining LaTeX snippets are loaded and work as expected.

P.S.: Sorry for squeezing this into one issue; let me know if I should split the issue into two separate ones.

benelan commented 3 months ago

The first issue should be resolved when package.json definitions are supported via #5

garymjr commented 3 months ago

I didn't realize that prefix was supposed to be optional. This should be a quick fix. Hopefully the issues with $ should be solved with the latest parsing changes. @benelan is correct that using package.json to setup default language snippets should remove the need to manually setup each languages snippets

pitkling commented 3 months ago

@garymjr: Thanks for the quick fix. Anyway, it seems there's still a parsing issue:

These two still cause errors when loaded by nvim-snippets. If I delete them, it works again. Let me know if I should open a separate issue for this.