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

Broken synthaxe highlight since update #107

Open Kaauw opened 2 years ago

Kaauw commented 2 years ago

Dear Team,

I think an update broke the synthaxe highlight. All braces are now colorized, not only jinja2 braces. With this example :

image

As raw if you want to test :

{% if device_family == "SRX" %}
security {
  apply-flags omit;
  forwarding-options {
    family {
      inet6 {
        mode packet-based;
      }
      mpls {
        mode packet-based;
      }
      iso {
        mode packet-based;
      }
    }
  }
}
{% endif %}

Thanks,

Benjamin

samuelcolvin commented 2 years ago

An update to this extension or to vscode?

Kaauw commented 2 years ago

Maybe, I don't open this folder for a month or two maybe.

I tried with many themes and the issue is still present. If I open an HTML file formated in Jinja2HTML, the problem is also present. image

samuelcolvin commented 2 years ago

humm, seems to be broken for me too. Seems like something must have changed in vscode.

Happy to accept a PR if someone can find a fix, but since I don't use vscode day-to-day, I can't devote the time to fix this myself.

samuelcolvin commented 2 years ago

I've been looking at this for some time. It seems vscode somehow changes in how it interpreted grammars.

I tried the other "Jinja" extension which hasn't been updated for ages and it seems to be broken in the same way.

Seems like it might involve rewriting the grammar completely to get it to work.

@nathan-barrett do you have any idea what might have changed in VS code to cause this to break?

samuelcolvin commented 2 years ago

See https://github.com/microsoft/vscode/issues/158379, I'm waiting for a respond from there.

samuelcolvin commented 2 years ago

Also worth noting that for me only one brace is highlighted. I tried changing the regex in the syntax definition, but nothing seemed to work.

image

I also tried installing a different systax definition, e.g. from https://github.com/shikijs/shiki but I got the same problem.


Updated: macro -> regex

nathan-barrett commented 2 years ago

Weird, let me take a look this afternoon and see if I can shake anything loose! thanks @samuelcolvin

samuelcolvin commented 2 years ago

https://github.com/microsoft/vscode/issues/158379

@RedCMD @thqby Thanks a lot for helping out! heart

@samuelcolvin The issue samuelcolvin/jinjahtml-vscode#107 is caused by us enabling bracket pair colorization by default in 1.67 which shipped early May 2022. @Kaauw can get the previous behavior by configuring "editor.bracketPairColorization.enabled": false

cedsana commented 1 year ago

Disabling bracketPairColorization does not fix the issue on my end, I still don't get any color for the jinja brackets/variables.

RedCMD commented 1 year ago

if you're getting no syntax highlighting at all that sounds like a separate issue

has the correct language been assigned to your file? jinja2 etc

can you send a screenshot and a copy of your code

dromer commented 1 year ago

Seeing something similar happen in .cpp.j2:

Certain single-bracket enclosures get highlighted:

And here we see perfectly fine jinja code being missed (because it's enclosed within such an identified block):

I use cpp extensively with jinja, so this makes the plugin quite useless at the moment (also I miss not being able to lint the code, even though it's quirky and limited).

samuelcolvin commented 1 year ago

Has this changed recently @dromer?

dromer commented 1 year ago

I'm only using the plugin since this week and this is the only highlighting I've seen.

The main problem that I see is that any single set of { } is being identified as belonging to the .j2 syntax and anything inside of it will subsequently be highlighted incorrectly. Instead it should only look for {% %} and {{ }} enclosed code. (I understand why the later doesn't work inside " ", but that's a separate issue I assume)

Sorry if I can't give any more info. I can link to these files if you need them.

samuelcolvin commented 1 year ago

humm, have you tried disabling bracketPairColorization?

dromer commented 1 year ago

Then the jinja2 highlighting is completely broken:

(looks exactly the same as if the file just had .cpp extension. only difference is that linting is now disabled)

RedCMD commented 1 year ago

I think you confuse bracketPairColorization with syntax highlighting the bright colored bracket highlighting is handled separately by vscode and is the same for all languages the extension just tells vscode what type of brackets exist

if you try just the plain cpp language with bracketPairColorization enabled all cpp brackets will be highlighted

other than {{class_name}} it doesn't seem like any of jinja2 syntax highlighting is working in any of your examples. Jinja2 probably doesn't inject itself with enough priority

dromer commented 1 year ago

@RedCMD indeed, thnx for the clarification. Still it seems that the jinja2 scope isn't recognized when enclosed in a pair of single brackets. At least that's what I think we're observing here.