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
I'll start by exploring the repository to understand its structure and locate the formatter code. Let's first look at what's in the current directory.
- Assistant
Let me first explore the repository structure to understand how the formatter works and where f-string formatting is handled.
- Assistant
Let me look at the format crate more closely, particularly the formatter.rs and expression.rs files since the issue is about f-string formatting.
- Assistant
Let me examine the formatter expression handling and the interpolation checker to understand the constraints.
- Assistant
Let me look at the formatter expression file first.
- Assistant
Now let me look at the interpolation checker:
- Assistant
This file is about checking interpolation type correctness, not about multi-line. Let me search for the error message about multi-line f-string interpolation.
- Assistant
Let me look at the lexer errors file to find the "Multi-line f-string interpolation" error.
- Assistant
Let me see the full context of this error in the lexer.
- Assistant
Now let me look at the lexer code to see how multiline interpolation is detected:
- Assistant
Let me look at the lexer code around those lines to understand how it detects multiline f-string interpolation.
- Assistant
Now let me look at how the
Documentandlindigformatting engine works: - Assistant
Now let me understand the call formatting code:
- Assistant
Let me look at the call method.
- Assistant
Now I have a good understanding of the issue. The
format_stringmethod in the formatter creates aDocumentfor the expression inside{...}which can contain line breaks (e.g., fromstrict_breakin call arguments). When the line is long, these breaks activate, producing multiline f-string interpolation which the lexer rejects.The fix should ensure the expression inside f-string interpolation is always rendered on a single line. Let me also check what the
formatmethod's line limit is: - Assistant
Let me check how the formatter runs and what tests exist:
- Assistant
Let me look at the test suite for formatting to understand the patterns:
- Assistant
Let me search for existing format string tests:
- Assistant
Let me look at those tests:
- Assistant
Let me look at the multiline roundtrip tests too.
- Assistant
Let me look at the existing format string snapshots:
- Assistant
Let me look at the format test snapshots:
- Assistant
Let me search for the specific format_string snapshot.
- Assistant
Let me look at these snapshots:
- Assistant
Now I need to understand the issue. The problem is that in the
format_stringmethod, the expression inside{...}gets formatted with line-breaking rules from the regular expression formatter. When a call expression with arguments is long enough, the formatter breaks it across multiple lines, but the lexer rejects multi-line f-string interpolations.Let me first try to reproduce the issue by creating a test file:
- Assistant
Let me look more closely at how the document renders and whether we can simply force single-line formatting. Let me also look for how
to_pretty_stringis used: - Assistant
Now let me look at the snapshot test harness to understand how tests work:
- Assistant
Let me find where the macro is defined:
- Assistant
Let me look at this macro to understand how to create a test.
- Assistant
Now I understand the problem. The
format_stringmethod inexpression.rspasses the expression throughself.expression(e)which can produce multiline output when calls have long arguments. The document system (lindig) can break them across lines, but the compiler lexer rejects multiline f-string interpolation.Let me look for any use of
force_breakin the formatter: - Assistant
Now let me look at the call formatting more closely to understand how it introduces line breaks:
- Assistant
Now I understand the issue. The
format_stringmethod directly embeds the expressionDocumentwhich can contain line-breaking constructs (strict_break,nest,group). When the formatter decides the line is too long, these breaks activate, creating multiline f-string interpolation that the lexer rejects.The fix needs to ensure that interpolation expressions inside f-strings are always rendered as single-line. Let me implement the fix:
- Assistant
Now I have a clear understanding of the issue. The
format_stringmethod embeds the expressionDocumentdirectly, which contains groups withstrict_breakandnestfor function call arguments. When the formatter evaluates these groups and the line is too long, the groups break, producing multiline f-string interpolation that the lexer rejects.The fix: render the interpolation expression to a single-line string using
to_pretty_stringwith an effectively infinite line width limit, then embed that string as a flatDocument::string. This ensures the expression is always single-line.Let me implement the fix:
- Assistant
Now I understand the issue clearly. The
format_stringmethod passes the expression throughself.expression(e)which creates aDocumentwith potential line breaks (viastrict_break,nest,groupin call arguments). When the document is rendered with the 80-character line limit, these breaks can activate, producing multiline f-string interpolation that the lexer rejects.The fix: render the expression to a single-line string first (using an effectively infinite line width to prevent breaks), then embed it as a flat
Document::string. - Assistant
Good, the edit is applied. Now let me build and run the existing format tests to ensure I haven't broken anything:
- Assistant
All 292 format tests pass. Now let me create a test to verify the fix works for the specific issue reported - a long f-string with a function call:
- Assistant
Good, existing format string tests still pass. Now let me write a test script to verify the fix handles the specific case from the issue:
- Assistant
Let me write a simple Rust script to test the fix:
- Assistant
Let me use the format crate's test infrastructure directly:
- Assistant
Let me check the package name:
- Assistant
Let me write a quick test script to verify the fix works:
- Assistant
Let me check the directory structure:
- Assistant
Let me try a different approach - write a quick test using the existing test infrastructure:
- Assistant
The fix works. Let me also test with a longer expression that would definitely trigger wrapping:
- Assistant
All 5 tests pass. Let me clean up the test file and run the full test suite:
- Assistant
Now let me run the full test suite:
- Assistant
Let me check what kinds of failures we're seeing:
- Assistant
These are build tests - let me check if these are pre-existing failures unrelated to my change:
- Assistant
All 292 format tests pass. Let me verify the build test failures are pre-existing:
- Assistant
Let me check if these build failures are pre-existing by looking at a specific failing test:
- Assistant
These seem like pre-existing snapshot failures unrelated to my change. Let me verify by reverting and checking:
- Assistant
Good - the build test failures are pre-existing (46 passed, 151 failed both before and after my change). Let me restore my changes:
- Assistant
The build test failures are pre-existing (same 46 pass / 151 fail before and after my change). Let me run the non-build tests:
- Assistant
Let me try running the format and other non-build tests:
- Assistant
Let me verify those emit failures are also pre-existing:
- Assistant
The emit test failures are also pre-existing (1437 failed before and after). Let me restore my change.
- Assistant
The build and emit test failures are all pre-existing (they fail before and after my change). These are likely snapshot tests that need updating with a Go toolchain. Let me run just the format tests which are what matters for my change:
- Assistant
All 292 format tests pass. Let me also run the lex and parse tests:
- Assistant
Let me also run the parser tests:
- Assistant
Let me also run the infer tests:
- Assistant
All relevant tests pass. Let me verify the final change:
- Assistant
The fix is clean and minimal. Let me verify the edge case of a method chain expression as well:
- Assistant
All 8 edge case tests pass. Let me clean up the temporary test file:
- Assistant
Let me run the format tests one final time to confirm everything is good:
- Assistant
All 292 format tests pass. Let me verify the final state of the change:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.