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
I'll start by exploring the repository structure to understand the codebase. Let's first get a high-level view.
- Assistant
Let's get a better view of the repository structure.
- Assistant
Let's examine the overall project structure more closely:
- Assistant
Let's explore the formatter module to understand how it handles f-strings and interpolation. The issue is about multiline f-string interpolation. Let's first look at the main formatter files.
- Assistant
Let's examine the format spec tests to understand what's expected:
- Assistant
Let's search for f-string related tests in the format spec:
- Assistant
Let me look at that test and also search for more fstring-related tests:
- Assistant
Let me also look for more fstring-related tests and snapshot files:
- Assistant
Let's look at the error case that was mentioned in the issue:
- Assistant
Let me look at the formatter code to understand how it handles f-string formatting. The issue is that the formatter is breaking f-string interpolation expressions across multiple lines, which the compiler then rejects. Let me examine the formatter code more closely.
- Assistant
No results from the format crate? Let's search more broadly.
- Assistant
Let me look at the lexer to understand how f-strings are tokenized and what multiline interpolation means:
- Assistant
Let me search for the specific error message:
- Assistant
Now let's look at the formatter code to understand how it handles f-strings. Let's start with the expression formatter since that's likely where the issue is.
- Assistant
Let me continue reading to see how f-strings are handled.
- Assistant
Now I can see the issue. In the
format_stringmethod, when we have aFormatStringPart::Expression(e), we push the expression directly without any constraints. If the expression is complex (like a function call with multiple arguments), the formatter may format it across multiple lines, which would cause the f-string interpolation to span multiple lines.Let me look at the test cases to see what the expected behavior should be:
- Assistant
Let me look at the lexer error for multiline interpolation to understand the exact error message:
- Assistant
Now I understand the issue. The compiler rejects multiline interpolation inside f-strings, but the formatter is allowing expressions to be formatted across multiple lines. Let me check if there are any existing tests for this issue in the format spec:
- Assistant
Let me continue exploring the codebase to understand the issue better and find a solution.
- Assistant
Let me check the existing format tests more broadly and the snapshot for the multiline fstring text test.
- Assistant
Let me look at the existing format_string snapshot to understand how the formatter handles format strings:
- Assistant
Let me look at the multiline fstring text roundtrip snapshot:
- Assistant
Now let me look at the lindig document model to understand how we can force single-line formatting:
- Assistant
Now I understand the issue better. The formatter uses a pretty-printing library (lindig.rs) that handles line breaking. When formatting f-strings, the
format_stringmethod usesself.expression(e)for the interpolated expressions, which can result in multiline output when the expression is complex (like function calls with multiple arguments).Looking at the lexer code, it checks if there's a newline between the interpolation start
{and end}, and if so, it errors with "f-string interpolations must be single-line".The fix should ensure that when formatting f-string interpolation expressions, they are kept on a single line. Let me look at how the formatter handles this:
- First, let me check if there's a way to force single-line formatting in the lindig library
- Look at how the formatter currently handles f-string expressions
- See if we need to modify the
format_stringmethod to prevent multiline formatting
Looking at the lindig library, I see there's a
Grouptype that tries to fit content on a single line, and if it doesn't fit, it breaks the content. We might need to use this or a similar mechanism to ensure f-string interpolations stay on a single line.Let me also check if there are any tests for this specific case:
- Assistant
Let me look at existing format_string tests to understand what's expected:
- Assistant
Let me create a reproduction script to see the exact issue:
- Assistant
Let me look at how
format_stringis currently working and create a test case: - Assistant
Let me look at the full
format_stringmethod: - Assistant
Now I understand the core issue. Let me look at how the call expression formatter works:
- Assistant
Let me look at the call function:
- Assistant
Now I understand the issue. The formatter's
format_stringmethod delegates expression formatting toself.expression(e), which can produce multi-line output for things like function calls. But the lexer/compiler rejects multi-line interpolations inside f-strings. I need to add aflattenmethod to theDocumenttype that forces all breaks to be their unbroken form.Let me first write a test to reproduce the issue:
- Assistant
Let me understand the test harness:
- Assistant
Let me look at how the
assert_format_snapshot!macro works. - Assistant
Let me look at how the assert_format_snapshot macro is defined.
- Assistant
Let me look at the macro definition.
- Assistant
Let me create a small reproduction script to see the actual behavior:
- Assistant
Let me find how to use the format crate directly:
- Assistant
Let me write a small test to reproduce the issue:
- Assistant
Let me check how to run a standalone test with the format crate. Maybe I can write a simple test using cargo test.
- Assistant
Let me write a small test that creates a temporary test file using the test framework. First let me check if there's an example of how to use format_source in the test suite:
- Assistant
Let me write a simple script to test the issue. I'll use cargo test with a test that we'll remove later.
- Assistant
Let me just add a test directly to the tests directory and run it:
- Assistant
Let me find the test target.
- Assistant
Let me look at the call formatter more carefully to understand what happens when an expression is formatted inside a function call.
- Assistant
Let me look at how
next_break_fitsis used in the codebase: - Assistant
Let me look at how
next_break_fitsis used in the call formatter: - Assistant
Let me look at how
force_breakis used: - Assistant
Now I have a clear understanding of the issue. Let me look at the lindig document model more closely to understand how to implement a proper fix:
- Assistant
Now I understand the architecture. The core issue is:
- The formatter's
format_string()method callsself.expression(e)for interpolation expressions - The expression formatter can produce documents with
Group/StrictBreak/FlexBreakthat may break across lines - The f-string interpolation
{...}must be single-line (lexer rejects multiline) - We need to force the expression inside
{...}to never produce line breaks
The cleanest solution is to add a
flattenmethod toDocumentthat recursively converts all breaks to their unbroken form, then use it informat_string.Let me implement the fix:
- The formatter's
- Assistant
Now let me add the
flattenmethod toDocumentand modifyformat_string: - Assistant
Let me open the file and look at the full lindig.rs to understand where to add the flatten method.
- Assistant
Let me look at the rest of the file to understand the format function and then add the flatten method.
- Assistant
Now I have a clear understanding of the issue. Let me examine the key areas:
- Assistant
Wait, I need to close the currently open file first. Let me continue exploring.
- Assistant
Now I have a complete understanding of the issue. Let me create a test to reproduce it first:
- Assistant
Let me now reproduce the issue by creating a test that demonstrates the problem:
- Assistant
Let me try a different approach - write a simple test within the test suite:
- Assistant
Let me just add a simple test to the test suite and run it directly:
- Assistant
Let me add a test case directly and run it to see what happens:
- Assistant
Let me directly write a small test into the existing test file and run it:
- Assistant
Let me try a simpler approach - just add the test and run it. First, let me add it to the end of the test file:
- Assistant
Let me add a test case to reproduce the issue:
- Assistant
Now I have a thorough understanding of the issue. Let me trace through what happens:
format_string()callsself.expression(e)for the interpolation expression- The expression formatter produces a
DocumentwithGroup/StrictBreak/FlexBreaknodes - When the document is rendered, Groups independently decide whether to break based on line width
- This causes the f-string interpolation
{...}to span multiple lines - The lexer rejects multiline interpolation
The fix: add a
flatten()method toDocumentthat converts all breaks to their unbroken form and removes all Group/Nest structure, then use it informat_string(). - Assistant
Let me add the
flattenmethod to theDocumenttype: - Assistant
Now I need to add a
flattenmethod toDocument. This method should recursively transform the document so that all breaks are replaced with their unbroken form, and groups/nesting are removed. Let me add this method. - Assistant
Now I'll add the
flattenmethod toDocument. This method should recursively transform the document tree so that all breaks are rendered unbroken (i.e., on a single line), which is needed for f-string interpolation expressions: - Assistant
Now I need to modify
format_string()to use.flatten()on the expression. Let me do that: - Assistant
Now I need to modify the
format_stringmethod to flatten the expression document before embedding it: - Assistant
Now let me build and test:
- Assistant
Good, it compiles. Now let me run the existing tests to see if my change breaks anything:
- Assistant
Many tests failed. Let me check what happened with the format tests specifically:
- Assistant
There are failures in emit tests related to format strings. Let me check what those failures look like:
- Assistant
The emit tests are failing, but they seem unrelated to my formatting change (the output shows Go code emission issues, not formatting). Let me verify by checking if these tests were already failing:
- Assistant
Good - the emit test was already failing before my change. Let me restore my changes and focus on format tests:
- Assistant
Good - those emit tests were already failing before my changes. Let me focus on format tests only:
- Assistant
All 292 format tests pass. Now let me write a test to verify my fix works correctly. Let me add a test case that reproduces the issue:
- Assistant
Let me verify that the fix works by writing a small script that tests the specific case from the issue:
- Assistant
Let me write a verification script:
- Assistant
The Rust toolchain isn't set up outside the lisette directory. Let me check how to run Rust tools in the lisette project.
- Assistant
Let me just use the existing test infrastructure. I'll run a quick inline test:
- Assistant
Let me find the correct library paths:
- Assistant
Let me try a simpler approach - just add a test case to the existing test file temporarily and run it:
- Assistant
Let me just use cargo test with a temporary test. I'll add a test at the end of the format module file, run it, and then remove it:
- Assistant
The test output shows the interpolation is on a single line - exactly what we want! The test failure is just because there's no snapshot yet. Let me accept it:
- Assistant
The output shows the interpolation is on a single line. Let me also add more test cases to verify edge cases:
- Assistant
The
|isn't being properly interpreted. Let me run them separately: - Assistant
Good - the interpolation stays on a single line even for long expressions. Let me check the multiple interpolation case:
- Assistant
All the test outputs show the interpolations stay on a single line. The test failures are just because there are no existing snapshots. Let me now clean up the temporary tests I added and verify the existing format tests still pass:
- Assistant
Let me clean up the .snap.new files and make sure existing format tests pass.
- Assistant
All 292 format tests pass. Let me also run the formatter-specific tests:
- Assistant
Let me also run the lex tests since they test the multiline interpolation error:
- Assistant
Let me also check if there are any other format-related tests I should run:
- Assistant
Let me verify the full test suite excluding the known failing emit tests:
- Assistant
All 2101 tests pass. Let me also run the formatter unit tests:
- Assistant
Let me also run the format tests specifically one more time:
- Assistant
All 292 format tests pass. Let me review the changes I made:
- Assistant
The changes look clean and minimal. Let me also make sure there are no .snap.new files left:
- Assistant
Good, no .snap.new files. Let me also verify the changes compile correctly:
- Assistant
Let me also verify the release build works:
- Assistant
Let me also run the full test suite one more time to make sure nothing else is broken by my change:
- Assistant
The 1588 failures are the pre-existing emit tests. Let me verify that the failures are only in the emit tests:
- Assistant
Let me check if those tests were also failing before my change by stashing and running:
- Assistant
Same number of failures before and after my change. Let me restore my changes:
- Assistant
The 1588 failures are all pre-existing (in the
spec::buildandspec::emittests). My changes only affect the format tests, and all 292 of those pass. Let me now clean up any remaining .snap.new files and verify one more time. - Assistant
Let me now review the final diff to make sure everything is clean:
- Assistant
The diff looks clean and minimal. Let me now submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.