nunjucks-for-visual-studio-code
nunjucks-for-visual-studio-code copied to clipboard
Possible to use on other grammar instead of HTML?
from readme:
provide syntax highlighting for Nunjucks tags, filers, and variables which are injected into the default html grammar
So I'm making a code generator from openapi definition. I'm generating typescript files, so my files are named operation.ts.njk etc. Now obviously the base code is typescript, then I have nunjucks sprinkled inside it. Can I make the base grammar typescript and not html?
Actually I face this issue often, something.html.twig, works kinda okey with a twig extension, but making a php/rust/go file with twig, it craps out. So this question is kinda broad, is it possible to for [Template Engine] Extensions to inject their tags, filers, and variables into arbitrary user selectable grammar?
@sarim The extension will register the grammar as HTML Nunjucks because of the .njk extension.
If you override the grammar to be TypeScript, the Better Nunjucks Extension will not work.
If you share an example Gist, it will help me understand what you're trying to do. That being said I don't know of a way for a grammar or LSP extension to know what syntax highlighting you're wanting unless there is something inside of a configuration file that talks to the LSP. - sense TWIG, Nunjucks, Liquid, Handlebars, etc. share a similar syntax. I'm sure there is a way to support embedded languages with VSCode's LSP, but I haven't had time to learn how that works and is probably out of the supported scope for this extension.
I have plans on creating an extension for, Eleventy projects, that supports all the templating languages but is based on the eleventy configuration file.
@edheltzel I made a demo for you here: https://github.com/sarim/nunjucks-vscode-demo .
I did a bit more search, and it seems like for things to be dynamic, extension needs to create a language server then provide features (syntax highlight, autocomplete etc.. from there). Ref: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
Thanks... Yeah I have plans on doing this.
I have the same use case, would be nice to see it support other grammars