ISSUE DESCRIPTION Formatter rewrites Lisette f-strings to multiline interpolation that…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lisette, current file: none) bash-$
Assistant
Now let's write a reproduction test before making changes.
Assistant
Let's create a small test binary using cargo to reproduce the issue.
Assistant
Reproduced the bug. Now let's confirm the compiler rejects this output.
Assistant
Confirmed the reproduction matches the exact reported error. Now let's implement the fix in
format_string.Assistant
Now need to add
to_pretty_stringimport in scope (already accessible via Document since it's a method). Also need to import nothing extra sinceDocumentalready imported. Let's build.Assistant
Now let's re-run the repro example.
Assistant
The interpolation is preserved on a single line even though it exceeds 80 columns overall. Now let's verify this reformatted output round-trips through the lexer without errors.
Assistant
Now let's test the exact example from the issue itself (with the trailing-comma multiline call already present in source) to see behavior — formatter should collapse it back to single line.
Assistant
Let's revert the Cargo.toml dev-dependency addition since it was only needed for the example scripts, then run tests.
Assistant
Now let's build the whole workspace and run tests.
Assistant
Build succeeds. Now run test suites relevant to formatting.
Assistant
Good — same failures exist before our change, so pre-existing/environment-related, not caused by us. Let's restore our change.
Assistant
Good, now clean. Let's run just the format spec tests.
Assistant
All 292 format tests pass. Let's also run the LSP formatting stress test mentioned, and any format-related tests in other crates.
Assistant
Now let's run the fuzz seed corpus file (format_string.lis) through the formatter/lexer round-trip to double check nothing breaks with more complex nested cases.
Assistant
All good —
if x { 1 } else { 0 }interpolation remains single-line as expected. Clean up test artifacts.Assistant
Let's view the final diff.
Assistant
Now let's run the full spec test suite for
format,lex,parse, andlspcrates one more time comprehensively, plus fuzz target compile check (not running fuzz, just build) to be safe.Assistant
All confirmed clean and pre-existing failures are unrelated to formatting (they're all in
spec::emit/spec::build, present identically before and after our change). Let's also add a quick focused check ofspec::formattests once more in isolation to be safe.Assistant
All 292 pass cleanly in isolation. Final diff review:
Assistant
This is a clean, minimal, targeted fix. Let's go through the checklist explicitly.
Assistant
Summary
Root cause: In
crates/format/src/formatter/expression.rs, theformat_stringfunction rendered each f-string interpolation expression by simply callingself.expression(e)and embedding the resultingDocumentdirectly into the overall document tree, which is later pretty-printed with the module's global 80-column width limit. Because the Wadler-styleGroupbreaking decision in this pretty-printer (lindig.rs) is based on the already-consumed column width at the point the group is reached (not on the interpolation expression's own local width), a long f-string prefix could push an otherwise-short call expression'sGroupfits-check over budget, causing the formatter to wrap call arguments across multiple lines — something the lexer explicitly forbids insidef"...{...}"interpolations (Multi-line f-string interpolation/format_string_multiline_interpolation).Fix: Added
format_interpolation_expression, which renders the interpolation's expression document independently usingDocument::to_pretty_stringwith an effectively unbounded width (1_000_000columns). This guarantees that width-driven breaking decisions for the interpolation expression are made in isolation, so any expression that could originally fit on a single source line (which the lexer already guarantees, since it rejects any interpolation containing real newlines) is now always re-emitted on a single line, regardless of how much text precedes it in the f-string or where it sits on the overall line.Checklist
- Reproduced the reported error: Yes. I wrote a temporary example (
crates/format/examples/repro.rs, removed before submitting) that formatted a single-line f-string call similar to the issue and confirmed the formatter previously rewrote it into a multi-line interpolation call, which the lexer then rejected with the exactMulti-line f-string interpolation/f-string interpolations must be single-lineerror from the issue. - Confirmed the fix resolves the error: Yes. After the change, the same input renders the interpolation call on a single line (even though the overall physical line exceeds 80 columns), and feeding the formatted output back through the lexer succeeds with no errors. I also verified the fix is idempotent (formatting the output again produces identical text).
- Thought about edge cases: Considered: (1) interpolation expressions that themselves contain forced/verbatim newlines (defensively handled by falling back to
Document::verbatimif the flattened rendering unexpectedly contains a newline); (2) nested constructs likeif/elseinside interpolations (verified via the existingformat_string.lisfuzz seed corpus, output unchanged/still single-line); (3) multi-part f-strings with several interpolations and surrounding literal text with real newlines (verified existingformat_fstring_multiline_text_roundtriptest still passes); (4) sources that are already invalid (contain real multi-line interpolations) — behavior unchanged, they are still rejected at the lexer stage before formatting, which is correct and unrelated to this fix. - Ran existing tests: Ran the full
spec::formattest suite (292 tests) — all pass. Also ran the LSPstress_format_string_interpolation_positionstest — passes. Ran the full workspace test suite and confirmed the large number of failures inspec::emit/spec::buildare pre-existing and identical in count (1588) both before and after this change (verified viagit stash), so they are unrelated to this fix (environment/tooling issue, e.g. missing Go toolchain for codegen tests). Cleaned up all temporary example files and stray.snap.newartifacts before finishing.
- Reproduced the reported error: Yes. I wrote a temporary example (
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →