Skip to content

[Repo Assist] Fix trailing comments in record types not indented to field level#3300

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-2482-record-trailing-comment-indent-259ee2b4990c232c
Closed

[Repo Assist] Fix trailing comments in record types not indented to field level#3300
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-2482-record-trailing-comment-indent-259ee2b4990c232c

Conversation

@github-actions
Copy link
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #2482

Root Cause

In genRecordFields, the ContentBefore trivia of the closing brace (}) — which contains commented-out lines appearing after the last field — was written via genSingleTextNode node.ClosingBrace after the unindent that 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:

// Before fix:
type UserInfo =
    {
        UserId: int
    // Roles: Role list   ← was at column 4 (wrong)
    }

Fix

enterNode closingBrace (which emits ContentBefore) is now called inside the indent block, before unindent, so comments are written at field-level indent.

One subtlety: when CommentOnSingleLine trivia is emitted, its trailing sepNlnForTrivia pre-commits a new blank line in the WriterModel with the current (field-level) indent. After unindent, 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 + leaveNode directly, skipping enterNode to avoid re-emitting ContentBefore.

Result

// After fix (aligned):
type UserInfo =
    {
        UserId: int
        // Roles: Role list   ← now at column 8 ✓
    }

// After fix (Stroustrup):
type UserInfo = {
    UserId: int
    // Roles: Role list   ← now at column 4 ✓
}

This affects the Aligned and Stroustrup MultilineBracketStyle modes. The Cramped mode uses a separate code path and is not changed.

Trade-offs

  • The fix involves a targeted direct mutation of WriterModel.Lines to correct the pre-committed indentation. This is intentional: the WriterEvents queue is a diagnostic side channel; the authoritative output state is WriterModel.Lines.
  • The correction only fires when the head of Lines is a blank (whitespace-only) line, so it cannot accidentally affect records without trailing comments.

Test Status

  • ✅ Build succeeded (0 warnings, 0 errors)
  • ✅ All 2741 tests pass (2 new tests added for this fix: one for aligned style, one for Stroustrup style)

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@d1d884596e62351dd652ae78465885dd32f0dd7d

)

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>
@nojaf
Copy link
Contributor

nojaf commented Mar 19, 2026

Horrible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commented line inside of record should be indented at the same level as the fields

1 participant