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:
lisettef"You cannot use another ender pearl for {shared.format_duration( remaining, )}."The compiler reports:
text[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.
Assistant
Let me start by understanding the repository structure and the issue. The issue is about a Lisette formatter that rewrites f-strings to multiline interpolation, which the compiler rejects. I need to:
- Explore the repository structure
- Understand how the formatter works
- Find where the formatter handles f-string interpolation
- Fix the formatter to keep interpolation expressions on a single line
Let me start by exploring the repository.
Assistant
The issue is about the formatter. Let me explore the
formatcrate.Assistant
Let me search for f-string related code in the formatter:
Assistant
Let me look at the expression.rs file more specifically for string/interpolation handling.
Assistant
Now I can see the
format_stringmethod. Let me look at it more closely. The issue is that when formatting f-string expressions, the formatter may break lines inside the{...}interpolation, but the compiler rejects multiline interpolation. Let me also look at thecallmethod since the example shows a function call inside the interpolation:Assistant
Now let me look at the
format_stringmethod again more closely:Assistant
Now I see the issue. In the
format_stringmethod, when formattingFormatStringPart::Expression(e), it callsself.expression(e)which can introduce line breaks (through the document formatting system withstrict_breaketc.). The compiler doesn't allow multiline f-string interpolation.Let me look at how the Lindig document system works to understand how to prevent line breaks:
Assistant
Let me understand the Document system better. The issue is that
format_stringcallsself.expression(e)for expressions inside{...}which can introduce line breaks. I need to force the expression to stay on one line usingnext_break_fits(false).Let me first check if there are any tests related to f-string formatting:
Assistant
Let me search for any existing f-string format tests:
Assistant
Now let me check for the snapshot files to understand the expected format output:
Assistant
Let me look at the multiline interpolation error to understand how the compiler rejects it:
Assistant
Now let me understand how the formatter handles expressions that might span multiple lines. The key issue is in
format_stringwhereself.expression(e)can produce line breaks for complex expressions like function calls with multiple arguments.Let me also check how the
next_break_fitsmethod works:Assistant
Now let me look at the existing format_string snapshot to understand the expected output:
Assistant
Now let me create a test case to reproduce the issue. The problem is when a function call with multiple arguments is inside an f-string interpolation:
Assistant
Let me write a small test script to reproduce the issue:
Assistant
Let me run the existing format tests first to understand how things work:
Assistant
Let me run just the format test for f-strings:
Assistant
Good. Now let me write a test to reproduce the issue with a function call inside an f-string:
Assistant
Let me create a test as part of the format crate's tests:
Assistant
Interesting - the current code doesn't seem to break these specific examples into multiline. Let me test with a longer example or try to understand when the formatter would break a function call inside the f-string:
Assistant
I need to fix the Rust script - the code needs to be inside
main():Assistant
Now I can see the issue! Test 5 shows the problem:
- Input:
f"This is a very long format string that should still keep the interpolation on one line {some_call(arg1)}" - Output: The formatter broke the call into multiline:
{some_call(\n arg1,\n )}
Even though my multiline check says OK (probably because the
}check logic has a bug with the trailing comma case), the output clearly shows the interpolation is now multiline! Let me fix my test script:- Input:
Assistant
My detection function is buggy - it's detecting newlines in the function body as being inside the f-string braces because it doesn't properly track f-string context. Let me fix the detection:
Assistant
Now I can see the issue clearly:
- Test 4 ("Long f-string that exceeds line width") produces output with multiline interpolation:
{some_call(\n arg1,\n )}
The formatter is breaking function call arguments across lines when the f-string line is long. This is the bug.
Now let me look at the
format_stringfunction again and fix it. The issue is that when formatting expressions inside{...}, the formatter can introduce line breaks through its normal document formatting logic. We need to force the expression to stay on a single line by usingnext_break_fits(false)(which forces "unbroken" mode):- Test 4 ("Long f-string that exceeds line width") produces output with multiline interpolation:
Assistant
Now I need to modify the
FormatStringPart::Expression(e)case to usenext_break_fits(false)which forces the next break to be in "unbroken" mode (i.e., it prevents line breaks). Let me look at how it's used elsewhere:Assistant
Looking at the code, I see
next_break_fits(false)is used to force "unbroken" mode, meaning the nextstrict_breakorflex_breakwill use its unbroken representation. But I need to think about this more carefully.Looking at the Lindig algorithm implementation:
next_break_fits(false)creates aNextBreakFits(doc, false)which when encountered, sets the mode toMode::ForcedUnbroken- In
ForcedUnbrokenmode,StrictBreakandFlexBreakuse their unbroken text
So the fix should be to wrap the expression in
next_break_fits(false)to force it to stay on one line:Assistant
Now let me make the fix. In the
format_stringmethod, I'll add.next_break_fits(false)to the expression to prevent it from being broken across lines:Assistant
Now I can see the exact lines I need to modify. The fix is on line 241 - I need to add
.next_break_fits(false)to prevent the expression from breaking across lines:Assistant
The change looks correct. Now let me test if this fix resolves the issue:
Assistant
The test is still failing for the "Long f-string" case. The temp project is being compiled from scratch and doesn't pick up my changes. Let me check:
Assistant
Hmm, it's still showing multiline. The test creates a new temp directory each time and recompiles. Let me check if the format crate is being rebuilt:
Assistant
Good, it compiled without errors. But the test is creating a new temp directory each time. The issue might be that the temp directory's cargo build doesn't properly get the new code. Let me try a different approach - run the test from a fixed directory:
Assistant
Interesting - even though
lisette-formatis being compiled, it seems like the changes aren't being picked up. Let me check what version of ecow is being used in the temp project vs. the main project:Assistant
The temp project is using
ecow 0.2.6while the main project uses0.2.7. This could cause issues. But wait, let me check if my change is actually in the file:Assistant
The change is there. The issue might be that the temp project is downloading different dependency versions from crates.io. Let me try to clean and rebuild from the lisette directory directly:
Assistant
Looking at the
formatfunction in lindig.rs, I see thatNextBreakFitsdoesn't actually change the mode during formatting - it only affects thefitscheck. AndGroupalways starts withMode::Unbrokenfor its internalfitscheck, ignoring the parent's mode. SoNextBreakFits(false)on the expression doesn't prevent it from breaking.I need to:
- Make
NextBreakFitsactually set the mode during formatting - Make
GrouprespectForcedUnbrokenmode from the parent
Let me implement both changes:
- Make
Assistant
Let me see the Group handling in both the
fitsandformatfunctions:Assistant
Now I understand the issue better. Looking at the code:
- In
fitsfunction (line 43-47):Grouponly resets mode fromBrokentoUnbrokenfor the fits check. Otherwise it keeps the same mode. - In
formatfunction (line 194-200):Groupalways starts withMode::Unbrokenfor the fits check. If it fits, it usesMode::Unbroken, otherwiseMode::Broken. NextBreakFitsis handled infits(lines 70-76) but NOT informat(line 202 just passes it through without setting the mode).
So
NextBreakFits(doc, false)should:- In
formatfunction: set the mode toMode::ForcedUnbrokenwhenenabledisfalse - In
Group: when the parent mode isForcedUnbroken, the group should respect it and not break
Let me fix both issues:
- In
Assistant
Now I need to:
- Change line 202 to handle
NextBreakFitsproperly informat(setting the mode based onenabled) - Update
Grouphandling informatto respectForcedUnbrokenmode
Let me make these changes:
- Change line 202 to handle
Assistant
I need to:
- Change the
ForceBroken | NextBreakFitscase to handleNextBreakFitswith mode changes - Update
Groupto respectForcedUnbrokenmode
- Change the
Assistant
I see there's an extra
}on line 217. Let me fix that:Assistant
There's still a duplicate line. Let me view the area around lines 215-220 and fix it properly:
Assistant
There's a duplicate
docs.pushline. Let me fix it:Assistant
There's still an extra
}on line 217. Let me fix it:Assistant
There's still an extra
}on line 218. Let me check the structure:Assistant
I see - there's an extra
}on line 218. The structure should be:}forNextBreakFitsarm (line 216)}for thematchblock (line 217)}for thewhileblock (line 218) - but this is wrong, there shouldn't be this
Let me check the full structure of the format function:
Assistant
So the structure is:
- Line 94:
fn format( - Line 102:
while let Some(...) { - Line 103:
match document { - Line 216:
}(closes theNextBreakFitsarm) - Line 217:
}(closes thematchblock) - Line 218:
}(should close thewhileblock) - Line 219:
}(should close thefn format)
But line 218 is extra. Let me remove it:
- Line 94:
Assistant
Now there's an extra
}on line 220. Let me remove it:Assistant
Now I need to add a blank line between the function and the derive:
Assistant
That didn't work right - it has literal
\n. Let me fix this:Assistant
The
pub enum Document<'a> {line got eaten. Let me restore the file and make a cleaner edit:Assistant
Let me view the original file and make precise edits:
Assistant
Now I'll make precise edits. First, let me update the
Grouphandling:Assistant
Let me use the correct format:
Assistant
I need to use the goto command correctly - it only takes a line number, not a file path. The file is already open.
Assistant
Now I can see the exact lines. Let me apply the replace:
Assistant
The changes look good. Now let me build the project to make sure it compiles:
Assistant
Now let me run my test again:
Assistant
The issue is that when running from
/tmp/test_fstring_project, the rust-toolchain.toml from/lisetteisn't being found. Let me run from the/lisettedirectory:Assistant
The existing tests still pass. Now let me create a proper test to verify the fix works by writing it as a simple inline test:
Assistant
Let me write a quick integration test using the existing test infrastructure. Let me look at how the format tests are run:
Assistant
Let me create a simple test script to verify the fix works:
Assistant
Let me run this test using the existing test framework. Let me write a unit test that can be run with cargo test:
Assistant
Interesting! The fix caused 2 test failures because the
next_break_fits(false)behavior now affects other formatting. Let me look at the failing tests:Assistant
These failures are NOT related to f-strings. They're related to regular function calls where the
next_break_fits(false)from our changes is leaking into the formatting of normal function calls.Wait, looking at the test output more carefully:
comment_same_line_trailing_before_inlinable_last_arg- The formatter now keepsfoo(a, b, // trailing\n |x| { x + 1 })on fewer lines. The old output broke args across lines, but now it keeps them on one line.
The issue is that my change to
Groupto respectForcedUnbrokenmode is affecting ALLGroupdocuments, not just f-string ones. This is too aggressive.Let me think about this more carefully. The issue is:
- When formatting
format_string, we need expressions inside to stay on one line
Assistant
Assistant
I see - the
fitsfunction already handlesNextBreakFits. The issue might be that infits, whenNextBreakFits(false)is seen, it checks if the content fits usingForcedUnbroken. But infits, this doesn't change the mode for subsequent elements.Actually, wait. Let me re-read my change more carefully. In the
formatfunction:rustDocument::NextBreakFits(document, enabled) => { let new_mode = if *enabled { Mode::ForcedBroken } else { Mode::ForcedUnbroken }; docs.push((indent, new_mode, document)); }This sets the mode for the document wrapped by
NextBreakFits. But the old code was:rustAssistant
Now let me just make the
NextBreakFitschange (without theGroupchange):Assistant
Now let me think about this differently. The current behavior is:
NextBreakFits(false)affects thefitscheck (line 75 infits)- In
format, just passes through with the current mode
Assistant
Good. Now I also need to update the
Grouphandling to respectForcedUnbroken:Assistant
Now let me build and test:
Assistant
The same tests are failing. Let me look at the failing tests more carefully. These tests involve function calls with trailing comments and lambdas. The issue is that
ForcedUnbrokenis leaking from theGroupwhen processing aNestinside.Let me trace through what happens:
NextBreakFits(Group(Call), false)→ push(indent, ForcedUnbroken, Group(Call))Group(Call)→ mode isForcedUnbroken, so usesForcedUnbrokenfor fits check- Content is a
Callwhich hasNest(Group(args)) Nestpasses through mode unchanged: pushes(indent+nest, ForcedUnbroken, Group(args))Group(args)→ mode isForcedUnbrokenagain, so args don't break
But the issue is that
NestpropagatesForcedUnbrokenmode to nested content. After the outerGroupfinishes, we're back to normal mode. So the problem must be thatNestpropagates the mode too.Let me also check
Nest:Assistant
Yes,
Nestpasses the mode through unchanged. So if we have:codeNextBreakFits(Group(Nest(Group(call_args))), false)The mode propagates:
ForcedUnbroken→Group→Nest→Group(call_args)→ call args don't break.This is correct behavior for the f-string case! The issue is that the failing tests are NOT f-strings but regular function calls.
Wait, let me check the actual test inputs. The test
comment_same_line_trailing_before_inlinable_last_arghas input:codefn f() { foo(a, b, // trailing |x| { x + 1 }) }This doesn't have any f-strings. So why would my change affect it?
The answer is that these function calls use
next_break_fits(false)in the format_call_with_head function! Let me check:Assistant
I see the problem - my changes to
lindig.rsare affecting function calls that already usenext_break_fits(false). The originalnext_break_fits(false)was only used in thefitscheck, not informat. Now it's affecting the actual formatting.I need a different approach. Let me revert the lindig.rs changes and use a simpler solution - render the f-string expression to a string with infinite line width and use
verbatim:Assistant
Now I need a different approach. Instead of modifying the lindig engine (which breaks other uses of
next_break_fits), I'll render the f-string expression to a string with a very large line width, forcing it to stay on one line:Assistant
Now let me update the
format_stringfunction to render expressions to strings with infinite line width:Assistant
Good, now let me build and test:
Assistant
I need to run the tests to verify the fix works.
Assistant
All 292 format tests pass. Now let me verify the fix resolves the f-string multiline interpolation issue:
Assistant
The fix works. The output now shows the interpolation
{some_call(arg1)}stays on one line instead of being broken across multiple lines. All 292 format tests pass.Let me verify the changes I made:
Assistant
Now let me also run the full test suite to make sure I haven't broken anything else:
Assistant
There are many failing tests. Let me investigate what's going wrong. The format tests all passed (292 passed), but there are 1588 failures in other test categories. Let me check if these failures are related to my change or were already failing.
Let me first revert my change and run the tests again to see if these failures existed before my change.
Assistant
Good - the same 1588 tests fail without my changes. These are pre-existing failures unrelated to my fix. Let me restore my changes and verify that the format tests still pass.
Assistant
All 292 format tests pass. The 1588 other failing tests are pre-existing and unrelated to my change. Let me verify my fix one more time:
Assistant
Let me run the test script one more time to confirm the fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.