Formatter rewrites Lisette f-strings to multiline interpolation that the compiler…
- User
Formatter rewrites Lisette f-strings to multiline interpolation that the compiler rejects
lis buildrejects multiline interpolation expressions insidef"...{...}"strings, but Zed’s Lisette formatter appears to rewrite single-line calls across lines automatically.Example:
f"You cannot use another ender pearl for {shared.format_duration( remaining, )}."The compiler reports:
[error] Multi-line f-string interpolation ... error: f-string interpolations must be single-lineImpact:
lis buildfails after formatting in touched spots.- This forces manual one-line edits to pass build.
Expected:
- Either Lisette formatter should preserve single-line interpolation in compatible cases, or
- Formatter rules should be configured to avoid splitting interpolation argument expressions across lines.
Interface
No new interfaces are introduced.
- Assistant
The fix works — the interpolation stays single-line and formatting is idempotent. Accept the new snapshot:
- Assistant
Confirmed pre-existing (gofmt missing in this environment — Go output comes back unformatted). Clean up the stray
.snap.newfiles and run the full format suite: - Assistant
I'll add spec tests for those edge cases directly:
- Assistant
Both render correctly single-line (the idempotency assertion passed; only the snapshots were new). Accept them:
- Assistant
That system note reflects the stash I just ran (baseline state). Let me get the baseline failure list and restore my changes:
- Assistant
Fixed. The formatter no longer splits f-string interpolations across lines.
Root cause
The lexer hard-rejects newlines inside
f"...{...}"interpolations (crates/syntax/src/lex/mod.rs:998), but the formatter'sformat_stringembedded each interpolation expression's document — including all its groups and break points — directly into the output. When the line exceededMAX_LINE_WIDTH(80), the call's argument group broke across lines, producing output the compiler then rejects.Changes
crates/format/src/lindig.rs— addedDocument::to_flat_string(), which renders a document on a single line: every strict/flex break uses its unbroken form, group fitting andforce_breakare ignored, andNewlinebecomes a space.crates/format/src/formatter/expression.rs:239—format_stringnow renders each interpolation expression viato_flat_string()instead of embedding its breakable document, so interpolations can never be split regardless of line width. This is always safe: valid input interpolations are single-line by the lexer's rule, so a flat rendering exists for anything that parses.tests/spec/format/mod.rs— three regression tests (+ snapshots): the reported case (long method call in interpolation), a nested call with a slice literal, and a lambda argument. All previously either failed re-lexing after format or would break at width 80; all now stay single-line and format idempotently.
Verification
- The reported case reproduced before the fix: formatting produced multiline interpolation whose re-lex failed with
Multi-line f-string interpolation. - All 295
spec::formattests pass, including idempotency assertions. - Full suite failure sets are byte-identical before and after the change (the 1588 pre-existing failures are
spec::build/spec::emittests needing a Go toolchain absent in this environment). cargo clippyandcargo fmt --checkare clean.
One trade-off to note: an interpolation rendered flat can push a line past the 80-column limit, but that's the only compilable output — the alternative the lexer suggests (extracting to a
letbinding) is a semantic rewrite the formatter shouldn't do on its own.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →