[Repo Assist] Fix trailing comments in record types not indented to field level#3300
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
Conversation
) Comments appearing after the last field in a record type declaration (e.g., commented-out fields) were being placed at the brace indent level rather than the field indent level. Root cause: in genRecordFields, the ContentBefore trivia of the closing brace (}) is written via genSingleTextNode *after* the unindent that ends the field block. This means the WriterModel's current indent level is at the brace level (e.g. column 4) rather than the field level (e.g. column 8) when the comments are emitted. Fix: call enterNode closingBrace *inside* the indent block so that the comments are written at field-level indent. Then, after unindent, fix the pre-committed blank line that the last comment's trailing newline created at the wrong (field) indent level, replacing it with a correctly-indented blank line at the brace level. The closing brace is then written without re-emitting ContentBefore (using recordCursorNode + leaveNode directly). This affects the aligned and Stroustrup MultilineBracketStyle modes (the cramped mode uses a separate code path). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Horrible |
34 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Closes #2482
Root Cause
In
genRecordFields, theContentBeforetrivia of the closing brace (}) — which contains commented-out lines appearing after the last field — was written viagenSingleTextNode node.ClosingBraceafter theunindentthat ends the field block. This caused comments to be written at the brace-level indent (e.g., column 4) rather than the field-level indent (e.g., column 8).For example, with aligned brackets:
Fix
enterNode closingBrace(which emits ContentBefore) is now called inside the indent block, beforeunindent, so comments are written at field-level indent.One subtlety: when
CommentOnSingleLinetrivia is emitted, its trailingsepNlnForTriviapre-commits a new blank line in theWriterModelwith the current (field-level) indent. Afterunindent, we detect this pre-committed blank line and replace it with the correct (brace-level) indentation — ensuring the closing brace lands at the right column.The closing brace text is then written using
recordCursorNode + leaveNodedirectly, skippingenterNodeto avoid re-emittingContentBefore.Result
This affects the
AlignedandStroustrupMultilineBracketStylemodes. TheCrampedmode uses a separate code path and is not changed.Trade-offs
WriterModel.Linesto correct the pre-committed indentation. This is intentional: theWriterEventsqueue is a diagnostic side channel; the authoritative output state isWriterModel.Lines.Linesis a blank (whitespace-only) line, so it cannot accidentally affect records without trailing comments.Test Status