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.
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.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
- Assistant
I’ll first inspect the repository structure and locate the formatter implementation, grammar, and relevant tests. Then I’ll reproduce the formatting behavior with the project’s existing tooling before making a targeted change.
- Assistant
The repository is a Rust workspace with editor integrations and compiler crates. I’ll identify formatter-related crates and search for f-string/interpolation formatting and line-breaking logic, as well as snapshot tests that can demonstrate the regression.
- Assistant
ripgrepis unavailable, so I’ll usegrep. The formatter has a dedicated crate; I’ll inspect its AST formatting branches and test organization, then determine how interpolated strings are represented by the parser. - Assistant
The likely defect is clear:
format_stringdelegates each interpolation expression to the normal pretty-printer, whose grouped call documents may break at the global width. I’ll inspect that function, call formatting, document grouping semantics, and formatter test harness to decide whether interpolation expressions should be rendered atomically/flat while still preserving comments and nested syntax. - Assistant
There is already a
ForcedUnbrokenrendering mode in the document engine, so the safest fix may be to expose/use an “unbreakable” wrapper for interpolation documents rather than flattening documents into strings manually. I’ll inspect how that mode is entered and review formatter fixtures/macros to reproduce the exact issue through the public API. - Assistant
The shell interpreted
!in the search pattern, so I’ll rerun the inspection using safely quoted patterns. - Assistant
The existing forced mode is only used during fit prediction and does not directly suppress nested
Groupdecisions during rendering, so I won’t rely on it without validating behavior. I’ll reproduce using the CLI’s format command (or a temporary external Rust driver if necessary), inspect the call document construction, and establish whether wrapping the whole interpolation in one group can force all nested groups flat. - Assistant
I’ll now create a temporary
.lisfile containing the reported single-line interpolation near/over the 80-column width, run the actual formatter, show the rewritten output, and then run the compiler on that output to confirm the lexer rejection. Temporary files will stay outside the repository. - Assistant
The exact sample at two-space indentation is just within the formatter limit, so it remains valid; this confirms the bug is width/context dependent. I’ll increase nesting or argument length enough to trigger the automatic call break. Since
format_sourcelexes before formatting, formatting the result a second time is also a direct compiler-front-end reproduction even though Go is unavailable. - Assistant
The regression is reproduced: a slightly longer prefix causes formatting to emit a multiline call, and a second formatter/check pass rejects its own output with the same parse error. I’m considering the full invariant, not just calls: some expression documents contain unconditional newlines (pipelines, blocks), so merely forcing width-dependent breaks flat would still allow invalid output. I’ll inspect comment/source retention and expression spans to see whether the robust approach is to format interpolation normally when it stays one line, but fall back to the original lexer-approved single-line expression whenever normal formatting would introduce a newline.
- Assistant
A robust strategy is available without changing the pretty-printer globally: render each interpolation expression independently at effectively unlimited width, making the resulting text atomic in the enclosing f-string. This keeps normal canonical formatting (spacing, calls, nested expressions) while preventing outer line width from splitting it. For expression forms whose canonical formatter inherently emits newlines, I’ll retain the original single-line source slice accepted by the lexer. I’ll verify span boundaries and add a narrow source-slice helper to
Comments. - Assistant
I’ll inspect the exact
Spanand interpolation definitions, then implement the helper and interpolation rendering. The fallback will be limited to documents that still contain a newline at unlimited width, avoiding broad preservation of unformatted input. - Assistant
The AST span is byte-based and includes the complete expression, so the fallback can safely borrow the exact original expression. I’ll add a crate-private span slice method and change
format_stringto atomically append either the unlimited-width canonical expression or, only if that remains multiline, its original single-line source. - Assistant
The line-based edit used stale line numbers after the import insertion and accidentally overwrote the constructor tail; it also consumed one closing brace in
format_string. I’ll immediately restorecomments.rsand reapply via exact text replacement, then repair the missing match brace and re-run formatting/diff validation. - Assistant
The source now parses and formatting/diff checks pass. I’ll compile the formatter/workspace test target, rerun the exact width-triggering reproduction twice to verify idempotence/front-end acceptance, and probe edge cases: multiple arguments, multiple interpolations, nested calls, and a pipeline whose normal formatter uses unconditional newlines (exercising the source fallback).
- Assistant
The reported failure is fixed: the formerly broken call remains on one line, and a second parse/format pass succeeds. The edge probes also remain valid and idempotent, including the unconditional-newline pipeline fallback. I’ll now run the existing formatter snapshot suite and broader crate tests. I’ll first identify the test binary/filter names, then execute the relevant formatter tests and syntax/format-adjacent workspace tests.
- Assistant
The test package is named
tests, notlisette-tests; the failed command did not run any tests. I’ll rerun with the correct package and formatter module filter, then run the syntax crate tests (the format crate intentionally disables its own unit-test target). - Assistant
All 292 existing formatter snapshots pass, and syntax-related compilation/tests pass. I’ll add a concise rationale comment so future changes do not reintroduce context-sensitive breaking, then run the specific lexer diagnostic test (if present), workspace formatting/checks, and inspect the final diff/status for unintended files.
- Assistant
The targeted lexer diagnostic test passes, confirming the compiler still correctly rejects genuinely multiline interpolations while the formatter no longer creates them. I’ll clarify the fallback behavior in the comment, run Clippy for the changed crate and a workspace check, then perform one final idempotence reproduction and status review before submission.
- Assistant
All static validation passes, including
cargo clippy -D warningsfor the changed crate andcargo check --workspace. I’ll do the final regression run from fresh input, assert the interpolation call is not split, assert the second formatter pass accepts it unchanged, and verify only the two intended source files are modified.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.