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 analyze the repository structure first to understand the codebase, then identify the issue and fix it.
Assistant
Now let me understand the issue. The formatter in Zed is rewriting single-line f-string interpolation to multi-line. Let me search for formatter-related code:
Assistant
Now let me understand the LSP server and formatter:
Assistant
Now let me understand what is happening here. The format_string function looks correct - it concatenates without forcing breaks. Let me check the
expressionfunction to see how it might force breaks for the call expressions inside f-strings:Assistant
Now let me look at
is_inlinable_arg:Assistant
Now I understand. The
format_call_with_headis used for the call expression. Now let me search for how the f-string is parsed in the syntax crate:Assistant
Now I understand the issue clearly. The formatter takes the source code, formats the f-string, and any sub-expressions inside the f-string get formatted using
format_call_with_headwhich has logic that can break across multiple lines.Looking at the formatter:
format_stringwritesf"..."and the inner expressions- For each inner expression, it calls
self.expression(e)which can format things multi-line if needed - In particular,
callandformat_call_with_headusegroup()which can break
But the issue is that when the formatter takes an already-formatted source like:
f"You cannot use another ender pearl for {shared.format_duration( remaining, )}."It appears the user has written this manually - but actually the formatter is generating it. Let me read again.
Wait - looking at the issue again:
- The user wrote single-line f-string interpolation
Assistant
So the formatter uses 80-char max line width. The issue is clear now:
- The user writes
f"x for {shared.format_duration(remaining)}." - The
format_call_with_headdecides whether to break (usinggroup()) - If the line is too long, it breaks to multi-line
- This breaks the f-string interpolation rule
Let me look at
next_break_fitsandgroup:- The user writes
Assistant
Now let me look at how the formatter's tests work and try to reproduce the issue:
Assistant
Let me look at the test macro
assert_format_snapshot:Assistant
Good. Now let me actually try to reproduce the issue:
Assistant
Let me write a script that mimics the formatter behavior to reproduce:
Assistant
Let me create a small test directly using cargo:
Assistant
Let me create a test inside the format crate directly:
Assistant
Now I have rust installed. Let me try to compile:
Assistant
That single-line format string is OK because it fits within the 80-char line limit. Let me try a longer one:
Assistant
I've reproduced the issue. The formatter breaks the call expression inside the f-string interpolation across multiple lines.
Now I understand the issue:
- The
format_call_with_headproduces agroup()that can break across multiple lines when the line is too long. - When this happens inside an f-string interpolation, the result is invalid Lisette code.
The fix should be in the
format_stringfunction: when formatting the inner expression of an f-string interpolation, we need to force the inner expression to NOT break across multiple lines.Let me check what kinds of expressions can be inside an f-string interpolation:
- The
Assistant
Now I see —
parse_expression()is called inside an interpolation. The expression can be anything that can be parsed (call, binary, etc.). It seems the issue is that the formatter allows breaks inside the call expression within the interpolation.Let me now think about the proper fix. The cleanest fix is in the
format_stringfunction — wrap the inner expression with something that prevents breaking.Looking at the existing primitives:
NextBreakFits(Box<Self>, bool): whenenabled = true, forces the next break to beForcedBrokenso the group breaks. Whenfalse, forces the next break to beForcedUnbroken.Group: tries to fit on one line; if not, breaks.ForceBroken: forces the contents to be broken.
What we need is something that ensures the expression inside
{}stays on a single line. The f-string interpolation rule is single-line interpolation only.Let me look at how the existing format_call_with_head deals with
next_break_fits:Assistant
Now let me check what happens at the top level with
Expression::Literaland look at how the whole expression containing the f-string is formatted:Assistant
Assistant
I now understand the implementation. So to force the inner expression to never break, I can wrap it with a
group()thennext_break_fits(false). Wait, that's the opposite of what we want.Let me think again. What I want is: when the inner expression (the call expression inside
{}) is formatted, itsgroup()calls should not break.Let me re-trace:
format_stringreturnsconcat(docs)where one of the docs isself.expression(call_expr).expression(call_expr)ends up incall()which callsformat_call_with_head.format_call_with_headends with.group(), and usesstrict_break("", "")which can break based on mode.
The mode is propagated from the outer group to the inner group. If the outer group is broken, the inner becomes unbroken (because of the
Mode::Broken => Unbrokenrule). If outer is unbroken, inner stays unbroken.But wait - the outer is the entire
expression()call which doesn't add a group. So mode should be Unbroken for the call's group...Assistant
Assistant
Now let me implement the fix. First, let me look at the current
format_string:Assistant
Now I need to think about what the right approach is. Looking at this more carefully, I think the cleanest fix is to wrap the inner expression in a way that prevents breaking.
Looking at
NextBreakFits, when called withfalse, it forces the contents to useMode::ForcedUnbroken. This is exactly what we want for f-string interpolations.Let me write a test first:
Assistant
My check isn't working but I can see in the output that the issue is reproduced. Let me think about the best fix.
Now I need to understand what
next_break_fitsactually does in the context. Let me write the fix:Assistant
Now let me apply the fix. The approach: wrap the inner expression with
next_break_fits(false)to prevent breaking. But wait, this would just propagate the unbroken mode to the inner content. Let me think about what would happen.When the f-string is being formatted:
- The outer context is unbroken (since there's no parent group).
- We push
{, thennext_break_fits(self.expression(e), false), then}. - The
next_break_fits(false)makes the inner content mode =ForcedUnbroken. - Inside, all
StrictBreaks use unbroken form. - Inside, all
Groups use the unbroken form.
Let me verify this would work with a test:
Assistant
Now let me apply the fix. I need to wrap the inner expression with something that forces it to be unbroken. Let me first look at all callers/usages of
format_string:Assistant
Now I'll think about this more. The fix should be in the
format_stringfunction. Let me apply it:The approach: Wrap the inner expression with
next_break_fits(false). This forces the inner expression to NOT break (because all strict breaks and groups inside are forced to use unbroken mode).But wait, there's a subtle issue: the mode is propagated through the document tree. If we wrap the entire expression in
next_break_fits(false), the expression's groups will be inForcedUnbrokenmode. But what about strict breaks that may be needed for the expression?Looking at
format_call_with_head:head.append("(") .append(strict_break("", "")) .append(body) .nest(INDENT_WIDTH) .append(close_sep) .append(")") .next_break_fits(false) .group()The
strict_break("", "")is between the(and the body. When mode isForcedUnbroken, it uses""as unbroken (empty string), so no newline is added.OK so wrapping the expression with
next_break_fits(false)should work. Let me apply it:Assistant
Now let me test:
Assistant
Hmm, the fix didn't work. Let me check why. The issue is that I'm rebuilding the format crate, but the cache might still have the old version. Let me check:
Assistant
Still doesn't work. Let me think about this more carefully.
The issue might be that
next_break_fitsonly affects how things fit (infits()), not the actual mode used. Let me trace through carefully:When
next_break_fits(content, false)is encountered in format():Assistant
Assistant
So
let s = ...is NOT wrapped in a group. So thenext_break_fits(false)inside the f-string doesn't have a parent group. Sofits()is only called on the innerGroup(the call expression's group).Let me re-trace:
- format_string produces:
concat([f", "{", NextBreakFits(call_doc, false), "}"]) - Where
call_doc = format_call_with_head(...)which is aGroup(...).
Wait, but my trace didn't match this. Let me check what
format_call_with_headreturns:- format_string produces:
Assistant
Assistant
The patch is in place. Let me verify by running the test:
Assistant
Assistant
OK this one is fine - the line fits in 80 chars. Let me try with a longer one:
Assistant
Assistant
Wait, there's a
strict_break("", "")at the beginning of the segment! Let me look:Assistant
Assistant
Assistant
Still not working. So my fix isn't actually preventing the breaking. Let me debug by looking at where exactly the breaking comes from.
The output shows breaking inside the call . So the inner Group is breaking. Why isn't my NextBreakFits preventing this?
Assistant
let_doesn't add a Group. So no Group above. Hmm.Wait, but
expressionIS called recursively. Let me look at the top-level formatting. Thelet s = ...is a top-level item in a function body. The body is wrapped byblock:Assistant
So
blockdoesn't add a Group either. The items are concatenated.Hmm. So where is the breaking happening?
Let me add some debug prints to understand. Let me check by writing a debug program:
Assistant
Let me add some print statements to understand the document tree:
Assistant
Let me add a debug print to understand the document structure for the failing case:
Assistant
Let me add a debug print to format_string to see the document tree:
Assistant
Assistant
OK so my fix isn't working because the
Group()inside the call expression is what gets checked for fitting, and myNextBreakFits(false)is outside it.Let me revert my debug print and think of a better approach:
Assistant
Assistant
Assistant
Assistant
Assistant
OK let me take a different approach. I'll add a new method
force_unbroken_inline()to Document that returns aGroupForceUnbrokenvariant. Let me implement this:Assistant
Hmm. Let me think more carefully. Actually the cleanest approach is to think about what the user wants:
- Inside f-string interpolation, the expression should be on one line.
So I want the formatter to ALWAYS inline the expression inside an f-string interpolation.
The way to achieve this: when the formatter formats an expression inside an f-string, it should NEVER produce multi-line output.
Implementation: a recursive helper that walks the Document tree and forces all Groups to be unbroken (i.e., all strict breaks use unbroken form, and the Group is essentially bypassed).
Let me implement this as a helper function. Actually, even simpler: I can add a method
force_inline()that walks the tree and replaces anyGroup(content)withcontentdirectly. This way, the Group is removed and the inner strict breaks use the default mode (Unbroken).Let me implement this:
Assistant
OK let me think differently. Let me try a more pragmatic approach:
Add a
force_inline()method to Document that walks the tree and removes Groups:pub fn force_inline(self) -> Self { match self { Self::Group(content) => content.force_inline(), Self::Sequence(vec) => Self::Sequence(vec.into_iter().map(|d| d.force_inline()).collect()), Self::Nest(_, content) => content.force_inline(), Self::NestIfBroken(_, content) => content.force_inline(), other => other, } }This recursively unwraps Groups, Nests, etc. Let me also think about whether this would mess anything up.
Actually, this could be tricky because Nest adds indentation. If I unwrap Nest, I lose the indentation. But inside an f-string, we don't want indentation changes because we want to stay on one line.
Actually for the f-string interpolation, we want everything on one line. So removing Groups (which trigger line breaks) and Nests (which change indentation) makes sense.
But what about NextBreakFits, ForceBroken, etc.? Those have specific semantics, so I should probably leave them alone.
Let me write this approach:
Assistant
Let me add a
force_inline()method and use it in format_string:Assistant
Now let me update
format_stringto useforce_inline():Assistant
Now let me test:
Assistant
The fix works. Now let me test more cases:
Assistant
The lambda case has a parse error (different issue, not related to my fix - it's that Lisette uses
|x| x * 2syntax for lambdas). Let me fix the test:Assistant
All cases work correctly! The spread test is unrelated to my fix - it's a parser issue.
Let me also verify idempotency - the formatting should be stable:
Assistant
Now let me also run the existing format tests to make sure I didn't break anything:
Assistant
There are some failures. Let me look at the actual failures:
Assistant
Hmm, this is interesting. The test is comparing the OUTPUT of
lis formatafter the input is processed. The test seems to expect:package main import "fmt" func test() { name := "Alice" fmt.Printf("Hello, %s!", name) }But we're getting a different output. Let me look at the actual test:
Assistant
These tests check the EMIT output, not just the format output. Let me look at
assert_emit_snapshot:Assistant
So
assert_emit_snapshotcallsemit::emit($input)which compiles the lisette code and emits Go code. Let me look at whatemitdoes:Assistant
OK so
emitruns the pipeline but doesn't run the formatter. So my changes to the formatter shouldn't affect the emit tests. The failures must be unrelated.Let me check what's happening. The output shows:
package main import "fmt" func test () { x := 7 fmt.Printf("prefix \", %d\n", x) }That's WEIRD. It seems like the formatter wasn't applied, and the parser misinterpreted the input. Wait, actually this is the EMIT output, not the format output. So this is showing what would happen if the input is directly emitted.
Hmm, but if my changes are to the formatter, why is the emit output different?
Wait, let me check if I changed something else. Let me look at the snapshot:
Assistant
So the expected output is
func test()(no space), but the new output isfunc test ()(with space). That's weird. The emit output shouldn't depend on the formatter.Let me check if maybe my changes broke something else. Let me revert my changes to format_string and run the failing tests:
Assistant
The test was ALREADY failing before my changes! So these failures are pre-existing and unrelated to my fix. Let me restore my changes:
Assistant
Let me clean up the .new files and run only the format tests:
Assistant
Good. Now let me run only the format tests:
Assistant
All 292 format tests pass. Now let me look at the pre-existing failures to confirm they're unrelated:
Assistant
Confirmed - the failure is pre-existing and unrelated to my fix. My fix passes all format tests.
Let me now also check that the fix doesn't break things in unexpected ways. Let me check what other tests might be affected:
Assistant
Let me also run the format tests for things related to my changes:
Assistant
All format tests pass.
Now let me also test the actual reproduction scenario more thoroughly. Let me create a test that mimics the issue:
Assistant
Now let me also test some edge cases that might be tricky:
Assistant
All cases work correctly. The comment test correctly errors out with the multi-line interpolation error.
Let me also verify the new test file passes by running through one more check:
Assistant
Let me also test that my fix works correctly when there's a multiline interpolation that the user wrote themselves (should be reported as an error):
Assistant
Good. The parser correctly rejects multi-line interpolation in source code. The formatter doesn't produce such invalid output anymore.
Now let me think about edge cases. What about a case where the interpolation expression itself contains a string with a newline? Wait, that's not allowed in a single-line interpolation. Let me check:
Assistant
Good, that's also rejected as expected.
Now let me also think about cases where
force_inlinemight be too aggressive. What if the inner expression has aNewline? Let me think...Actually
force_inlineonly unwrapsGroup,Nest,NestIfBroken, andSequence. It doesn't touchNewline,ForceBroken,Text,StrictBreak, etc. So if there's an explicitNewline(fromforce_breakor something), it stays.But in our context (f-string interpolation expression), there shouldn't be any explicit
Newlinefrom a force_break. Let me check if there's any case where a call expression might use force_break:Assistant
There's a
force_break()here for handling comments. Let me think about this case. If there's a comment in a method chain, force_break is used. With myforce_inline, would that break?force_break()wraps content inForceBroken. Myforce_inlinedoesn't touchForceBroken. So theForceBrokenremains.When format() encounters
ForceBroken:Document::ForceBroken(document) | Document::NextBreakFits(document, _) => { docs.push((indent, mode, document)); }Assistant
Wait, the output looks correct (single line) but my heuristic detects
{\nwhich is just the start of a block in another part of the file. Let me fix the heuristic:Assistant
No multi-line interpolations detected. My fix is working. Let me also think about whether
force_inlinecould affect things inside the expression.Let me think about a case where the call expression has nested Groups. For example,
outer(inner(x, y)):expression(outer(inner(x, y)))returnsGroup(...)for the outer call.- Inside,
inner(x, y)is alsoGroup(...). force_inline()on the outer Group: unwraps the outer Group, returns the content.- The content includes the inner Group.
- The inner Group still exists.
When format() processes this:
- The f-string sequence has the inner Group directly (no outer Group).
- The inner Group is processed: fits() is called with content.
- In fits(), strict breaks use unbroken form (because the outer mode is Unbroken).
- fits() returns true if the inner content + current width <= 80.
- If true, inner Group is unbroken.
- If false, inner Group is broken with mode Broken. Inner strict breaks use broken.
So even with my fix, inner Groups can still break!
Let me test this scenario:
Assistant
As I suspected, the inner Group still breaks. I need a more robust fix. The
force_inlineonly removes the top-level Group, but nested Groups can still break.I need to make
force_inlinerecursive into Group. But the issue is that the inner Group may be useful for OTHER purposes (like nesting indentation). Actually for f-string interpolation, we don't want any breaking at all.Let me think. The cleanest approach would be to recursively unwrap ALL Groups. Let me update
force_inlineto also recurse into the inner content:Assistant
My
force_inlineIS recursive. Let me re-check why it doesn't work for nested cases.For
outer(inner_call(...)):expression(outer(inner_call(...)))returns a Document tree.- The outer call returns
Group(content1). - Inside
content1, there'sheadwhich isexpression(outer).append(type_args). expression(outer)isIdentifier("outer")=Document::string("outer").- So
head= .
Assistant
Now nested calls also stay on one line. Let me test more edge cases:
Assistant
Most cases work, but the match expression still has multi-line output. Let me check what's happening with match:
Assistant
OK so
braced_bodycallsforce_break()at the end. This forces the entire content (including newlines) to break.So for
match, the format ismatch ... { \n arms \n }with a forced break.With
force_inline, my function recursively unwraps ForceBroken. But wait,force_break()creates aForceBroken(doc). When myforce_inlineencountersForceBroken, it recurses into content. But the content contains explicitNewlines which my function doesn't remove.Let me check:
Assistant
OK I can't access
lindigfrom outside. Let me think about this differently.The issue with match expressions is that they have explicit s inside them. My only handles structural wrappers (Group, Nest, etc.) but not the explicit and semantics.
Assistant
Assistant
So
join_sibling_bodyaddsDocument::Newlinebetween entries. These Newlines are explicit and force multi-line output.If I want
force_inlineto handle these, I need to remove Newlines or replace them with spaces.Assistant
Confirmed: the formatted output for match case is invalid Lisette. The re-formatting fails.
So I need to handle these cases too. Let me think about a comprehensive approach.
Looking at this, I think the right approach is to make
force_inlinemore aggressive: remove all explicitNewlines and unwrap all the structural wrappers. Let me update:Actually, let me reconsider. The simplest approach might be to:
- Define
force_inlineto remove explicitNewlines and unwrapNest,Group,ForceBroken, etc. - Use it in
format_stringfor the inner expression.
Let me try this:
- Define
Assistant
Hmm, but I think a more conservative approach is better. The match case is an edge case that the user probably shouldn't be using in f-strings anyway.
Let me think about the issue from the issue description's perspective:
- The example is
shared.format_duration(remaining)(a simple call expression). - The fix should handle this case.
My current fix DOES handle this case (call expressions, lambda, struct, etc.). The match case is an additional edge case.
But the match case IS a real problem because the formatter produces invalid Lisette code.
Let me look at what an "inline mode" would look like. I think the cleanest approach is:
When formatting inside an f-string interpolation, use a different version of the formatting that doesn't force multi-line output. This means:
braced_bodyshould not useforce_break()in inline mode.blockshould not use newlines.
But this is complex. Let me try a simpler approach: make
force_inlinemore aggressive by removingDocument::Newline:- The example is
Assistant
Assistant
Assistant
Even short match expressions are broken into multiple lines. The
braced_bodyusesforce_break()which always forces a break.So my fix needs to handle this case too. Let me think about the cleanest way.
Approach: Make
force_inlinealso remove explicitNewlines. This is more aggressive but ensures single-line output.Let me update:
Assistant
Let me think about this. I want to minimize the impact of my changes. Let me look at the actual behavior more carefully.
For the simple case in the issue (
shared.format_duration(remaining)), my fix works. For more complex cases like match, the fix doesn't work because uses .Assistant
Ahh, the input itself is INVALID (because the user wrote multi-line interpolation in the source). My fix doesn't make the source valid.
But if the user writes the SINGLE-LINE version:
Assistant
My fix correctly handles the original case.
Now let me think about the match case. Should I also fix that?
Looking at this:
- The original issue is about call expressions.
- My fix handles the call expression case.
- The match case is a separate issue (formatter produces invalid Lisette for match inside f-string).
Let me decide whether to fix the match case too. Pros: more comprehensive. Cons: more invasive change.
Actually, I think for completeness, I should fix the match case. Let me also remove explicit Newlines in
force_inline:Assistant
Hmm, the match case is now on one line but the output is
match x {1 => "one",2 => "two",_ => "other",}which is missing spaces. Let me check if that's valid Lisette:Assistant
OK that's valid (it parses and re-formats idempotently). It's ugly but valid. Maybe I should add spaces between elements.
Actually, let me reconsider. My current implementation removes all Newlines, which can result in things being run together. Let me think about a better strategy.
Instead of removing all Newlines, maybe I should replace them with spaces, or use separators based on context.
Actually, let me think about what the user EXPECTS. The match expression in f-string is unusual. The user probably knows they need to refactor. So maybe it's OK to produce weird output for match.
But the OUTPUT is valid Lisette (which is the requirement). So my fix achieves the goal.
However, the ugly output is not ideal. Let me see if I can improve it by replacing Newlines with spaces:
Actually, looking at the issue more carefully:
- The original issue is about call expressions.
Assistant
The match body is constructed by
join_sibling_body, which usesDocument::Newlineto separate entries. There's no separator (like,) in the body — the separator is part of each arm's doc.Let me look at the match arm formatting:
Assistant
OK so each match arm has a
,at the end. The join_sibling_body puts Newlines between arms.With my
force_inlineremoving Newlines, the arms run together with no space.For better output, I could replace Newlines with spaces (or
,if I can detect the context). Let me change to replace Newlines with spaces:Actually, let me just use a space for simplicity. Let me think about other places where removing Newlines could cause issues.
In
block:Document::Newline.append(body).nest(INDENT_WIDTH)If I remove this Newline, the body would be directly after
{. That might look like{let x = 1; x}. Let me check if that's valid.Actually, blocks in Lisette use
{ ... }syntax. Without spaces, it'd be like{let x = 1; x}which is a single line block.Let me check:
Assistant
OK that works. Let me also test the original simple cases:
Assistant
All cases are valid and idempotent. The match case has
match x {1 => "a",}which is a bit ugly but valid.Now let me check that all existing format tests still pass:
Assistant
All 292 format tests pass.
Now let me look at the change carefully:
Assistant
Let me also reconsider. I'm worried that the Newline removal might be too aggressive and cause issues elsewhere. Let me check if removing Newlines is the right approach.
Actually wait, I just realized: I'm removing Newlines only in
force_inlinewhich is only called for f-string interpolation expressions. So it shouldn't affect other places.Let me also think about whether
force_inlinecould leave a sequence with only newlines (resulting in empty sequence). That's fine - an empty sequence renders as nothing.OK my fix should be safe. Let me also consider whether removing the
ForceUnbrokenvariant (which I added but don't use) is appropriate. Let me check if it's needed.Looking at my changes:
- Added
ForceUnbrokenenum variant. - Added handler in
fits()andformat(). - Added
force_inline()method. - Updated
format_stringto useforce_inline().
The
ForceUnbrokenvariant is NOT actually used byforce_inline()(since unwraps it). So it's dead code. Let me remove it.- Added
Assistant
Cleaner now. Let me verify the tests still pass:
Assistant
All format tests pass.
Now let me think about the original problem one more time. Let me re-read the issue:
Formatter rewrites Lisette f-strings to multiline interpolation that the compiler rejects
So the issue is specifically about the formatter producing invalid output. My fix:
- For simple cases (call, binary, lambda, struct, etc.): keeps the f-string interpolation on one line.
- For complex cases (match, etc.): also keeps on one line (even if ugly).
Let me also think about the alternative: what if I DON'T remove Newlines, but instead just unwrap Groups and other structural wrappers? This would leave the simple cases working but the match case still broken.
Actually, looking at the test cases, I see that the issue is specifically about call expressions. The match case is an edge case. Let me think about whether to handle it.
If I keep the Newline removal, my fix is more comprehensive. The risk is breaking other tests. Let me check.
Let me run a broader test:
Assistant
Hmm, many tests fail. Let me check if these are pre-existing failures:
Assistant
Same numbers of failures (3691 passed, 1588 failed) before and after my changes. So these are pre-existing failures, not caused by my fix. Let me restore my changes:
Assistant
Good. My changes don't break any existing tests.
Now let me also look at other places where the formatter might be called. Let me also think about whether my fix could affect the formatting in other ways (e.g., when the f-string has multiple expressions).
Let me also think about an edge case: what if the inner expression contains a string with a newline?
Assistant
Good - the parser correctly rejects multi-line f-string interpolation in the source.
Let me also think about the case where there's a
Document::VerbatimTextwith a newline (like raw strings with newlines). Myforce_inlinedoesn't remove those. Let me check:Assistant
VerbatimText produces newlines if the string contains them. My
force_inlinedoesn't remove these. So if a VerbatimText with a newline is inside an f-string interpolation, the output would have a newline.But wait, can a VerbatimText be inside an f-string interpolation? Yes, if the user has a raw string with newlines. But the parser would reject this (multi-line f-string interpolation).
So in practice, VerbatimText with newlines shouldn't appear inside an f-string interpolation in valid Lisette code.
Let me think about whether
force_inlineshould also handle VerbatimText. Probably not, since:- Such code is invalid Lisette.
- The user wouldn't write it intentionally.
OK I think my fix is good. Let me also look at the existing snapshot for the format_string test:
Assistant
Let me also look at the formatter behavior for an edge case I missed: what if the inner expression has a
Document::VerbatimText? Let me check if that affects things.Actually, the test format_string_multiline_roundtrip exists. Let me look at it:
Assistant
OK so this test verifies that an f-string with multi-line text (using newlines in the text part) preserves the newlines. My fix doesn't affect this because I'm only changing how the inner EXPRESSION is formatted, not the text parts.
Let me also verify by running this test:
Assistant
Let me also test with the LSP to make sure I haven't broken anything there. Let me check the LSP tests:
Assistant
All LSP tests pass.
Let me also verify the syntax tests:
Assistant
Syntax tests pass.
Now let me also make sure the format crate's own tests pass:
Assistant
All format tests pass.
Now let me look at my changes one more time to make sure they're clean:
Assistant
The diff looks clean.
Wait, I noticed a comment in my fix says "If it would overflow the line width, we leave it as-is". Let me think about this. Actually, my fix DOES allow the line to overflow if needed. The
force_inlinejust removes Groups and Newlines, but if the actual text is too long, the line will be too long.Let me update the comment to be accurate:
Assistant
Now let me also think about another consideration. The
force_inlineremoves Newlines. This might cause issues if the inner expression has actual text that's supposed to be on a separate line (like comments).Let me check:
Assistant
Good, parser correctly rejects multi-line interpolation in source.
What about a single-line comment inside?
Assistant
OK that's a parser issue with comments inside f-string, not related to my fix.
Let me check what about a trailing comment after the call (still single line):
Assistant
OK basic case still works.
Let me also think about how my fix interacts with the
eprintln!debug code I added earlier. Let me check that I removed it:Assistant
Good, no debug code.
Let me also do a final check by running all format tests:
Assistant
All 292 format tests pass.
Let me also test the issue example one more time to verify:
Assistant
The fix works correctly:
- The f-string interpolation is kept on one line.
- The line might exceed 80 chars if necessary, but it's still valid Lisette.
- Idempotency is maintained.
The line being 104 chars in Test 2 is acceptable — better to have a long but valid line than to break the f-string interpolation.
Let me also think about whether removing the explicit Newlines is a problem for any non-f-string cases. Since
force_inlineis only called fromformat_stringfor f-string interpolations, it shouldn't affect other cases.Let me do a final comprehensive check by looking at all changes:
Assistant
The changes are minimal and focused on the issue. Let me summarize:
-
Added
force_inline()method toDocumentinlindig.rs. This method recursively unwraps structural wrappers (Groups, Nests, etc.) and removes explicit Newlines, forcing the document to render on a single line. -
Modified
format_stringinexpression.rsto useforce_inline()on the inner expression of f-string interpolations.
The result: the formatter no longer produces multi-line f-string interpolation, which would otherwise be rejected by the Lisette compiler.
Let me think about the checklist:
- ✅ Reproduced the error with a script.
- ✅ Confirmed my fix resolves the error.
- ✅ Thought about edge cases (match, lambda, struct call, etc.) and made sure the fix handles them.
- ✅ Ran existing tests (292 format tests pass).
Let me also verify with a final test that mimics the actual issue scenario:
-
Assistant
The issue is fixed.
Let me also check that I haven't accidentally broken the case where the f-string interpolation has a comment that should be on the same line:
Assistant
Comments outside the f-string are preserved correctly.
Let me also think about a subtle issue. When
force_inlineremoves theNewlines from a Sequence, the result might still haveDocument::Newlines deeper in the structure (because the recursion only handles top-level Sequence's Newlines). Let me think...Actually, my implementation calls
force_inlineon each element first, then filters out Newlines. So if an element contains nested Newlines (like in another Sequence), those would also be removed by the recursive call.Let me trace through a case like
match:match_()returns .
Assistant
The match case works (valid Lisette, idempotent). The output is a bit ugly but valid.
OK I think my fix is good. Let me also think about whether to use
Cargo.lockor anything else.Let me also do a final sanity check by running the format tests one more time:
Assistant
All format tests pass.
Let me also run the syntax tests to be thorough:
Assistant
Hmm, an e2e test fails. Let me investigate:
Assistant
The
e2e_learntest failed. Let me check what's happening:Assistant
This test runs
lis learnto scaffold a project, then runslis format --check. The format check failed, meaning the scaffolded project has files that don't match the formatted output.Let me see what's in the scaffolded project:
Assistant
Hmm! The formatter produced
f" [{self.tags.join(\n \", \",\n )}]"which is a multi-line f-string interpolation! Let me trace this.The line
f" [{self.tags.join(", ")}]"is being formatted. The inner expression isself.tags.join(", "). This is a method chain:self.tags.join("...").Let me see how method chain formatting works:
Assistant
Assistant
OK so
collect_method_chainwalks up the chain ofCallexpressions. Forself.tags.join(", "):expressionisself.tags.join(", ")(Call).- Walk:
Call { expression: self.tags.join, ... }.
Assistant
Hmm no debug output. Let me check if the format was successful:
Assistant
The formatter still produces multi-line output! Let me check the debug output:
Assistant
The format is failing because of a parse error. Let me check what:
Assistant
The current file is broken. Let me reset and rebuild:
Assistant
Still broken. The debug output isn't showing because the formatter is going through different code paths. Let me check where the format is happening:
Assistant
Hmm now there's a parse error. Let me check:
Assistant
The file is broken (was formatted incorrectly). Let me restore it and check what's happening:
Assistant
OK so the original file has
f" [{self.tags.join(", ")}]"on one line. The formatter then breaks it into multiple lines.The issue is that
self.tags.join(", ")is a method chain. Even after myforce_inline, the inner Group still has strict_breaks that get triggered.Assistant
OK so
join_pattern_entriesusesstrict_break(",", ", ")to separate entries. For 1 entry, no separator.The body for
self.tags.join(", ")would be:- 1 entry (the string
", "). - body =
Sequence(", "). - close_sep =
strict_break(",", "").
After
.nest(INDENT_WIDTH):- The body is wrapped in Nest(2, ...).
So the final structure (after
.group()) is:Group( Sequence( head, // self.tags.join "(", strict_break("", ""), Nest(2, body), // ", " close_sep, // strict_break(",", "") ")" ) )With
force_inline:- Group → unwrap. Content = Sequence.
- Sequence → process elements.
- For each element:
head(Sequence) → force_inline recursively, filter Newlines."("→ text.strict_break("", "")→ strict break. Kept.Nest(2, body)→ unwrap Nest. Then force_inline on body.close_sep→ strict break. Kept.
- 1 entry (the string
Assistant
No debug output! That means the formatter is NOT going through my
format_stringfunction. Let me check iflis formatuses a different code path:Assistant
OK so the CLI uses
format_sourcedirectly. My debug output should be there. Let me re-build and test:Assistant
Assistant
WAIT! The output is actually correct now!
f" [{self.tags.join(", ")}]"is on one line. Let me check the original again:Assistant
OK so the formatted output is correct!
f" [{self.tags.join(", ")}]"is on one line. The earlier output I saw was stale (from the old broken state).Wait, let me re-check my fix actually worked. Earlier I was getting multi-line output. Let me verify:
Assistant
OK format says "Formatted 1 file" but there was a "FORCED" message in between. Let me check if the file was actually formatted:
Assistant
AHA! So when I run
lis formatSECOND time on the already-formatted file, it breaks the f-string!The first format run produced the correct output. The SECOND format run on the same file produces broken output!
Wait, that means the formatter is not idempotent for this case. Let me check:
Assistant
Assistant
Assistant
Assistant
Now let me update
force_inlineto wrap the result withForceUnbroken:Assistant
Now let me test:
Assistant
Excellent! Now the format works correctly.
f" [{self.tags.join(", ")}]"is on one line.Let me also run the format tests:
Assistant
All 292 format tests still pass.
Assistant
The e2e_learn test now passes! Let me also run other tests:
Assistant
All LSP tests pass. Let me also verify the format tests one more time:
Assistant
Let me also test the match case to make sure it still works:
Assistant
Hmm, the match case is still producing multi-line output. Let me investigate.
Wait, that's actually the SAME behavior as before for the match case. The match has explicit
Document::Newlines frombraced_bodyandjoin_sibling_body. Myforce_inlineremoves those.But wait, the output shows
match x {\n 1 => "a",\n }}which has newlines. That means the Newlines are NOT being removed.Hmm, let me check. Actually let me look at the match case more carefully:
Assistant
Hmm, the match case still shows multi-line output. But the call case works fine now. Let me look at what's happening with the match.
Wait, looking more carefully at the match output:
f"match: {match x { 1 => "a", }}"The
match x {is on one line, then1 => "a",is on next line, then}}is on the line after.This suggests the Newlines inside the match body are NOT being removed.
Let me trace. The match expression:
match_()returnsbraced_body(header, body).braced_body= .
Assistant
OK so the body has Newlines between entries. My
force_inlineshould remove them.Let me trace through more carefully. The match expression is
match x { 1 => "a" }. Afterexpression(match), we get a Document. Thenforce_inlineis applied.But wait, my
force_inlineis recursive. Let me think about whether it works correctly for the body.Actually, looking at the output:
f"match: {match x { 1 => "a", }}"The
{and1 => "a",are on different lines. This means there's a Newline betweenmatch x {and1 => "a". And there's a Newline after"a",(probably the}is on the next line).Wait the output is:
f"match: {match x { 1 => "a", }}Hmm so:
- Line:
f"match: {match x { - Line:
1 => "a", - Line:
}}
There are 2 newlines. One between
{and1 => "a", and one between"a",and}}.These should be removed by my
force_inline. Let me debug to see what's happening:- Line:
Assistant
Assistant
Hmm, still multi-line. Let me check the new debug output:
Assistant
Still the same output. The structure has
ForceUnbroken(Newline)elements that should be removed.Wait, my change unwraps
ForceUnbrokeninforce_inline. SoForceUnbroken(Newline)should becomeNewline, then filtered out by the Sequence handler.Let me check if my code change actually compiled:
Assistant
Assistant
Still multi-line. Let me check the new debug output:
Assistant
I see, the OUTER Sequence is now not wrapped in ForceUnbroken (good). But the elements are still wrapped in
ForceUnbroken. And the elements includeForceUnbroken(Newline)which survive the filter.The issue: the Sequence's elements are wrapped in
ForceUnbroken. The filter checks forSelf::Newline, but the elements areForceUnbroken(Newline). So they're not filtered out.I need to either:
- Make the filter unwrap
ForceUnbroken. - Make the Sequence handler unwrap
ForceUnbrokenfrom elements before filtering.
Let me update the filter to also check for
ForceUnbroken(Newline):- Make the filter unwrap
Assistant
Now the match case is on one line. Let me check that other cases still work:
Assistant
Let me see the full output:
Assistant
All cases are idempotent. Let me see the actual outputs:
Assistant
All cases are working correctly! All f-string interpolations are on one line. Let me remove the debug print and check the format tests:
Assistant
All 292 format tests pass.
Let me also rebuild the binary and test the e2e_learn test:
Assistant
e2e_learn test passes.
Let me also check that the other tests still pass:
Assistant
All LSP tests pass.
Let me also run the e2e_smoke test:
Assistant
Let me also check the e2e_suite:
Assistant
All e2e tests pass.
Let me look at the final diff:
Assistant
Assistant
All f-strings are formatted correctly with single-line interpolations.
Now let me also do a final cleanup. The internal
force_inline_innerfunction is a bit awkward. Let me see if I can simplify.Actually, looking at the code, the flag
wrap_force_unbrokencontrols whether to wrap. The logic is:- When called on the top-level document, don't wrap.
- When called on a Sequence's element, wrap.
This is needed because the Sequence handler needs to filter out elements that are just Newlines. The wrapping ensures the elements are wrapped in ForceUnbroken so that the filter can recognize "ForceUnbroken(Newline)" patterns.
But there's a simpler way: instead of wrapping, just process the element without wrapping for the filter check. Let me think.
Actually, the current approach works. Let me just make sure the code is clean.
Let me also think about whether the
ForceUnbrokenwrapper is necessary. Could I just rely on the unwrapping + newline removal? Let me test:Assistant
Still works. Let me check the actual outputs:
Assistant
All cases work. The code is now simpler with just one
force_inlinemethod.Let me run all the tests:
Assistant
All tests pass.
Let me look at the final diff:
Assistant
The diff is clean. Let me also run all the tests to make sure everything is OK:
Assistant
Let me also verify the format tests:
Assistant
All format tests pass.
Let me also verify the syntax tests:
Assistant
All syntax tests pass.
Let me also check the LSP tests:
Assistant
All LSP tests pass.
Let me also test one more edge case - the e2e_learn test specifically:
Assistant
Excellent! Everything works.
Let me also clean up the temporary test files:
Assistant
Now let me do one final check on the diff:
Assistant
The diff is clean and focused. Let me summarize the changes:
Summary
Issue
The Lisette formatter was rewriting single-line call expressions inside f-string interpolations to multi-line, which the compiler rejects with "Multi-line f-string interpolation" error.
Fix
1.
crates/format/src/formatter/expression.rs: Updatedformat_stringto call on the inner expression of f-string interpolations.Assistant
There are a lot of
.snap.newfiles that I should clean up:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.