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.
Assistant
I'll start by exploring the repository structure to understand the codebase and then reproduce the issue.
Assistant
Let me explore the repository structure first.
Assistant
This is a Rust project. Let me explore the structure.
Assistant
There's a
formatcrate. Let me look at it and the f-string handling.Assistant
I need to make single tool calls. Let me look at the format crate structure.
Assistant
I can see the issue. The f-string interpolation uses
self.expression(e)which can produce multi-line output for calls with arguments. Let me look at how calls are formatted to understand the multi-line behavior.Assistant
Let me look at the
callfunction and theDocumenttype to understand how formatting produces multi-line output.Assistant
Let me look at the
Documenttype to understand how the rendering works and what options are available to force single-line.Assistant
Now I understand the Document model. Let me look at the CLI to find how to run the formatter, and write a reproduction.
Assistant
Now let me reproduce the issue. Let me check
format_sourceand the line limit.Assistant
Let me create a temporary reproduction test to confirm the bug.
Assistant
Let me check how the test module includes files before running.
Assistant
The format/mod.rs uses
assert_format_snapshot!. My_repro.rsis a separate file that won't be included as a module unless declared. Let me instead add the test directly to the format/mod.rs temporarily, run it, then revert. Actually simpler: let me just add a test function to format/mod.rs, run it, thengit checkout.Let me remove the _repro.rs file and add a temporary test to format/mod.rs.
Assistant
The line fit on one line because it was short. The issue triggers when the line exceeds 80 chars. Let me reproduce with a longer string.
Assistant
The line stayed single because the call group fit within 80 chars. The break triggers when the call group itself doesn't fit. Let me make the prefix longer so the call group exceeds the limit.
Assistant
My Python replacement used unescaped quotes. Let me fix the input to properly escape the inner quotes.
Assistant
I need to escape the inner quotes with backslashes for the Rust source. Let me rewrite using a heredoc directly.
Assistant
Now let me run the test.
Assistant
I've reproduced the bug. The formatter produces a multi-line f-string interpolation. Let me see the actual formatted output.
Assistant
The
.snap.newis stale. Let me write a standalone example to print the actual formatted output.Assistant
I've reproduced the exact issue. The formatter breaks the call's argument list inside the f-string interpolation. Now let me understand the fix. Let me look more at how the Document modes work and whether there's a flat-rendering mechanism.
Assistant
I see there's a pattern of pre-rendering documents to strings using
to_pretty_string. Let me look at how this is used in sequence.rs.Assistant
Now I understand the approach. The cleanest fix is to force the f-string interpolation expression to render on a single line. Let me look at how the lexer parses f-string interpolations to ensure my fix is safe (e.g., nested braces).
Assistant
The lexer balances nested braces and only rejects interpolations containing newlines. So forcing the interpolation expression to render on a single line (no newlines) is exactly the right fix. Let me look at the current
format_stringonce more and implement.Assistant
Now I'll implement the fix. The interpolation expression must render on a single line. I'll pre-render it flat (with an effectively unlimited width, consistent with the existing
to_pretty_stringpre-rendering pattern used elsewhere in the codebase) so no group/flex-break splits it across lines.Assistant
Now let me verify the fix with my reproduction example.
Assistant
The interpolation now stays on a single line. Let me verify the test passes now (idempotency check).
Assistant
The test "fails" only because the snapshot is new (no parse error now). Let me check the generated snapshot.
Assistant
The output is now single-line and idempotent (the idempotency check passed; it only "fails" because the snapshot is new). Let me test more edge cases with my example harness.
Assistant
All valid single-line inputs now produce single-line output and are idempotent. The two "FORMAT ERROR" cases are inputs that are already multi-line (rejected by the lexer at parse time, before formatting) — those aren't a regression; the formatter never sees them.
Let me check existing format snapshots for any f-string interpolations that might be affected.
Assistant
Let me look at the test definitions for these f-string tests.
Assistant
The existing f-string tests use simple identifier interpolations (
{name}), which are unaffected by my change. Let me remove my temporary test and example file, then run the full format test suite to ensure nothing breaks.Assistant
The mod.rs shows as modified — let me check that I restored it cleanly.
Assistant
There's a trailing blank line. Let me restore mod.rs to its original state.
Assistant
Now let me run the existing format test suite to ensure nothing breaks.
Assistant
These failures are in
spec::emit(Go codegen), not the formatter. Let me verify whether they're pre-existing by stashing my change.Assistant
These 11 failures are pre-existing (they fail without my change too) — unrelated to my fix. Let me restore my change.
Assistant
Let me clean up the stale snapshot files and run just the
spec::formattests (the ones my change affects).Assistant
All 292
spec::formattests pass, including the f-string ones. Let me also run the format crate's own unit tests.Assistant
The output is truncated. Let me run with
--no-fail-fastand capture differently.Assistant
Hmm, the log is empty. The
> /tmp/fmt_test.logwith2>&1should have captured. But the file appears empty when cat'd. The terminal shows "The command exited with exit code 0". Weird. Let me try differently.Wait — maybe the issue is the
> /tmp/fmt_test.log; grepreturned exit 1 because grep found nothing (no matches), and the file is empty because the output went elsewhere. Actually2>&1 > fileredirects stdout to file after stderr to stdout... order matters.2>&1 > filemeans: first dup stderr to current stdout (terminal), then redirect stdout to file. So stderr still goes to terminal, stdout to file. The build messages go to stderr. So file would have the test results (stdout). Butcargo testtest output goes to stdout normally... Actually cargo test prints test results to stdout. Hmm.Let me just run it properly with
&>to capture both.Assistant
The grep returned no matches (exit 1) but cargo test succeeded (exit 0). Let me check what's in the log.
Assistant
The format crate shows only "Finished" with no test run. Let me check the Cargo.toml and run with
--lib --verbose.Assistant
All format tests pass (292 spec tests + 25 lib unit tests). The pre-existing emit failures are unrelated to my change.
Let me do a final review of my change and ensure no stray temp files remain.
Assistant
The diff is clean — only the one change. Let me run a few more related spec test suites (parse, lex) to be thorough, since they involve f-string handling.
Assistant
Parse and lex tests pass too. Let me do one final clean verification of the exact issue scenario (a single-line f-string long enough that the old formatter would split it).
Assistant
My assertion script had a bug — it grabbed the wrong
{(the function block's brace). Let me fix the verification script.Assistant
The fix works correctly — the interpolation is single-line and the output is idempotent. Let me confirm the final state is clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.