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 first map the repository and locate the formatter, interpolation handling, and relevant tests/configuration. Then I’ll reproduce the formatting behavior with the project’s existing tooling before making a focused source change.
- Assistant
The repository is a Rust workspace with editor integrations, so the behavior is likely in a formatter crate rather than Zed-specific configuration. I’ll inspect workspace members and search for formatting code and f-string/interpolation syntax nodes and diagnostics.
- Assistant
rgis unavailable, so I’ll use recursivegrep. I’ve locatedcrates/format; next I’ll read its expression formatter and syntax definitions, plus discover the formatter’s test harness and snapshots so the reproduction uses the same entry point as production. - Assistant
The defect is visible in
format_string: it inserts the normal expression document directly, and call documents contain break opportunities. When the surrounding line exceeds 80 columns, the pretty-printer can therefore put those breaks inside{...}, producing invalid source. I’ll now inspect call/dot formatting and the document algebra to determine the safest way to force interpolation expressions flat without affecting ordinary calls. - Assistant
The document engine already has a
ForcedUnbrokenmode, exposed indirectly byNextBreakFits(..., false). I’ll inspect its public methods and call formatting in full, then run a temporary formatter driver (or CLI if easier) against a long valid one-line f-string. This should both confirm the exact output and reveal whether comments or inherently multiline nested constructs need special handling. - Assistant
A forced-unbroken wrapper around each interpolation expression should select every break’s inline spelling even when the containing line exceeds 80 columns; overflowing is preferable to generating uncompilable code. Before changing it, I’ll reproduce with
lis formaton a temporary.lisfile containing the reported shape and then runlis checkon the formatter’s output to confirm the multiline interpolation diagnostic. - Assistant
The first sample stayed inline because the call’s closing parenthesis still fit before column 80; trailing f-string text does not influence that inner call group. The reported failure occurs when the interpolation call itself crosses the limit (often due to indentation or a longer argument). I’ll adjust only the enclosing nesting to trigger that boundary, then invoke formatting a second time: the lexer rejection on the generated file directly demonstrates the incompatibility without requiring semantic validity.
- Assistant
The reproduction exactly matches the issue and fails on the second format pass. Simply forcing soft breaks inline fixes calls, tuples, binaries, and chains, but I also need to account for hard
Newlinedocuments (for example block expressions) even though the lexer accepted their original one-line spelling. I’ll inspect how blocks and definitions encode statement separators and test representative valid one-line interpolation expressions before choosing between document flattening and source preservation. - Assistant
Valid interpolations cannot contain source newlines or line comments, and the reported formatter regression comes from soft break decisions. The existing document semantics deliberately preserve
ForcedUnbrokenthrough nested groups and ignoreForceBrokenat render time, so wrapping the interpolation expression withnext_break_fits(false)is the narrow, idiomatic fix used elsewhere in this formatter. Hard newlines are only emitted by inherently block-structured AST forms; changing those would require preserving unformatted source and is outside the “compatible calls/arguments” behavior requested. I’ll apply the wrapper and verify the exact reproducer, idempotence, nested calls, tuples, and multiple interpolations. - Assistant
The source change is minimal and passes diff validation. I’ll now reset the temporary reproducer to the original valid one-line input, format it twice, and verify that no newline occurs between interpolation braces. I’ll also exercise long multi-argument calls, nested calls/tuples, and multiple interpolations in one f-string to ensure forced-unbroken mode propagates through nested document groups.
- Assistant
The verification exposed an important document-engine detail:
next_break_fits(false)only affects lookahead infits; rendering treats it as transparent, so it does not enforce inline output unless encountered during a specific enclosing group probe. That explains why existing call usages differ from the needed invariant. I’ll add an explicitForceUnbrokendocument wrapper, handled symmetrically in both fit analysis and rendering, and use it only for f-string interpolation. This avoids changing the subtle semantics of existingNextBreakFitscall formatting. - Assistant
The explicit wrapper compiles under
cargo fmt --checkand is exhaustively handled in both document traversals. I’ll rerun the same reproduction from pristine one-line input; unlike the previous attempt, this should keep nested optional breaks inline even when far beyond the configured width and allow a second formatter pass. - Assistant
The second run revealed one more asymmetry: the renderer’s
Grouparm always replaces its incoming mode withUnbrokenorBroken, whilefitspreserves forced modes. Thus nested call groups discard the new invariant. I’ll align rendering with fit analysis by preserving both forced modes through groups; ordinaryUnbroken/Brokenbehavior remains unchanged, so this only activates under an explicit force wrapper. - Assistant
Forced mode now survives all nested groups. I’ll repeat the pristine-input/idempotence test and scan the output. If successful, I’ll then run the formatter specification suite and broader workspace checks.
- Assistant
The reported failure is now fixed: deeply indented and nested long interpolation calls remain one line, and formatter output parses and is idempotent on the second pass. Next I’ll identify the exact test package/filter commands, run all formatter specification tests, and run crate/workspace compilation tests to catch document-engine regressions.
- Assistant
The manifest shows the package is literally named
tests, so the first test command failed only because I guessed the package identifier incorrectly; no tests ran. I’ll rerun with the correct package and theformatname filter. - Assistant
The broad substring filter unintentionally included emit tests whose names contain
format_string; 338 relevant tests passed, while 11 emit snapshots failed because this environment’s Go formatter output differs globally (for examplefunc test ()), unrelated to the Rust change. Those runs created.snap.newartifacts, which I’ll delete as required. I’ll rerun only thespec::formatmodule (all formatter tests), then perform workspace compilation and inspect status/diff. - Assistant
All 292 formatter specification tests pass, the full workspace type-checks, and no snapshot artifacts remain. As a final quality pass, I’ll run Clippy on the formatter crate with warnings denied and review the final diff/status for accidental changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.