Skip to content

Added container at-rule support - #15

Open
Carlos Hernandez (wileycoyote78) wants to merge 3 commits into
microsoft:mainfrom
wileycoyote78:main
Open

Added container at-rule support#15
Carlos Hernandez (wileycoyote78) wants to merge 3 commits into
microsoft:mainfrom
wileycoyote78:main

Conversation

@wileycoyote78

Copy link
Copy Markdown

The container rule is similar enough (if not down right identical) to the media rule. Copied and pasted the media lines, replaced the regex to look for container instead of media. All other patterns should work the same, so no need to create new ones.

The @container rule is similar enough  (if not down right identical) to the @media rule. Copied and pasted the @media lines, replaced the regex to look for @container instead of @media. All other patterns should work the same, so no need to create new ones.
@wileycoyote78

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Added comments on what I changed.
Added 'aspect-ratio' to the Standard CSS list
Comment thread README.md
Comment on lines +14 to +15
Saw that someone had created a pull request to add color syntax to the properties, but not the at-rule (see PR#14). After studying the cson file, I realized that the existing @media rule is basically identical to the new @container rule. Just copied and pasted the @media rule lines, and changed the regex lines to look for 'container' instead of 'media'.
This, however, still does not correct the problem that any properties (i.e. padding, margin, etc.) inside an @container block do not display a description thumbnail thingy when hovering over them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@container preludes are completely different from @media preludes.

Does this change account for this difference?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also agree with Romain Menke (@romainmenke) above. Media queries and container queries are different, and should be treated differently.

As an aside, this text excerpt should not be put in the repo's README. Rather, it should be in the PR's description.

@romainmenke

Copy link
Copy Markdown
Contributor

Also try to keep in mind that any at-rule that you reference here on GitHub is a ping to some person/account :)

You can wrap them in backticks to prevent that.

@wileycoyote78

Copy link
Copy Markdown
Author

@andreamah

Copy link
Copy Markdown
Contributor

If it should not be in the Readme, please remove it from the PR.

Is there any way that you can add a more concise way of incorporating syntax highlighting for @container? Although adopting the rules for @media would be a quick fix, I'd prefer something more accurate so that it works long-term.

@wileycoyote78

Copy link
Copy Markdown
Author

@andreamah

Copy link
Copy Markdown
Contributor

If you look at the differences between media queries and container queries in their docs, you can see that they use different keywords (ie: media features vs. the specific container descriptors).

The CSON file specifically addresses media features for @media, hence using the exact same ones for container may be strange.

'media-features':

@wileycoyote78

Copy link
Copy Markdown
Author

If you look at the differences between media queries and container queries in their docs, you can see that they use different keywords (ie: media features vs. the specific container descriptors).

The CSON file specifically addresses media features for @media, hence using the exact same ones for container may be strange.

'media-features':

I get what you are saying, however, this solution would only be "strange" if people start writing up something like @container mycontainer (prefers-reduced-motion: reduce) ...

'name': 'support.type.property-name.media.css'

I am assuming from line 1198 that there would be another file involved to help support a specific section for "container-features," though that would be beyond my expertise if so.

So it is a patch for now until full support for the rule is added.

@wileycoyote78

Copy link
Copy Markdown
Author

By the way, I seem to be unable to remove the README from the PR..?

@andreamah

Copy link
Copy Markdown
Contributor

If you look at the differences between media queries and container queries in their docs, you can see that they use different keywords (ie: media features vs. the specific container descriptors).
The CSON file specifically addresses media features for @media, hence using the exact same ones for container may be strange.

'media-features':

I get what you are saying, however, this solution would only be "strange" if people start writing up something like @container mycontainer (prefers-reduced-motion: reduce) ...

'name': 'support.type.property-name.media.css'

I am assuming from line 1198 that there would be another file involved to help support a specific section for "container-features," though that would be beyond my expertise if so.

So it is a patch for now until full support for the rule is added.

