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 first map the repository and locate formatter/f-string handling and its tests. Then I’ll reproduce the reported formatting behavior, implement the narrowest general fix, and run the relevant test suite plus the reproduction.
- Assistant
The repository is a Rust workspace with no pre-existing changes. I’ll now identify the formatter crate, formatting entry points, fixture conventions, and parser representation of f-string interpolation so the fix can be made at the correct abstraction level.
- Assistant
ripgrepis unavailable, so I’ll use recursivegrep. The formatter is isolated incrates/format; I’ll inspect its API, implementation, dependencies, and nearby tests/fixtures before attempting a command-line reproduction. - Assistant
The critical code is
format_string: it currently embeds the ordinary expression document, whose groups may break at width 80. I’ll inspect that function, call formatting/group semantics, and the formatting harness/spec cases to determine whether the document engine already supports a forced-flat mode or whether one should be added. - Assistant
The document engine already has a
ForcedUnbrokenmode (seen in rendering), suggesting an existing wrapper can force all nested breaks to their inline spelling. I’ll inspect the omitted engine definitions and enumerate test suite directories; then I’ll use the workspace’s own CLI or a temporary example to reproduce exact output. - Assistant
NextBreakFits(false)only affects lookahead and does not force rendering of its own subtree, so it is not a suitable safety guarantee. A dedicatedForceUnbrokendocument wrapper is likely the clean solution: analogous toForceBroken, it should propagateForcedUnbrokenthrough nested groups and breaks. Before changing the engine, I’ll inspect existing formatter fixtures/macros and reproduce the reported input through the current format test mechanism or CLI. - Assistant
I found the formatter suite and confirmed f-strings currently have only a basic short case. Per the constraint, I won’t alter tests. I’ll reproduce with a temporary source file via the CLI, preserving the original file separately so I can compare current formatter output and then verify that the emitted output re-parses successfully after the fix.
- Assistant
The package is named
lisette(binarylis), notlisette-cli; the failed invocation left the reproduction untouched. I’ll rerun using the correct package and capture both the formatting result and the second-pass compiler/lexer rejection. - Assistant
This exact wrapper happens to land at the width threshold, so it does not trigger the bug; line width and indentation are relevant. I’ll quantify the line and create a slightly longer/nested compatible case, while retaining the same interpolation call shape. This tests the general width-driven behavior described rather than hardcoding the exact phrase.
- Assistant
The bug is now reproduced exactly: first formatting emits a multiline interpolation, and the second pass rejects it. I’ll implement a document-level forced-inline mode and apply it only to interpolation expressions. I’ll make nested groups and both strict/flexible breaks honor that mode; hard newlines remain hard because flattening those could alter syntax (e.g. block statement separators), but ordinary calls, tuples, slices, binary expressions, and nested groups will remain compiler-compatible on one line even when exceeding the preferred width.
- Assistant
The forced-inline wrapper is now implemented and scoped to interpolation expression documents. I’ll rerun the original failing reproduction and then exercise nested call arguments, slices/tuples, binary expressions, and multiple interpolations. Each case will be formatted twice; the second pass is the key validity check.
- Assistant
All width-driven edge cases now remain single-line and reparse successfully. I’m going to inspect expressions that inherently format as structured blocks (
match, block lambdas, etc.) because a valid interpolation starts single-line but those formatters may emit hardNewlinedocuments. If such syntax can occur in interpolation, the same compiler invariant should be preserved rather than fixing only calls. - Assistant
The structured probe exposed the broader invariant:
matchand block-lambda interpolations are valid on input but still become multiline because their documents contain mandatory newlines. A generic newline-to-space conversion is unsafe (blocks require semicolons; match arms already use commas). The robust approach is to preserve the original single-line interpolation expression text verbatim, but only if formatter context can access source spans. I’ll inspectFormatterconstruction and usages to see whether adding source access can remain internal with no public-interface change. - Assistant
Commentsalready retains the original source with the same lifetime as the AST, so no constructor or public API change is needed. I’ll use a hybrid strategy: format and force-flat expressions composed of breakable documents; if the expression document contains a mandatory newline, fall back to that expression’s original (necessarily compiler-valid, single-line) source span. This preserves normal interpolation formatting while guaranteeing structured expressions are not rewritten into rejected syntax. - Assistant
The hybrid fallback is in place without changing any exposed formatter interface. I’ll now reset the structured fixture to its original valid one-line form, format it twice, and verify the width-driven reproduction again. Then I’ll run the formatter unit tests and snapshot suite.
- Assistant
Both the reported width case and the structured edge cases now survive two formatting passes. The library manifest disables its local test target, so
cargo test -p lisette-formatcorrectly had nothing to run. I used the wrong integration package name for snapshots; I’ll inspecttests/Cargo.toml, run the correct targeted suite, and also run Clippy/checks for the modified crate. - Assistant
Three unrelated snapshots regressed because I broadened existing
ForceBrokenlookahead behavior underForcedUnbroken; the engine already usesForcedUnbrokeninternally forNextBreakFits, so that change leaked beyond f-strings. I’ll restore the originalForceBrokensemantics. The new wrapper will still render its subtree inline; during outer lookahead, a nested forced break may conservatively make the outer group break, which is harmless and preserves existing behavior. I’ll also remove Insta’s generated.snap.newartifacts. - Assistant
After restoring the isolated semantics, all 292 formatter snapshots pass. I’ll run the full integration
suite(covering lexer/parser interactions as well as formatting), Clippy on the changed crate, and final diff/status checks. I’ll also rerun the temporary reproductions after the latest engine adjustment. - Assistant
Clippy passed. The full suite exposed a repository/environment-wide snapshot mismatch (thousands of build/emit
.snap.newfiles, unrelated to formatter behavior—likely external Go/toolchain output); the targeted formatter suite had already passed cleanly. I’ll remove every generated snapshot artifact, confirm only the three intended source files remain changed, and inspect the final diff for accidental broad changes. - Assistant
The final diff is isolated and clean. I’ll make the source-range helper crate-internal and add a concise comment documenting the compiler invariant and why structured expressions use source preservation. Then I’ll do one last targeted formatter test and status check before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.