feat(css): improve scss declaration modifier recovery#9352
Conversation
|
WalkthroughReworks SCSS variable declaration parsing by introducing a dedicated modifier parsing workflow and recovery logic. Adds token sets and diagnostics for modifier handling, implements ScssVariableModifierList with end-of-list detection, replaces direct list parsing with parse_scss_variable_modifiers, and adds recovery for malformed/trailing modifier sequences (including a specific diagnostic for disallowed Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
…ns and improve diagnostics
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/biome_css_parser/src/syntax/scss/declaration/variable.rs (2)
159-161: Widen the!importanterror span to cover both tokens.Right now the range is captured after bumping
!, so diagnostics typically underline onlyimportant. Including!as well would make the message match what users see.Also applies to: 172-177
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_css_parser/src/syntax/scss/declaration/variable.rs` around lines 159 - 161, The diagnostic range for the `!important` error is captured after consuming/bumping tokens, so the span excludes the leading `!`; update both places where you call p.error(important_modifier_not_allowed(p, p.cur_range())) followed by p.bump(T![important]) (and the other similar block) to capture the range before consuming: call let span = p.cur_range() (or otherwise compute the span that includes the `!` token) and pass that span into important_modifier_not_allowed when calling p.error, then proceed to bump the tokens (p.bump(T![bang]) / p.bump(T![important]) as needed) so the error underline covers both `!` and `important`.
109-112: Recovered modifiers placed outside the modifier list reduce accessor convenience.Line 110 finalises
SCSS_VARIABLE_MODIFIER_LISTbeforerecover_scss_variable_modifier_tail()runs on line 111. Recovered modifiers parsed in the tail loop become sibling nodes rather than list children, so callers usingdeclaration.modifiers()will miss them. This weakens the API ergonomics for traversing all modifiers in well-formed declarations that recover from malformed tokens.Consider incorporating recovered modifiers into the list marker's scope during recovery to preserve CST structure coherence.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_css_parser/src/syntax/scss/declaration/variable.rs` around lines 109 - 112, The recovered modifiers are being finalized outside the SCSS_VARIABLE_MODIFIER_LIST because ScssVariableModifierList.parse_list(p) completes before recover_scss_variable_modifier_tail(p) runs; change parse_scss_variable_modifiers so recovery happens while the list marker is still open — either call recover_scss_variable_modifier_tail from inside ScssVariableModifierList.parse_list or move the list finalization to after recovery so recovered nodes become children of SCSS_VARIABLE_MODIFIER_LIST and remain visible to callers using declaration.modifiers().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/biome_css_parser/src/syntax/scss/declaration/variable.rs`:
- Around line 159-161: The diagnostic range for the `!important` error is
captured after consuming/bumping tokens, so the span excludes the leading `!`;
update both places where you call p.error(important_modifier_not_allowed(p,
p.cur_range())) followed by p.bump(T![important]) (and the other similar block)
to capture the range before consuming: call let span = p.cur_range() (or
otherwise compute the span that includes the `!` token) and pass that span into
important_modifier_not_allowed when calling p.error, then proceed to bump the
tokens (p.bump(T![bang]) / p.bump(T![important]) as needed) so the error
underline covers both `!` and `important`.
- Around line 109-112: The recovered modifiers are being finalized outside the
SCSS_VARIABLE_MODIFIER_LIST because ScssVariableModifierList.parse_list(p)
completes before recover_scss_variable_modifier_tail(p) runs; change
parse_scss_variable_modifiers so recovery happens while the list marker is still
open — either call recover_scss_variable_modifier_tail from inside
ScssVariableModifierList.parse_list or move the list finalization to after
recovery so recovered nodes become children of SCSS_VARIABLE_MODIFIER_LIST and
remain visible to callers using declaration.modifiers().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8b198f25-a84b-4140-9410-e8b267a8e67e
📒 Files selected for processing (1)
crates/biome_css_parser/src/syntax/scss/declaration/variable.rs
Summary
This PR improves SCSS variable declaration modifier recovery in the CSS parser. The changes enable better error recovery when parsing malformed SCSS variable modifiers, allowing the parser to continue parsing subsequent valid modifiers even after encountering invalid tokens.
Test Plan
cargo test -p biome_css_parserDocs