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.
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.
Assistant
Let me start by exploring the repository structure to understand the codebase and find the relevant files related to the Lisette formatter that's causing the issue with f-string interpolation.
Assistant
I can see there's a
crates/formatdirectory that likely contains the formatter logic. Let me look at the structure more closely.Assistant
Let me explore the formatter files to understand how f-strings are being handled.
Assistant
Let me search for f-string related code in a different way:
Assistant
Let me look at the expression.rs file to understand how expressions are formatted:
Assistant
I can see
FormatStringPartis imported. Let me search for it:Assistant
Let me see the format_string method and the surrounding code:
Assistant
Now I can see the
format_stringmethod. The issue is that when an expression inside the f-string is formatted, theself.expression(e)call might cause the expression to span multiple lines (e.g., when a function call has multiple arguments), but the compiler rejects multiline f-string interpolations.Let me look at how the
callexpression is formatted to understand how expressions might get split:Assistant
I see. The
format_call_with_headcan produce multiline output when arguments are split. The issue is that when an expression is inside an f-string interpolation, we need to prevent it from being formatted across multiple lines.Let me look at the lindig module to understand the Document types available:
Assistant
Now I understand the structure. The
format_stringmethod formats expressions inside{...}by callingself.expression(e), which may produce multiline output. TheForceBrokenvariant inDocumentforces breaking, andNextBreakFitswithfalseforces the unbroken mode.Let me search for tests related to format strings to understand the expected behavior:
Assistant
Let me look at the compiler error about multiline f-string interpolation:
Assistant
Let me look at the lexer error definition:
Assistant
Good. Now let me look at the tests directory for formatting tests:
Assistant
Let me look for f-string related format tests:
Assistant
Let me look at the format test snapshots to understand the expected behavior:
Assistant
Now let me look at how to reproduce the issue. The issue is that when the formatter formats an f-string with a function call that has multiple arguments, it may split the call across lines:
Assistant
Let me create a test script to reproduce the issue:
Assistant
Let me check the Cargo.toml to understand the package names:
Assistant
Let me wait for the build to complete and run the tests:
Assistant
Now let me create a simple test to reproduce the issue:
Assistant
Let me write a simpler test directly:
Assistant
Let me add the example to the workspace:
Assistant
Let me run a quick test by adding a simple test case to an existing test:
Assistant
Let me write an inline Rust test to confirm the issue:
Assistant
I've confirmed the issue. The formatter is indeed splitting the f-string interpolation expression across multiple lines, which causes the compiler to reject it. Now let me understand the fix needed:
The
format_stringmethod inexpression.rsneeds to ensure that expressions inside{...}are formatted to stay on a single line. Looking at the code, whenself.expression(e)is called for the expression inside the interpolation, it can produce a multiline document.The solution is to force the expression inside f-string interpolation to stay on one line. I can do this by using a large line width when formatting the expression, or by using
force_break()in reverse (force unbroken). Let me look at the Document API again:Assistant
Looking at the
NextBreakFitslogic in thefitsfunction:- When
enabledisfalse, it sets mode toForcedUnbroken, which prevents breaks - When
enabledistrue, it sets mode toForcedBroken, which forces breaks
So I need to wrap the expression inside f-string interpolation with
.next_break_fits(false)to force it to stay on one line. But wait, let me re-check this logic:- When
Assistant
So
next_break_fits(false)will push the document withMode::ForcedUnbroken, which means breaks will not be taken. This is exactly what we need.However, looking at the
fitsfunction forStrictBreakandFlexBreak:Mode::ForcedUnbrokencounts the unbroken width
Let me check how
format_call_with_headworks and what document it produces:Assistant
I see the issue. The call formatting uses
.group()which allows the formatter to decide whether to break or not based on line width. But for f-string interpolations, we need to prevent breaking.The simplest fix is to wrap the expression document in a way that forces it to stay on one line. Looking at the Document variants, I can:
- Use
next_break_fits(false)which forcesForcedUnbrokenmode - Or use a higher line limit when formatting the expression
Let me look at how
to_pretty_stringworks to understand if there's a way to format with a different line limit:- Use
Assistant
The
to_pretty_stringtakes a line limit, but this is called at the end of formatting. We can't change it mid-document. The right approach is to usenext_break_fits(false)to force the expression to stay on one line.Let me look at the
format_stringmethod again and apply the fix:Assistant
Now I need to modify the
format_stringmethod to wrap the expression in a way that prevents it from being broken across multiple lines. The fix is to apply.next_break_fits(false)to force unbroken mode for the expression inside the interpolation.However, I need to think about this more carefully. The
next_break_fits(false)setsForcedUnbrokenmode, but the expression document might have its ownGroupwrapper that makes decisions based on the mode. Let me trace through the logic:- When
fitsis called withForcedUnbrokenmode, and encounters aGroup, it pushes withMode::Unbroken(line 43:Mode::Broken => docs.push((indent, Mode::Unbroken, doc))- wait, this is wrong...)
Let me re-read the
fitsfunction more carefully:- When
Assistant
I see. When
next_break_fits(false)is applied, it pushes the inner document withMode::ForcedUnbroken. Then:- When a
StrictBreakorFlexBreakis encountered inForcedUnbrokenmode, it counts theunbrokenwidth (no break is taken). - When a
Groupis encountered inForcedUnbrokenmode, the mode is preserved (line 44:_ => docs.push((indent, mode, doc))), so the inner group also seesForcedUnbroken.
This means wrapping with
next_break_fits(false)should force the entire nested document to stay on one line. But wait, looking at thefitsfunction forGroup:- When mode is
Broken, it tries the group withUnbrokenmode - When mode is anything else (including
ForcedUnbroken), it keeps the same mode
And in the
formatfunction:- When a
Assistant
I see! The
Grouphandling in theformatfunction (notfits) always callsfitswithMode::Unbrokento check if it fits. But the key insight is that when the outer wrapper isForcedUnbroken, the inner breaks (StrictBreak,FlexBreak) will use theirunbrokentext and not add newlines.So the fix should be to wrap the expression with
.group().next_break_fits(false):Assistant
Now let me apply the fix:
Assistant
Now I'll apply the fix. The key change is to wrap the expression with
.group().next_break_fits(false)to force it to stay on a single line:Assistant
Let me try a different approach with the edit command:
Assistant
I need to fix the edit command syntax. Let me use the correct format. </tool_call>
Assistant
I need to properly format my tool call. Let me use the edit command correctly.
Assistant
The edit was applied successfully. Now let me run the test to verify the fix works.
Assistant
The fix didn't work because the
formatfunction'sGrouphandling doesn't respectForcedUnbrokenmode. When aGroupis encountered, it always checks if it fits and may still decide to break. I need to modify theformatfunction inlindig.rsto respectForcedUnbrokenmode when processingGroup.Let me look at the
formatfunction:Assistant
I see the issue. The
formatfunction'sGrouphandling always checks if the content fits, and if not, it switches toBrokenmode. But when we're inForcedUnbrokenmode (fromnext_break_fits(false)), we should forceUnbrokenmode regardless of whether it fits.Let me fix the
formatfunction inlindig.rs:Assistant
The issue is that in the
formatfunction, when aGroupis encountered, it doesn't respect the current mode. It always triesfitswithMode::Unbrokenand decides whether to useMode::UnbrokenorMode::Broken.However, when we're in
Mode::ForcedUnbroken, we should force the group to stay unbroken regardless of whether it fits.Let me look at the Group handling in the format function and fix it.
Assistant
I see the issue now. The
formatfunction'sGrouphandling doesn't respectForcedUnbrokenmode. When we're inForcedUnbrokenmode, we should force the group to stay unbroken. Let me fix this.Assistant
The user is pointing out that my edit command didn't work. Let me try again with the correct syntax for the edit command.
Assistant
I see there's an extra closing brace
}on line 205 that shouldn't be there. Let me fix that.Assistant
The file looks correct now. Let me run the test again to verify the fix works.
Assistant
The test is still failing. I need to trace through the code more carefully. The issue is that
NextBreakFitsin theformatfunction doesn't actually set the mode - it just preserves the current mode. Let me fix that.Assistant
The user reminded me that I need to use tool calls. Let me continue with my fix. I've made changes to the lindig.rs file to properly set the mode when processing NextBreakFits. Now I need to run the test again to see if the fix works.
Assistant
I see the issue now. When we're in
ForcedUnbrokenmode and we hit aGroup, I'm switching toMode::Unbroken, butMode::Unbrokenstill allows the innerGroupto decide to break. I need to keep the forced mode.Assistant
The user's message seems to be empty or just a continuation indicator. Let me continue with testing my changes. I need to run the test again to see if my fix works now.
Assistant
The fix is working! The f-string interpolation now stays on a single line. The test is only failing because it's a new snapshot test that needs a snapshot file. Let me remove my test (since I shouldn't add tests) and run the existing format tests to ensure everything works.
Assistant
Good, I've restored the test file. Now let me run the existing format tests to make sure my changes don't break anything.
Assistant
Assistant
The user is reminding me that I need to use tool calls. Let me continue investigating the issue by searching for
next_break_fitsusage in the codebase.Assistant
I see the issue now. My change to
NextBreakFitsinformatis too aggressive - it affects all uses ofnext_break_fits(false)in the formatter, not just f-strings. I need a more targeted approach.Let me revert my change to
NextBreakFitsinformatand instead add a newForceUnbrokenvariant that's specifically for f-string interpolations.Assistant
I need to add the
ForceUnbrokenvariant to the Document enum and add a helper method. Let me update the enum first:Assistant
Now I need to add the
force_unbrokenhelper method and also handleForceUnbrokenin thefitsfunction. Let me first add the method:Assistant
The user hasn't sent a new message - the system is prompting me to continue with my task. I was working on adding the
ForceUnbrokenvariant to handle f-string interpolations.I've already:
- Added
ForceUnbroken(Box<Self>)to the Document enum - Added handling for it in the
formatfunction - Added the
force_unbroken()helper method
Now I need to:
- Add handling for
ForceUnbrokenin thefitsfunction - Update the
format_stringmethod to useforce_unbroken()instead ofnext_break_fits(false) - Run tests to verify the fix
Let me continue with the implementation.
- Added
Assistant
I need to add handling for
ForceUnbrokenin thefitsfunction as well. Let me do that now.Assistant
Now I need to update the
format_stringmethod to useforce_unbroken()instead ofgroup().next_break_fits(false).Assistant
I need to update the
format_stringmethod in expression.rs to useforce_unbroken()instead ofgroup().next_break_fits(false).Assistant
I accidentally edited the wrong file. Let me open the correct file and fix it.
Assistant
Good, I've reverted lindig.rs. Let me check the current state of expression.rs as well.
Assistant
Let me start fresh and implement this properly. First, let me check the current state of all modified files.
Assistant
I apologize for the confusion. Let me properly use the tool calls to continue with the fix.
Assistant
Let me start fresh - revert expression.rs and implement the fix properly.
Assistant
Let me implement the fix properly this time. I'll:
- Add
ForceUnbrokenvariant toDocumentenum inlindig.rs - Handle it in
fitsandformatfunctions - Add
force_unbroken()method - Make
GrouppropagateForcedUnbrokenmode - Use it in
format_string
Let me start by viewing the original lindig.rs file:
- Add
Assistant
I apologize for the mistake. Let me properly implement the fix by making the necessary changes to the
lindig.rsfile.Assistant
I apologize for the error in my tool call format. Let me now properly implement the fix by writing the changes directly to the files using sed commands.
Assistant
The Python script successfully updated both files. Let me now run the tests to see if the fix works correctly.
Assistant
All 292 format tests pass. Now let me verify that the fix actually works for the reported issue by creating a quick test.
Assistant
The fix works! The f-string interpolation now stays on a single line. Let me run the broader test suite to make sure nothing else is broken.
Assistant
There are many test failures. Let me investigate what's happening.
Assistant
Let me check one of the failing emit tests to understand what's happening:
Assistant
I see the issue. My change to
ForceUnbrokenis also affecting the code emitted by the emit module, which uses the same formatting infrastructure. The emitted Go code is now missing indentation and spaces (e.g.,func process (_ int) {}instead offunc process(_ int) {}, and no indentation inside function bodies).Assistant
I see the issue - my change to
ForceBrokenin theformatfunction changed its behavior from passing through the current mode to forcingForcedBrokenmode. This broke the emit tests. Let me revert that specific change.Assistant
I see the problem. I changed
ForceBrokenfrom:Document::ForceBroken(document) | Document::NextBreakFits(document, _) => { docs.push((indent, mode, document)); }to:
Document::ForceBroken(document) => { docs.push((indent, Mode::ForcedBroken, document)); }This change to
ForceBrokenis causing the emit tests to fail.ForceBrokenshould pass through the current mode, not forceForcedBrokenmode. Let me revert that change.Assistant
Wait, that sed command isn't right. Let me fix it properly:
Assistant
I need to run a command to verify the fix. Let me check the current state of the file and run tests.
Assistant
The emit tests are still failing with the same issue - missing indentation and extra spaces. Let me check if my fix_lindig.py script actually fixed the file correctly by examining the current state.
Assistant
The user seems to have received a system message. I should acknowledge it and continue with my task. Looking at my previous work, the emit tests are still failing with formatting issues (missing indentation, extra spaces). Let me investigate further.
The issue is that the emit tests show:
func process (_ int) {}instead offunc process(_ int) {}(extra space)- Missing indentation in function bodies
But the format tests passed (292 passed). This is strange because the emit module shouldn't be using the format module directly...
Wait, let me re-read the emit code. The emit module generates Go code, not Lisette code. So it shouldn't be using the Lisette formatter. Let me check if there's something else going on.
Actually, looking at the test output more carefully, the "old snapshot" shows properly formatted Go code, and the "new results" show broken Go code. This suggests that my changes somehow affected the emit module.
Assistant
The emit tests don't seem to use the format module directly. They test code emission to Go. The test failures show that the Go output is malformed (missing indentation, extra spaces). This is strange because my changes should only affect the Lindig document formatting, which is used by the format crate.
Let me check if the emit tests actually run the formatter on the Go output, or if they're comparing raw Go output. Also, let me check if maybe the issue is that the emit tests were already failing before my changes.
Actually, wait - let me re-check. The emit tests show output like
func process (_ int)with an extra space. This looks like it could be a Lindig formatting issue if the emit module uses Lindig.Let me check the emit crate's dependencies.
Assistant
The emit crate doesn't depend on the format crate or use Lindig. So my changes shouldn't affect emit tests. Let me check if the tests were already failing before my changes, or if something else is going on.
Let me revert all my changes and run the emit tests to see if they pass without my changes.
Assistant
The emit tests were already failing before my changes. I just confirmed this by stashing my changes and running the same test - it still failed with the exact same output. This means the emit test failures are a pre-existing issue in the repository, not caused by my fix.
Let me restore my changes and verify everything is working correctly.
Assistant
Good - I've confirmed that the emit tests were already failing before my changes. This is a pre-existing issue in the repository, not caused by my fix. Let me now verify my format fix works correctly and clean up.
Assistant
Let me clean up temporary files and verify my fix is complete.
Assistant
Now let me verify the final state of my changes and confirm the fix works.
Assistant
The changes look correct. Let me now run a final test to confirm the fix resolves the issue, then submit.
Assistant
I see the checklist. Let me review each item:
Checklist Review:
-
"If an error was reported in the issue description, I have successfully reproduced it." ✅
- I reproduced the error by creating a test case that showed the formatter splitting f-string interpolation expressions across multiple lines, which the compiler rejects with "Multi-line f-string interpolation" error.
-
"If an error was reported in the issue description, I have confirmed that my fix resolves the error." ✅
- I confirmed the fix works by running a test that showed f-string interpolations now stay on a single line after formatting.
-
"I have thought about edge cases and made sure my fix handles them as well." ✅
- The fix uses a new
ForceUnbrokendocument variant that propagates through nestedGroupelements, ensuring that even deeply nested expressions (like method chains, function calls with many arguments) stay on one line within f-string interpolations.
- The fix uses a new
-
Assistant
I need to fix the Rust syntax error in the test script and run it again.
Assistant
The test output shows the f-strings are staying on single lines. Let me verify this is correct by checking the actual formatted output doesn't have multiline interpolation, and also verify the fix handles the case where the formatter would normally break.
Assistant
The fix is working correctly:
- The f-string interpolation stays on a single line -
shared.format_duration(remaining, 1000, "seconds")is not split across lines - Formatting is idempotent - Reformatting the output produces the same result
- All 292 format tests pass - No regressions in existing formatting behavior
Let me clean up the temporary test files and verify the final state of my changes.
- The f-string interpolation stays on a single line -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.