Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Syntax highlighting in braces #714

Closed
cdtut opened this issue Dec 5, 2023 · 5 comments
Closed

🐛 BUG: Syntax highlighting in braces #714

cdtut opened this issue Dec 5, 2023 · 5 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: syntax Issue in our syntax highlighting (scope)

Comments

@cdtut
Copy link

cdtut commented Dec 5, 2023

Describe the Bug

Words inside braces have wrong highlighting. They are different from same words outside braces.

Steps to Reproduce

Write in vscode and see highlighting.

<div>word</div>
{true && <div>word</div>}
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 5, 2023
@Princesseuh
Copy link
Member

Princesseuh commented Dec 5, 2023

I suspect the theme you're using is theming text in the JSX scope wrongly or perhaps has a custom theme just for JSX. Outside of expressions, we match (as best as we can) HTML highlighting and looking at all the theme I have installed, our text color matches's always HTML and only a few themes are handling JSX wrongly, in most themes they're the same color. We specifically use the text.astro scope to use the proper color for text.

There's unfortunately nothing we can do about themes theming specific embedded languages differently from Astro.

@cdtut
Copy link
Author

cdtut commented Dec 5, 2023

Found workaround.

"editor.tokenColorCustomizations": {
  "textMateRules": [
    {
      "scope": "meta.tag",
      "settings": {
        "foreground": "#FFFFFF"
      }
    }
  ]
}

Can meta.tag refer to same value as text.astro/source.astro so they are always same color?

@Princesseuh
Copy link
Member

We could probably set meta.tag on the content of the tag like JSX does, yes! We followed HTML in this regard where the content is always text.

Would you be willing to send a PR for this? I can't quite remember how we handle tag content so can't pinpoint the line just now, but the syntax file is here and should be fairly documented: https://github.com/withastro/language-tools/blob/main/packages/vscode/syntaxes/astro.tmLanguage.src.yaml

@Princesseuh Princesseuh added feat: syntax Issue in our syntax highlighting (scope) - P2: nice to have Not breaking anything but nice to have (priority) and removed needs triage Issue needs to be triaged labels Dec 6, 2023
@goulvenclech
Copy link
Contributor

goulvenclech commented Mar 13, 2024

Sadly @cdtut , HTML and JSX have different approaches to syntax highlighting. JSX chose to have a meta.tag pattern matching tags and their content, while HTML chose to differentiate tags and text (tags content).

Astro chose to follow HTML, and it seems impossible to make these philosophies coexist 😕 @Princesseuh maybe you should close this issue?

@Princesseuh
Copy link
Member

Yeah, after investigating it seems like it's impossible to make everything work. You end up either breaking themes that highlight JSX's meta.tag a particular way, or you break those that highlight text a particular way. It's quite wonky. Other frameworks that uses JavaScript's TextMate grammar + HTML also have a similar issue.

Since:

  • There's a workaround
  • It doesn't affect a lot of themes
  • We generally align with HTML when possible

I'll just close this, apologies for the inconveniences. In the future, if we choose the completely own syntax highlighting inside expressions, we could fix this then, but it's a fairly consequential task.

@Princesseuh Princesseuh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: syntax Issue in our syntax highlighting (scope)
Projects
None yet
Development

No branches or pull requests

3 participants