Skip to content

Fix(Language): Comment scope guard + bg:url() / pipe highlighting - #426

Closed
0Miles wants to merge 1 commit into
master-co:rcfrom
0Miles:fix/grammar-bg-and-comments
Closed

0Miles wants to merge 1 commit into
master-co:rcfrom
0Miles:fix/grammar-bg-and-comments

Conversation

@0Miles

@0Miles 0Miles commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Closes #361, #217.

Summary

Two TextMate grammar fixes:

#361 — comment scope guard

`master-css.injection-{class,react,vue,string}.json` injection selectors didn't exclude comment scopes. Only `injection-js.json` had `-comment` in its selector. This PR aligns the four others, defense-in-depth for comment-toggle scenarios.

```diff
-"injectionSelector": "L:meta.tag,L:source.mdx"
+"injectionSelector": "L:meta.tag -comment, L:source.mdx -comment"
```

#217 — `|` styling + `bg:url(/foo.png)` mis-parse

`master-css.json` had two regex bugs:

  1. The `|` separator captured `name: "comment.block"` — semantically wrong (theme tools render in comment colour, accessibility flags it as a comment). Changed to `punctuation.separator.master-css`.
  2. The class-selector pattern `(?<![\|/])(\.)…` was too loose — `.png` inside `bg:url(/foo.png)` had `o` (not `|`/`/`) before the `.` and matched as a CSS class. Tightened the lookbehind to `(?<![A-Za-z0-9_\-\|/])` so a class selector only fires at a token boundary (whitespace, `:`, `(`, etc.).

Verification

Used `vscode-textmate` + Shiki-bundled host grammars to tokenize fixture lines:

  • TSX live `className="bg:white"` → token has `support.type.property-name.css` (master-css fingerprint)
  • TSX commented `// className="bg:white"` → token only has `comment.line.double-slash.tsx` (no master-css)
  • HTML `` → only has `comment.block.html`
  • Post-fix `bg:url(/foo.png)|cover`: `|` scope = `punctuation.separator.master-css` (was `comment.block`); `.png` no longer carries class-selector scope
  • Regression: `bg:white .btn` — the `.btn` after a space still tokenizes as `entity.other.attribute-name.class.css`

Honest caveat for #361

The same comment exclusion happens on `rc` without my fix, because TSX/HTML host grammars already absorb the comment scope and don't surface inner `string.quoted`/`meta.tag` scopes that the master-css injection selector would match. The `-comment` guard is defense-in-depth — structurally correct, matching VSCode convention — but the user-visible symptom in #361 may have a different root cause (e.g. `classNames(...)` function-call context, language-configuration commentToken). The fix is worth keeping; it's not strictly proven to address the user's exact scenario.

`#217` is fully verified by tokenization.

Repro scripts

`/tmp/grammar-test/` (vscode-textmate + vscode-oniguruma + shiki for host grammars). `packages/language/` has no test infra today; adding fixture-snapshot tests is its own work-item.

@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

@0Miles is attempting to deploy a commit to the Aoyue Team on Vercel.

A member of the Team first needs to authorize it.

Two TextMate grammar fixes verified by direct vscode-textmate
tokenization (scripts in /tmp/grammar-test/).

master-co#361: comment scope guard
- Adds -comment to injection selectors in injection-{class,react,
  vue,string}.json, aligning with injection-js.json which already
  had it
- Defense-in-depth: TSX/HTML host grammars already absorb comment
  scope, but the guard makes the contract explicit and matches
  VSCode convention

#217: | styling + bg:url(/foo.png) mis-parse
- The | separator captured name: "comment.block" — semantically
  wrong. Changed to punctuation.separator.master-css
- The class-selector lookbehind (?<![|/]) was too loose; .png
  inside bg:url(/foo.png) had o (not |//) before . and matched
  as a CSS class. Tightened to (?<![A-Za-z0-9_\-|/]) so a class
  selector only fires at a token boundary
- Regression: bg:white .btn — the .btn after a space still
  tokenizes as entity.other.attribute-name.class.css

Honest caveat for master-co#361: the same comment exclusion happens on rc
without this fix, because TSX/HTML host grammars already shield
comment regions. The guard is structurally correct but the user-
visible symptom may have a different root cause. #217 is fully
verified by tokenization.

packages/language/ has no test infra today; adding fixture-snapshot
tests is its own work-item.

Closes master-co#361
Closes #217
@0Miles

0Miles commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Retracting. The #217 portion (| scope correction + class-selector lookbehind tightening) is well-verified by direct vscode-textmate tokenization and is solid on its own.

The #361 portion is the concern: my -comment injection-selector guard is structurally correct and aligns with VSCode convention, but I could not reproduce the user's exact symptom — TSX/HTML host grammars already shield comment regions from the master-css injection even on rc without my fix. The guard is defense-in-depth but I'm not sure it actually addresses the user's reported case (the issue mentions classNames(...) function calls specifically, which I haven't repro'd).

Plan: split into two PRs — one for #217 (high confidence, will re-submit shortly) and one for #361 (after I get a concrete VSCode session repro from the original reporter, or the issue gets clearer test fixtures). Branch preserved.

@0Miles 0Miles closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Master CSS syntax highlighting: Commenting out code doesn't work

1 participant