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.
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.
Assistant
Let me start by exploring the repository structure to understand what we're working with. This appears to be a Lisette programming language formatter issue where the formatter is rewriting single-line f-string interpolations to multiline, which the compiler rejects.
Assistant
This is a Rust project. Let me explore the format crate since that's where the formatter logic would be.
The issue is that the formatter rewrites single-line f-string interpolations to multiline, which the compiler rejects. Let me look at the format crate more closely.
Assistant
Let me look at the expression formatter since f-strings and their interpolations would be expressions.
Assistant
Let me look at the expression.rs file since f-strings and their interpolations would be expressions.
Assistant
The file is 1120 lines. Let me search for f-string related code and see how interpolations are formatted.
Assistant
The grep command exited with error. Let me try a different approach.
Assistant
Let me look at the AST definition to find how f-strings are represented.
Assistant
Let me look at the AST definition for f-strings.
Assistant
The grep command failed, likely because there are no matches. Let me search for f-string related terms differently.
Assistant
The grep is failing. Let me try with a different approach:
Assistant
Grep is having issues. Let me try a simpler approach.
Assistant
Let me look at the ast.rs file more thoroughly to understand how f-strings are represented. The issue is that the formatter is rewriting single-line f-string interpolations to multiline.
Let me look at the AST definition for f-strings and how they are formatted.
Assistant
Let me search for f-string related code more broadly.
Assistant
Let me look at the lexer and find how f-strings are represented in the AST.
Assistant
Let me look at the AST file more carefully for f-strings:
Assistant
Found it! Let me look at the Literal enum and FormatStringPart:
Assistant
Now I understand the structure. Let me look at the format expression code to see how FormatString parts are formatted:
Assistant
Let me look at the
format_stringfunction:Assistant
Now I can see the issue! The
format_stringfunction at line 230 callsself.expression(e)for the interpolation expressions, butself.expression()may format the expression across multiple lines when it's complex (e.g., a method call with many arguments).Let me understand the Document types available and see how to force single-line formatting:
Assistant
Let me look at the lindig module to understand the Document types and how to force single-line expressions:
Assistant
Now I understand the document system. The issue is that
self.expression(e)informat_stringcan produce multiline output. Let me look at how function calls are formatted and find where the multiline splitting occurs.Assistant
Let me look at the
callfunction and how it handles arguments:Assistant
Assistant
Let me search for
is_inlinable_argin the expression.rs file.Assistant
Let me look at the
is_inlinable_argfunction.Assistant
Assistant
Let me search for flex_break usage in expression.rs to see where it's used.
Assistant
Good -
flex_breakis only used in the pipeline operator (line 555). So for f-string interpolations that are method calls or simple expressions,flex_breakis not present.Now let me understand the problem better by looking at the existing tests.
Assistant
Let me check the format string test corpus:
Assistant
Let me look for format tests:
Assistant
Let me look at how the format crate tests work:
Assistant
Let me look for existing format tests to understand the testing pattern:
Assistant
Let me search for format test fixtures:
Assistant
Let me look at the format tests in the tests directory.
Assistant
Let me look at the format test module to understand how tests are structured:
Assistant
Let me search for f-string tests in the test file:
Assistant
It seems like there are no existing f-string tests. Let me look for the snapshots directory to see how snapshots work:
Assistant
Assistant
Let me first try to reproduce the issue by creating a simple test case and running the formatter.
Assistant
The build is downloading crates. Let me wait for it to complete and check the results.
Assistant
Let me find the correct package name for the format crate.
Assistant
The package is called
lisette-format. Let me try to build and test it.Assistant
Good, it builds. Now let me write a quick test to reproduce the issue:
Assistant
Let me write a simpler test to verify the issue. Since the format crate has
test = false, I'll create a temporary test file.Assistant
Let me write a small test using the test suite infrastructure:
Assistant
Let me look at how the test harness works:
Assistant
Let me create a test to reproduce the f-string multiline interpolation issue:
Assistant
Let me create a small test binary to reproduce the issue:
Assistant
Let me create a test binary to reproduce the issue:
Assistant
Now I need to add the fstring-test package to the workspace. Let me check the workspace configuration.
Assistant
Let me add the fstring-test package to the workspace members and then run it.
Assistant
Now let me run the test to reproduce the issue:
Assistant
The lexer already rejects the multiline input. Let me test with a single-line input that gets formatted to multiline:
Assistant
The simple cases work. Let me try with more arguments that would exceed the line width limit:
Assistant
Let me try with an even longer example that would exceed the 80-character line width limit:
Assistant
I've successfully reproduced the issue. The formatter is producing multiline interpolations like:
codef"result: {obj.some_method( very_long_argument_name, another_very_long_argument_name, )}."which the compiler rejects because f-string interpolations must be single-line.
Now let me implement the fix. I'll add a
Flatdocument variant that forces the inner document to never break.Assistant
Let me open the file first.
Assistant
Let me read the file first and then make the necessary edits.
Assistant
Assistant
Let me search for uses of next_break_fits to understand the current usage pattern.
Assistant
Now I understand the issue and how to fix it. Let me implement the fix by modifying the
format_stringfunction to wrap expressions in a way that prevents them from breaking across lines.Looking at the code, I need to:
- Wrap the interpolation expression in
next_break_fits(false)to set mode toForcedUnbroken - Modify
formatto not evaluate groups for breaking when inForcedUnbrokenmode - Modify
FlexBreakto always use unbroken inForcedUnbrokenmode
- Wrap the interpolation expression in
Assistant
Now I understand the issue clearly. The
format_stringfunction wraps interpolation expressions usingself.expression(e), which can produce multiline output when the expression is complex (like a method call with multiple arguments that exceeds the 80-character line width).The fix involves two changes:
- Modify the
formatfunction to handleFlexBreakinForcedUnbrokenmode by always using the unbroken version (so pipelines also stay on one line) - Modify
format_stringto wrap interpolation expressions innext_break_fits(false)to setForcedUnbrokenmode
Let me implement these changes:
- Modify the
Assistant
Now I'll implement the fix. The fix requires two changes:
-
In
lindig.rs: Modify theformatfunction to handleForcedUnbrokenmode properly - groups should not evaluate for breaking, andFlexBreakshould always use the unbroken version. -
In
expression.rs: Modify theformat_stringfunction to wrap interpolation expressions innext_break_fits(false).
Let me start with
lindig.rs:-
Assistant
The fix needs to:
- Modify the
FlexBreakhandling informatto always use unbroken inForcedUnbrokenmode - Modify the
Grouphandling informatto not evaluate groups when inForcedUnbrokenmode - Modify
format_stringto wrap expressions innext_break_fits(false)
Let me make these changes:
- Modify the
Assistant
Now I'll implement the fix. I need to:
-
Modify
lindig.rsto handleForcedUnbrokenmode properly:- Groups should pass through without evaluating for breaking
FlexBreakshould always use unbroken inForcedUnbrokenmode
-
Modify
expression.rsto wrap interpolation expressions innext_break_fits(false)
-
Assistant
Let me check if the sed command worked correctly by viewing the file.
Assistant
The sed command created a syntax error. Let me fix the file properly by rewriting the affected section:
Assistant
Let me take a more careful approach. I'll read the file and make precise edits using the
editcommand with proper syntax.The issue is in
lindig.rsandexpression.rs:-
In
lindig.rs, I need to:- Modify the
formatfunction to handleFlexBreakinForcedUnbrokenmode by always using the unbroken version - Modify the
Grouphandling informatto not evaluate groups when inForcedUnbrokenmode
- Modify the
-
In
expression.rs, I need to:- Modify the
format_stringfunction to wrap interpolation expressions innext_break_fits(false)
- Modify the
Let me read the file carefully and make the changes step by step.
-
Assistant
Let me implement the fix more carefully. I'll modify the
formatfunction inlindig.rsto properly handleNextBreakFitswithenabled = falseandForcedUnbrokenmode, and then updateformat_stringinexpression.rsto wrap expressions innext_break_fits(false).Assistant
I need to make two changes to fix this issue:
-
In
lindig.rs: Modify theformatfunction to handleForcedUnbrokenmode properly - groups should not evaluate for breaking, andFlexBreakshould always use unbroken. -
In
expression.rs: Modify theformat_stringfunction to wrap interpolation expressions innext_break_fits(false).
Let me implement these changes step by step:
-
Assistant
Let me implement the fix properly. I'll modify both files carefully:
Assistant
Now let me implement the fix. I need to:
-
Modify
lindig.rsto handleForcedUnbrokenmode properly:FlexBreakshould always use unbroken inForcedUnbrokenmodeGroupshould not evaluate for breaking inForcedUnbrokenmode (pass through to inner docs)
-
Modify
expression.rsto wrap interpolation expressions innext_break_fits(false)
-
Assistant
Now let me verify the changes to lindig.rs:
Assistant
The replacement has some extra braces that need to be cleaned up. Let me fix this properly:
Assistant
Let me take a more careful approach to modify the file. First, let me see the exact content around the areas I need to change:
Assistant
Let me write a precise Python script to make the changes correctly:
Assistant
Let me verify the changes to lindig.rs:
Assistant
The FlexBreak change looks good. Now let me check the Group change:
Assistant
Good, the Group change also looks correct. Now let me verify the file compiles:
Assistant
Now I need to update the
format_stringfunction inexpression.rsto wrap interpolation expressions innext_break_fits(false):Assistant
Now I need to update the
format_stringfunction to wrap the interpolation expression innext_break_fits(false):Assistant
Let me verify the change to expression.rs and then test the fix.
Assistant
Now let me test the fix:
Assistant
The fix didn't work. Let me trace through the issue more carefully. Looking at the
formatfunction, I see that theNextBreakFitshandler doesn't change the mode:rustDocument::ForceBroken(document) | Document::NextBreakFits(document, _) => { docs.push((indent, mode, document)); }The
enabledparameter is only used in thefitsfunction, but theformatfunction just passes the document through without changing the mode. So theForcedUnbrokenmode is never actually set during formatting.Let me fix the
NextBreakFitshandler informatto actually set the mode:Assistant
The issue is that the
NextBreakFitshandler in theformatfunction doesn't actually use theenabledparameter to set the mode. Whenenabledisfalse, it should setForcedUnbrokenmode. Let me fix this:Assistant
Now let me add a separate handler for
NextBreakFits:Assistant
Good. Now I need to add a separate handler for
NextBreakFitsthat uses theenabledparameter:Assistant
Let me check if the changes were applied correctly:
Assistant
I see there's a duplicate
Document::ForceBroken(document)case. Let me fix this:Assistant
Let me take a more careful approach using Python to make the exact changes:
Assistant
Let me verify all the changes to lindig.rs:
Assistant
The lindig.rs changes look correct. Now let me verify the expression.rs change is still in place and then rebuild:
Assistant
Good, the expression.rs change is still in place. Let me now rebuild and test:
Assistant
Good progress - the method call case is now fixed! But blocks and match expressions still produce multiline output because they use
Document::Newlinewhich doesn't respectForcedUnbrokenmode. I need to modify theDocument::Newlinehandler to skip newlines inForcedUnbrokenmode.Assistant
I need to modify the
Document::Newlinehandler to skip newlines inForcedUnbrokenmode:Assistant
Let me verify the changes and test:
Assistant
All three test cases are now passing - the f-string interpolations are being kept on a single line. Let me now run the existing tests to make sure I haven't broken anything:
Assistant
Let me also run the format-related tests more specifically:
Assistant
The test failures show that my fix is too aggressive. The issue is that I changed the
NextBreakFits(document, true)handler informatto setForcedBrokenmode, which is breaking the existing behavior. I should only change the behavior fornext_break_fits(false).Let me fix this:
Assistant
Assistant
Let me search for how lambda expressions are formatted:
Assistant
Let me look at how Lambda expressions are formatted:
Assistant
Let me look at the lambda formatting function to understand why the closure block is being formatted differently.
Assistant
Let me look at the lambda formatting function to understand the behavior.
Assistant
I see the issue - my changes are affecting more than just f-string interpolations. The problem is that the
ForcedUnbrokenmode changes I made informatare being inherited by child groups. Let me check the current state and fix this more carefully.Assistant
The problem is clear now. I need to look at the failing tests more carefully:
Assistant
Let me continue investigating why the test is failing and ensure my fix is correct.
Assistant
Let me check the block function to see how it formats blocks.
Assistant
Assistant
The user wants me to revert the Group handling change in the format function. Let me do that properly.
Assistant
Let me verify the changes and test the fix.
Assistant
Good, the Group handling is now reverted. Let me run the tests again:
Assistant
Good progress! The
method_chain_two_callstest is now passing. But there are still 2 failing tests related to comments. Let me check what these tests are doing.Assistant
Let me create a test to see what's happening with these failing test cases:
Assistant
Assistant
Let me search for how comments and pattern entries are handled in the formatting:
Assistant
The issue is clear - my changes to skip
Newlinedocuments inForcedUnbrokenmode are too aggressive. Thenext_break_fits(false)is used informat_call_with_headfor ALL calls with spread or inlinable args, not just for f-string interpolations. This is causing the newline after comments to be removed.Let me revert all my changes to
lindig.rsand take a different approach. The fix should only affect f-string interpolations, not other uses ofnext_break_fits(false).Assistant
I need to take a completely different approach. The issue is that my changes to
ForcedUnbrokenmode are too aggressive and affect ALL uses ofnext_break_fits(false), not just f-string interpolations. Let me create a more targeted solution using a new document variant specifically for f-string interpolations.Assistant
Now I need to update the
format_stringfunction inexpression.rsto use.flat()instead of.next_break_fits(false). This will apply the Flat mode specifically to f-string interpolations, without affecting other uses ofnext_break_fits(false)elsewhere in the codebase.Assistant
Now I need to update the
format_stringfunction inexpression.rsto use.flat()instead of.next_break_fits(false):Assistant
Let me verify the changes to both files:
Assistant
Let me verify the lindig.rs changes are correct and then build and test:
Assistant
Let me check the lindig.rs file to make sure the Flat mode was added correctly.
Assistant
Good, the Flat mode has been added. Now let me verify the Document enum has the Flat variant and build the project:
Assistant
Let me try building and running the tests to see if my changes work correctly.
Assistant
I need to fix the compilation errors. The
Mode::Flatneeds to be handled in theStrictBreak/FlexBreakcases. Let me update the code:Assistant
The Flat mode needs to be added to the match statements in the fits function and format function. Let me update them:
Assistant
Now let me build and test the changes:
Assistant
The build succeeded. Now let me test the fix:
Assistant
Assistant
Let me search for
.flat()usage in the format crate:Assistant
I found the problem! The
sedcommand replaced ALL occurrences of.next_break_fits(false)with.flat(), including those informat_call_with_head. I need to revert those changes and only keep the one informat_string.Assistant
I see the problem now! The
sedcommand replaced ALL occurrences of.next_break_fits(false)with.flat(), including those informat_call_with_headwhich affect regular function calls. I need to revert those changes and only keep the one informat_string. Let me fix this:Assistant
Now let me make the specific change only to the
format_stringfunction:Assistant
Now let me only change the specific line in
format_string:Assistant
I need to be very careful with my sed command. Let me use a line-specific replacement to only change the exact line I want:
Line 241 is:
docs.push(self.expression(e));I want to change it to:docs.push(self.expression(e).flat());Let me use sed with line number to be precise:
Assistant
Let me verify the change is correct and only affects the format_string function:
Assistant
Let me check the current state of the file to verify the change:
Assistant
Now let me verify the fix by running the tests:
Assistant
The comment test cases now pass correctly. Let me run the actual format tests to confirm everything works:
Assistant
All format tests pass. Now let me update the fstring-test to verify the original issue is fixed:
Assistant
Excellent! The fix is working correctly. All f-string interpolations are now kept on a single line, which addresses the issue described in the bug report. Let me now run the full test suite to make sure everything is working correctly:
Assistant
Let me look at what's happening with the test failures. First, let me check if the failures are related to my changes or if they're pre-existing:
Assistant
The format tests all pass (292 passed, 0 failed). The other failures appear to be unrelated to my changes (they're emit tests, not format tests). Let me verify my changes are correct and complete by reviewing what I've changed:
Assistant
Let me review the final changes I've made:
Assistant
Let me review the complete changes to lindig.rs to make sure everything is correct:
Assistant
The changes look correct. Let me clean up by removing the test package I added and verify the final state:
Assistant
Now let me verify the final changes and run the tests to confirm everything is working:
Assistant
Let me run the format tests one more time to verify everything is working correctly:
Assistant
The fix is complete and all format tests pass. Let me summarize what I've done:
Summary of Changes
Problem
The Lisette formatter was rewriting f-string interpolations to multiline expressions that the compiler rejects. For example:
lisettef"You cannot use another ender pearl for {shared.format_duration( remaining, )}."Solution
I added a new
Flatdocument mode that forces the formatter to keep content on a single line. This is used specifically for f-string interpolation expressions.Changes Made
-
lindig.rs- Added a newFlatmode andFlatdocument variant:- New
Mode::Flatenum variant - New
Document::Flat(Box<Self>)variant
- New
-
Assistant
Let me create a quick test to verify the fix handles the exact case from the issue description:
Assistant
Let me fix the cargo configuration issue and try again.
Assistant
Good, rustup installed the stable toolchain. Let me run the test again using the workspace's toolchain:
Assistant
All 292 format tests pass. Let me verify the final state of my changes:
Assistant
The fix is complete and all tests pass. Let me submit my changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.