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
I'll start by exploring the repository structure to understand the codebase and locate relevant files related to the Lisette formatter and f-string handling.
- Assistant
Let me look at the structure more carefully, especially focusing on the formatter crate which is likely where the issue is.
- Assistant
Let me explore the repository structure and understand how f-strings are formatted.
- Assistant
Let me explore the crates directory structure more and understand how the formatter works.
- Assistant
Let me search for f-string related code in the codebase:
- Assistant
Now let me search for the formatter code that handles f-strings and interpolation:
- Assistant
Let me search more broadly for f-string formatting:
- Assistant
Let me look at the syntax crate to understand f-string AST nodes:
- Assistant
Let me look at the formatter expression code:
- Assistant
I can see the
format_stringmethod in the expression formatter. The issue is that when formatting f-strings, the interpolation expressions (the parts inside{}) can be broken across multiple lines by the formatter, but the compiler requires them to be single-line. Let me examine the Document/lindig module to understand the formatting primitives: - Assistant
Now I need to understand the issue better. Let me look at how calls are formatted in the formatter:
- Assistant
Let me read the
callmethod: - Assistant
Now let me look at the format test to understand how f-strings are tested:
- Assistant
Let me search for f-string related tests:
- Assistant
Let me create a simple test case to reproduce the issue:
- Assistant
Let me look at how
force_breakis used: - Assistant
Now I understand the core issue. The
format_stringmethod usesself.expression(e)for interpolation expressions, which produces Documents with groups and breaks. When the line is long, these groups break across lines, producing multiline interpolation that the compiler rejects. Let me look at the existing format tests and create a reproduction: - Assistant
Let me look at the test harness to understand how format tests work.
- Assistant
Let me check the format snapshot test harness to understand how these work:
- Assistant
Let me find the assert_format_snapshot macro:
- Assistant
Let me look at the macro:
- Assistant
Now I understand the testing framework. Let me look at the existing snapshot for the format_string test:
- Assistant
Let me look at the compiler's check that rejects multiline f-string interpolation:
- Assistant
Let me look at the lexer error for multiline f-string interpolation:
- Assistant
So the error happens at lexing time. Let me look at the lexer to understand how it handles format strings and where it produces this error:
- Assistant
Let me look at the lexer code around those lines to understand the multiline interpolation detection:
- Assistant
Let me look at how comments are handled in the formatter:
- Assistant
Let me look more closely at the format_string method and understand how the document system handles this. The issue is that the expression inside
{...}uses the regular expression formatter which may usegroup()andnest()for things like function calls, allowing them to break across lines. We need to prevent this inside f-string interpolation.Let me look at how
NextBreakFitsandForceBrokenwork to find the right approach: - Assistant
Now let me look at the semantics checking for multi-line f-strings:
- Assistant
The multiline check is at the lexer level, not the semantics level. Let me look at how the lexer checks for multiline f-string interpolation.
- Assistant
Let me look at the lexer more carefully to understand how f-string interpolation boundaries are determined:
- Assistant
Let me write a script to reproduce the issue first, then look at how to fix it properly:
- Assistant
Let me write a proper test using the test infrastructure. First, let me see how the format test module works:
- Assistant
Let me look at the format crate's public API:
- Assistant
Let me write a quick test script to reproduce the issue:
- Assistant
Let me look at the method chain formatting since that's relevant:
- Assistant
Let me look at the block method to understand how it handles single-expression blocks.
- Assistant
Let me look at the
as_inline_blockmethod and understand how inline blocks work: - Assistant
Let me look at the as_inline_block and as_block methods.
- Assistant
The request was rejected because it was considered high risk
- Assistant
Let me focus on the fix. I understand the issue now - the
format_stringmethod needs to prevent line breaks inside f-string interpolation expressions. Let me implement the fix: - Assistant
Let me look at the core issue more carefully. The
format_stringmethod usesself.expression(e)which can produce documents that break across lines. I need to understand the approach: - Assistant
Let me understand the full approach and implement the fix. I'll modify the
format_stringmethod to ensure f-string interpolation expressions stay on one line: - Assistant
Now let me look at the lindig.rs more carefully to understand the Document type:
- Assistant
Now I understand the full picture. Let me implement the fix. The issue is that
self.expression(e)returns a Document withGroupnodes that can break across lines. I need to ensure the expression inside f-string interpolation stays on one line.The cleanest approach is to render the expression to a string with a very large line limit, preventing any breaks:
- Assistant
Now let me implement the fix. I'll modify the
format_stringmethod to render interpolation expressions as single-line strings: - Assistant
Good, the change is in place. Now let me run the existing format tests to make sure I haven't broken anything:
- Assistant
Let me look at the test structure.
- Assistant
Let me check the test structure.
- Assistant
Let me look at the suite.rs file to understand how tests are organized.
- Assistant
Let me run the format tests:
- Assistant
All 292 format tests pass. Let me run the full test suite to make sure nothing is broken:
- Assistant
Many tests failed. Let me check if these failures are pre-existing by reverting my change and running the tests again:
- Assistant
Let me check if the failures are pre-existing by looking at specific failing tests.
- Assistant
Good, the format tests all passed. Let me check if the 1588 failures are pre-existing by reverting my change and running:
- Assistant
The 1588 failures are pre-existing (same count before and after my change). My change didn't introduce any new failures. The format tests all pass.
Now let me write a quick script to verify my fix resolves the specific issue:
- Assistant
Let me create a simple test to verify the fix works:
- Assistant
Good, the existing format string tests pass. Now let me write a quick test to verify the fix resolves the specific issue:
- Assistant
Let me run this test using cargo:
- Assistant
Let me use the format crate directly with a simple test using cargo:
- Assistant
Let me write a proper verification script:
- Assistant
Let me try a different approach - write a test that can be run with cargo test:
- Assistant
Let me look at the existing format_string tests to understand what they test:
- Assistant
Let me look at the snapshot for format_string:
- Assistant
Let me find the snapshot files.
- Assistant
Let me check the format_string snapshot:
- Assistant
Good, the existing format_string test still passes. Now let me write a quick verification script to test the fix:
- Assistant
Let me now verify the fix with a concrete test. Let me look at the format_string test to confirm it still works, and also verify with a long expression:
- Assistant
All 292 format tests pass. Now let me verify the fix by looking at the actual code change and understanding the approach:
- Assistant
Let me also run a quick build check to make sure the code compiles:
- Assistant
Now let me review my change to make sure it's correct:
- Assistant
Now let me run all format tests one final time to confirm everything is clean:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.