fix: embedded snippets with parenthesis#9828
Conversation
🦋 Changeset detectedLatest commit: a05db18 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will not alter performance
Comparing Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughA patch release for 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_formatter/src/lib.rs (1)
1036-1057: Consider a nesting stack over one shared flag for more robust handling.
last_start_resolvedonly tracks the most recentStartEmbedded, so ifDocument::transform()descends into an inserted embedded document (which it does, per theInterneddocumentation), an innerStartEmbeddedwould overwrite the outer state. The result: an unresolved inner embed would incorrectly suppress the outerEndEmbedded. A smallVec<bool>keyed by embed depth would handle nesting safely.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_formatter/src/lib.rs` around lines 1036 - 1057, The current single-boolean state last_start_resolved is insufficient for nested embeds; replace it with a stack (e.g., Vec<bool>) tracked across the transform closure so each StartEmbedded/EndEmbedded pair uses its own depth entry: when matching FormatElement::Tag(Tag::StartEmbedded(range)) call fn_format_embedded(*range) and push true onto the stack if Some(document) (and output the Interned), or push false and output None to keep the StartEmbedded; when matching FormatElement::Tag(Tag::EndEmbedded) pop the top value and if it was true emit FormatElement::Line(LineMode::Hard) otherwise emit None so unresolved inner embeds no longer clobber outer state (adjust variable names around last_start_resolved, Interned, fn_format_embedded, and the self.document.transform closure accordingly).
🤖 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_formatter/src/lib.rs`:
- Around line 1036-1057: The current single-boolean state last_start_resolved is
insufficient for nested embeds; replace it with a stack (e.g., Vec<bool>)
tracked across the transform closure so each StartEmbedded/EndEmbedded pair uses
its own depth entry: when matching FormatElement::Tag(Tag::StartEmbedded(range))
call fn_format_embedded(*range) and push true onto the stack if Some(document)
(and output the Interned), or push false and output None to keep the
StartEmbedded; when matching FormatElement::Tag(Tag::EndEmbedded) pop the top
value and if it was true emit FormatElement::Line(LineMode::Hard) otherwise emit
None so unresolved inner embeds no longer clobber outer state (adjust variable
names around last_start_resolved, Interned, fn_format_embedded, and the
self.document.transform closure accordingly).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1b2260b6-0e0c-49f4-906d-f13e55d9cb8f
⛔ Files ignored due to path filters (3)
crates/biome_service/src/workspace/snapshots/biome_service__workspace__server__tests__issue_9484_parens_before_graphql_call.snapis excluded by!**/*.snapand included by**crates/biome_service/src/workspace/snapshots/biome_service__workspace__server__tests__issue_9484_parens_jsx_with_graphql_tag.snapis excluded by!**/*.snapand included by**crates/biome_service/src/workspace/snapshots/biome_service__workspace__server__tests__issue_9484_propagate_expand_after_embed.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (5)
.changeset/chatty-showers-cover.mdcrates/biome_formatter/src/lib.rscrates/biome_js_formatter/src/js/auxiliary/template_chunk_element.rscrates/biome_service/src/file_handlers/javascript.rscrates/biome_service/src/workspace/server.tests.rs
Summary
Closes #9484
We needed to use source maps to track the original text range.
Used coding agent to track the bug and fix it.
Test Plan
Added various tests, even one to match the expanded parents.
Docs