We don't want to highlight invalid syntax as if it were valid. Even if we were to introduce a patch, I would prefer something incomplete (ie: not covering all container queries and cases) rather than something that is incorrect. This way, we can try to keep the grammar better in the long-term.

Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 27, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Bound the scope leak from unclosed `@container` and `@scope` preludes
with `(?=\{[^)]*$)`. Recover at `{` only when no `)` follows on the
same line, preserving legal balanced blocks in declaration values.
Do not use `;` as a bail-out: `<general-enclosed>` permits top-level
semicolons through `<any-value>`, and legal preludes may span lines.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 27, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard every parenthesised region reachable
inside a prelude with `(?=\{[^)]*$)`: recover at `{` only when no `)`
follows on the same line, preserving legal balanced blocks in
declaration values. Guarding only the outermost regions is not enough,
because an outer `end` cannot be evaluated while an inner rule is
active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 27, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude with `(?=\{[^)]*$)`: recover at `{` only when no `)`
follows on the same line, preserving legal balanced blocks in
declaration values. Guarding only the outermost regions is not enough,
because an outer `end` cannot be evaluated while an inner rule is
active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` unguarded. A `var()` fallback may legally contain a
balanced curly block spanning lines, and guarding it truncated that
value; main does not recover an unclosed `var(` either, so the
exception gives up nothing main provided.

Give the `:lang()` and `:dir()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 27, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude with `(?=\{[^)]*$)`: recover at `{` only when no `)`
follows on the same line, preserving legal balanced blocks in
declaration values. Guarding only the outermost regions is not enough,
because an outer `end` cannot be evaluated while an inner rule is
active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` unguarded. A `var()` fallback may legally contain a
balanced curly block spanning lines, and guarding it truncated that
value; main does not recover an unclosed `var(` either, so the
exception gives up nothing main provided.

Give the `:lang()` and `:dir()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 27, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude with `(?=\{[^)]*$)`: recover at `{` only when no `)`
follows on the same line, preserving legal balanced blocks in
declaration values. Guarding only the outermost regions is not enough,
because an outer `end` cannot be evaluated while an inner rule is
active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` unguarded. A `var()` fallback may legally contain a
balanced curly block spanning lines, and guarding it truncated that
value; main does not recover an unclosed `var(` either, so the
exception gives up nothing main provided.

Give the `:lang()` and `:dir()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 28, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude so they recover at `{` only when the rest of the line
does not close the parenthesis, preserving legal balanced blocks in
declaration values. The test is lexical rather than a plain `[^)]*`,
because a `)` inside a comment, string or escape does not close
anything: without that, `@container (width > 1px{ /* ) */` stayed open
where main recovered. Guarding only the outermost regions is not
enough, because an outer `end` cannot be evaluated while an inner rule
is active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` and custom function calls unguarded. Both are
declaration values, and `<declaration-value>` admits a balanced curly
block that legally spans lines, as in `--x: --foo({ ... });`. The legal
`--foo({` and the malformed `--foo(a{` are indistinguishable within a
single line, so recovering there would cost legal CSS that main scopes
correctly. Main does not recover an unclosed `var(` either.

Give the `:lang()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 28, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude so they recover at `{` only when the rest of the line
does not close the parenthesis, preserving legal balanced blocks in
declaration values. The test is lexical rather than a plain `[^)]*`,
because a `)` inside a comment, string or escape does not close
anything: without that, `@container (width > 1px{ /* ) */` stayed open
where main recovered. Guarding only the outermost regions is not
enough, because an outer `end` cannot be evaluated while an inner rule
is active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` and custom function calls unguarded. Both are
declaration values, and `<declaration-value>` admits a balanced curly
block that legally spans lines, as in `--x: --foo({ ... });`. The legal
`--foo({` and the malformed `--foo(a{` are indistinguishable within a
single line, so recovering there would cost legal CSS that main scopes
correctly. Main does not recover an unclosed `var(` either.

Give the `:lang()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 28, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container`
coverage for the gap first identified in microsoft#15, and accept digit-prefixed
`@property` names consistently with microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude so they recover at `{` only when the rest of the line
does not close the parenthesis, preserving legal balanced blocks in
declaration values. The test is lexical rather than a plain `[^)]*`,
because a `)` inside a comment, string or escape does not close
anything: without that, `@container (width > 1px{ /* ) */` stayed open
where main recovered. Guarding only the outermost regions is not
enough, because an outer `end` cannot be evaluated while an inner rule
is active. Do not use `;` as a bail-out: `<general-enclosed>` permits
top-level semicolons through `<any-value>`, and legal preludes may
span lines.

Leave `var()` and custom function calls unguarded. Both are
declaration values, and `<declaration-value>` admits a balanced curly
block that legally spans lines, as in `--x: --foo({ ... });`. The legal
`--foo({` and the malformed `--foo(a{` are indistinguishable within a
single line, so recovering there would cost legal CSS that main scopes
correctly. Main does not recover an unclosed `var(` either.

Give the `:lang()` string rules the end-of-line fallback
the shared `#string` rule already uses, so an unterminated language
range no longer runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to microsoft#32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Kristofer Baxter (kristofer-baxter) added a commit to kristofer-baxter/vscode-css that referenced this pull request Aug 31, 2026
Add grammar and regression coverage for modern at-rules, functions,
properties, selectors, and media queries. Include `@container` coverage
for the gap first identified in PR microsoft#15, and accept
digit-prefixed `@property` names consistently with PR microsoft#43.

Dedicated prelude regions end only at `)`, so an unclosed parenthesis
would run to end of file where the generic at-rule header on main
recovers at the first `{`. Guard the parenthesised regions reachable
inside a prelude so they recover at `{` only when the rest of the line
does not close the parenthesis, preserving legal balanced blocks in
declaration values. The test is lexical rather than a plain `[^)]*`,
because a `)` inside a comment, string or escape does not close
anything: without that, `@container (width > 1px{ /* ) */` stayed open
where main recovered. The test also accepts an incomplete trailing
escape, both bare and inside an unterminated string, because a line
ending in an odd number of backslashes otherwise matches no alternative
and the newline-escape rule holds the prelude open. Guarding only the
outermost regions is not enough, because an outer `end` cannot be
evaluated while an inner rule is active. Do not use `;` as a bail-out:
`<general-enclosed>` permits top-level semicolons through `<any-value>`,
and legal preludes may span lines.

Leave `var()` and custom function calls unguarded. Both are declaration
values, and `<declaration-value>` admits a balanced curly block that
legally spans lines, as in `--x: --foo({ ... });`. The legal `--foo({`
and the malformed `--foo(a{` are indistinguishable within a single line,
so recovering there would cost legal CSS that main scopes correctly.
Main does not recover an unclosed `var(` either.

Add `#condition-string` to the `@media` and `@supports` condition
regions. The bail-out only inspects text from the candidate `{` onwards,
so with no string rule active it read the closing quote of `(future:
"a{b")` as an opening one, took the real `)` for shielded, and opened
the body at the brace inside the string. `@container` keeps no string
rule, because there an unterminated string would instead shield a
malformed `{` from the bail-out; that case tokenizes as it already does
on main.

`#condition-string` is a condition-local copy of `#string` rather than
`#string` itself. It differs in one respect: its newline escape ends at
`^` instead of the shared rule's `^(?<!\G)`, which cannot match while
the condition is still open and so swallowed the rest of the stylesheet
after a legal `@media (future: "a{\` continuation. Keeping the copy
local leaves string tokenization everywhere else byte-for-byte as it is
on main.

Give the `:lang()` string rules the end-of-line fallback the shared
`#string` rule already uses, so an unterminated language range no longer
runs past its line.

Leave `animation-timeline`, `animation-range`, `animation-range-start`,
and `animation-range-end` entirely to PR microsoft#32.
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.

5 participants