samuelcolvin / jinjahtml-vscode

Syntax highlighting for jinja(2) html templates in vscode
https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml
MIT License
135 stars 53 forks source link

TextMate tokens for Jinja missing if underlying language ignores (eg: quoted string) #151

Open IS2511 opened 9 months ago

IS2511 commented 9 months ago

Problem

TextMate tokens for the Jinja language are not always present with languages jinja-*. Sometimes tokens are present, but if the Jinja substitution is inside a TOML quoted string for example - no Jinja tokens, only the global Jinja language token.

Examples

Example with Jinja over TOML.

Language 'jinja', TOML value quoted ![Screenshot showing TextMate tokens of an example TOML file with language 'jinja', value quoted](https://github.com/samuelcolvin/jinjahtml-vscode/assets/23707032/cf180ace-8f57-4eec-a62a-07eff0c47501)
Language 'jinja-toml', TOML value quoted ![Screenshot showing TextMate tokens of an example TOML file with language 'jinja-toml', value quoted](https://github.com/samuelcolvin/jinjahtml-vscode/assets/23707032/f4e8793e-18c0-4e75-a270-0eacba9d1b9f)
Language 'jinja-toml', TOML value without quotes ![Screenshot showing TextMate tokens of an example TOML file with language 'jinja-toml', value without quotes](https://github.com/samuelcolvin/jinjahtml-vscode/assets/23707032/1f318a89-4bda-42db-8c18-825d2dbe3f0b)

Example with Jinja over shell.

Language 'jinja' ![Screenshot showing TextMate tokens of an example shell file with language 'jinja'](https://github.com/samuelcolvin/jinjahtml-vscode/assets/23707032/7e65fd33-224c-435b-ac6f-8827b56881c7)
Language 'jinja-shell' ![Screenshot showing TextMate tokens of an example shell file with language 'jinja-shell'](https://github.com/samuelcolvin/jinjahtml-vscode/assets/23707032/db4c38fc-9135-4aa8-b8c0-dd35d4d9a800)

Comments

When the underlying language stops parsing the text bit, so does the jinja parser? I don't have time to collect more evidence, but it seems like a parser priority issue or something. In the real world the file will supposedly be processed like so: jinja -> underlying language. But I have no idea how VSCode works with multiple parsers. I would assume in the same order they are listed... What would it place in the Jinja substitutions then? Blanks? What if the Jinja substitution closes a quoted string for example? Highly unlikely, but possible non the less.

I don't have a good idea of how the whole multiple parsers thing should work, but since in this particular case Jinja comes first for sure, this extension should always parse for Jinja substitutions first and definitely add TextMate tokens for it before the underlying language.