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
Let me start by exploring the repository structure to understand what we'reworking with.
Assistant
This is a Rust project. Let me explore the crates directoryto find the formatter.
Assistant
Let me see the call function and how arguments are formatted:
Assistant
Now let me look at the
format_call_with_headfunction and the rest of the expression.rs to understand how functioncall formatting works:Assistant
Now let me look at the lindig.rs to understand Documentand pretty-printing:
Assistant
Now let me see the rest of the expression.rs file - especially the call function and join_pattern_entries:
Assistant
Let me look at sequence.rs which contains join_pattern_entries and other things:
Assistant
Let me look at how the issue manifests. First let me create a reproduction script:
Assistant
Let me find where the compiler validates f-string interpolation to understand the constraint better:
Assistant
Now let me reproduce the issue. Let me first set up a test program:
Assistant
Let me write a simple test to verify the bug:
Assistant
The error reproduces. Now let me also test what happens when we feed single-line input:
Assistant
I've confirmed the issue. Let me look more carefully at the format string AST and find a way to preserve the original source for interpolation:
Assistant
Let me look at the parser to see how format strings are parsed:
Assistant
Let me look at the formatter to see if it has access to the source code:
Assistant
Let me check the parser error more carefully. The user's example has multi-line interpolation that should be a parse error:
Assistant
Now let me look at how the source is passed to the formatter:
Assistant
The Comments struct already has access to the source. Let me check if there's a public getter:
Assistant
Let me check how the Formatter uses comments:
Assistant
Let me look at the comments.rs file to understand the structure:
Assistant
Let me look at the lexer for the format string to understand what the interpolation span includes:
Assistant
Let me check what happens with block comments in interpolation:
Assistant
Now let me implement the fix. The simplest and most reliable approach is to use the verbatim source text for the interpolation expression. Let me check the test infrastructure first:
Assistant
Now I have a clear understanding. Let me implement the fix. The plan is:
- Add a way to access the source code from the formatter (via
Comments). - In
format_string, use the verbatim source text for the interpolation expression instead of reformatting it. This preserves the user's formatting and guarantees single-line output for valid input.
- Add a way to access the source code from the formatter (via
Assistant
Now let me implement the fix. I'll add a method to
Commentsto get the source for a span, then use it in theformat_stringfunction:Assistant
Let me add a method to
Commentsto get the source text for a span:Assistant
Now let me add the source accessor method:
Assistant
Hmm, my replacement didn't work because I used
syntax::ast::Spanoriginally. Let me look at what I did wrong - actually I see I did changesyntax::ast::SpantoSpanin the import. Let me re-look.Looking at line 1-3:
use crate::lindig::{Document, concat, join}; use syntax::ast::Span; use syntax::lex::Trivia;OK so I already imported
Span. So my replacement should match. Let me see if my issue is the specialcharacters in the heredoc.Assistant
The file still has
syntax::ast::Span. My earlier edit only added the import line. Let me try again with the correct search text:Assistant
Let me use the
editcommand for a more focused change:Assistant
I see - I included an extra
}. Let me check and fix:Assistant
There's still an extra
}on line 317. Let me remove it:Assistant
Now let me add a blank line between the closing
}of the impl block and the next function:Assistant
I now have a duplicate
fn comments_to_document. Let me remove it:Assistant
The line numbers shifted. Now lines 316 has the closing
}of the impl, and lines 318-319 have the duplicatefn comments_to_document. Let me deleteline 319.Assistant
Now let me verify the file compiles by running cargo build:
Assistant
Now let me update the formatter to use this new method:
Assistant
Now let me update the formatter to use the verbatim source for interpolation expressions:
Assistant
Now let me build and run the test to see if it works:
Assistant
The fix works for the main issue. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All format crate tests pass. Now let me run the format integration tests:
Assistant
Let me look at the format-related test failures:
Assistant
These failures are in
spec::emit::expressions::format_string_*tests, not in format tests. These tests are testing the emit crate (Go code generation), not the formatter. Let me check the actual format tests:Assistant
All 292 format tests pass! Let me check those emit test failures to make sure they're not related to my changes:
Assistant
These tests are pre-existing failures unrelated to my changes. Let me restore my changes:
Assistant
Now let me also run a broader test to ensure I haven't broken anything else:
Assistant
Many tests are failing. Let me check if this is pre-existing or if my change broke them. Let me revert my changes and run again:
Assistant
These test failures are pre-existing and unrelated to my fix. Let me restore my changes:
Assistant
Lots of pre-existing failing tests. Let me clean those snapshot.new files up and then runthe format-related tests only:
Assistant
Let me also test some edge cases:
Assistant
All edge cases work correctly. Now let me also check the format-fstring-multiline-text-roundtrip test which uses
\nin the source:Assistant
Let me verify this test passes:
Assistant
Let me verify idempotency:
Assistant
Excellent! All idempotent. Let me also run all spec::format tests to ensure no regression:
Assistant
Let me also run the lex and parse tests to ensure I haven't introduced regressions:
Assistant
Let me also run the other test targets:
Assistant
Let me look at e2e_learn to see if it does any testing of f-string interpolation:
Assistant
Let me check the existing fstring test:
Assistant
Let me also check the comment about
preludesince that may have f-string examples:Assistant
Let me test a couple more edge cases:
Assistant
Let me think about this more carefully. The user's whitespace inside
{}should ideally be normalized. Let me improve the fix to try formatting first and fall back to verbatim source if formatting would break the line:Assistant
Let me improve the fix to try formatting first and fall back to verbatim source only if needed:
Assistant
I see there's a missing closing
}for thematchblock. Let me fix this:Assistant
Now let me build and test:
Assistant
Now let me verify the original issue case:
Assistant
Let me run all the format tests to make sure nothing is broken:
Assistant
Let me also check what happens with complex edge cases:
Assistant
Let me verify idempotency:
Assistant
All idempotent. Let me run the comprehensive test suite to make sure nothing else is broken:
Assistant
Wait, only 12 tests? Let me try a different filter:
Assistant
All library tests pass. Let me check the current state of my changes:
Assistant
Wait, I see there's a stray deletion in the diff. Let me check the comments.rs file:
Assistant
There's a missing line
let _ = comments.peek()?;- it was accidentally removed during my edits. Let me check the original file and restore it:Assistant
Now there's a duplicate
let mut docsline. Let me remove the duplicate on line 323:Assistant
Now there's another duplicate
while letline. Let me remove line 325:Assistant
Now let me verify the diff is clean:
Assistant
Let me also check that I haven't introduced any other unintended changes:
Assistant
I accidentally removed the blank line between
}anddocs.push. Let me restore it:Assistant
I see I have issues with the file - there's an extra
}andconcat(docs)was removed. Let me look at the original file to understand:Assistant
The original ends with
concat(docs)on line 254. Let me check myfile and fix it:Assistant
Let me fix the missing blank line between format_string and block:
Assistant
I see I have duplicate
concat(docs)lines and missinglet block_end. Let me fix these:Assistant
Let me check that the file builds:
Assistant
Let me now check the diff to make sure it's clean:
Assistant
Let me restore that blank line:
Assistant
I lost the
returnkeyword on line 266! Let me fix this:Assistant
The file is broken. Let me restore it from git and re-apply my changes more carefully:
Assistant
Good. Now let me apply my changes very carefully using the
replacecommand:Assistant
The replace tool found it at line 238. Let me try again with the right context:
Assistant
Now the file looks correct. Let me verify the build and run the tests:
Assistant
The diff is now clean. Let me run all the tests to confirm nothing is broken:
Assistant
Let me also run the reproduction script to verify the fix is still working:
Assistant
Let me run all the spec tests one more time to make sure nothing is broken:
Assistant
All non-emit tests pass. Let me also verify the format tests pass once more and clean up:
Assistant
Let me clean up the temporary reproduction files:
Assistant
Let me view the final diff to make sure everything is correct:
Assistant
Let me do a final verification that the build works:
Assistant
Let me also run the full test suite (only the ones that were passing) to make sure I haven't introduced any new failures:
Assistant
Let me verify by comparing to pre-change test results:
Assistant
Let me clean up these .snap.new files:
Assistant
Let me do one final test to verify the fix works:
Assistant
Let me show the final state of the changes:
Assistant
Now let me address the checklist:
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it.
- I created a reproduction script in
/tmp/repro/and confirmed thatf"You cannot use another ender pearl for {shared.format_duration(remaining)}."was being reformatted to multiple lines, causing a parse error.
- I created a reproduction script in
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
-
Assistant
The fix is complete. Let me also do a final verification of my work by running the issue's specific scenario:
Assistant
My assertion was too strict. Let me fix it:
Assistant
The fix is verified. Let me clean up the temporary files:
Assistant
The fix is complete and ready to be submitted. Here's a summary:
Summary of Changes
The issue was that the Lisette formatter was reformatting single-line f-string interpolations across multiple lines, but the lexer rejects multi-line interpolations with the error "f-string interpolations must be single-line".
Changes:
-
crates/format/src/comments.rs:- Added
use syntax::ast::Span;import. - Updated
has_comments_in_rangeto use the importedSpantype. - Added a new
source_for_spanmethod that returns the verbatim source text for a given span. This allows the formatter to preserve the original formatting of f-string interpolations when reformatting would introduce line breaks.
- Added
-
crates/format/src/formatter/expression.rs:- Updated the function to handle differently. The expression is first rendered at a very wide width (effectively forcing it to stay on one line). If the result still contains newlines (e.g., for very long expressions), the formatter falls back to the original source verbatim. This approach:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.