Skip to content

fix(css): highlight statement at-rules - #247

Open
juliangut wants to merge 2 commits into
tempestphp:mainfrom
juliangut:fix/css-statement-at-rules
Open

juliangut wants to merge 2 commits into
tempestphp:mainfrom
juliangut:fix/css-statement-at-rules

Conversation

@juliangut

Copy link
Copy Markdown

At-rules ending in a semicolon were left unhighlighted; only @import and at-rules followed by a block were:

@charset "utf-8";
@layer reset, base;
@namespace svg url(http://www.w3.org/2000/svg);
.btn { @apply px-4 py-2; }

The new CssAtRulePattern highlights any @name in statement position whose statement ends in ;, rather than a fixed list of names. This covers standard CSS (@charset, @layer, @namespace) and tooling such as Tailwind (@apply, @plugin, @source, @custom-variant…) without listing them.

Left untouched on purpose:

  • @import, which keeps its own pattern.
  • Block at-rules (@layer x {, @font-face {), highlighted as before.
  • An @ inside a value or a string (url("a@b.c"), "@tailwindcss/typography"), and Tailwind variants such as @md:px-6 inside @apply.
  • At-rules inside comments.

The lookahead for the closing ; is capped at 1000 characters, so input with many @word and no ; stays linear (50,000 of them match in ~30 ms; uncapped it took ~2 s).

Added pattern tests, a language test, and tests that long unterminated input matches without a PCRE error. composer bench: css 189 µs → 190 µs, scss 266 µs → 273 µs (it now highlights @use/@include), other languages unchanged.

These changes were made with AI assistance, based on changes already in use in another project, and have been reviewed manually. That project highlights a fixed list of at-rule names; here it is generalised to any statement at-rule.

juliangut and others added 2 commits November 28, 2026 00:50
At-rules ending in a semicolon, such as `@charset`, `@layer x;`,
`@namespace` or Tailwind's `@apply`, `@plugin` and `@source`, were left
unhighlighted: only `@import` and at-rules followed by a block were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without a bound, input with many at-rules and no semicolon made every
`@` scan to the end of the input, so matching grew quadratically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant