Skip to content

Fix several formatter issues moving docs/comments#3132

Open
kstich wants to merge 1 commit into
mainfrom
dev/kstich/investigate-doc-comment-moving
Open

Fix several formatter issues moving docs/comments#3132
kstich wants to merge 1 commit into
mainfrom
dev/kstich/investigate-doc-comment-moving

Conversation

@kstich
Copy link
Copy Markdown
Contributor

@kstich kstich commented May 15, 2026

The IDL formatter mishandled comments around members with default value assignments and around shape boundaries: trailing comments were hoisted to their own lines, doc comments after default values kept their /// prefix even when the position was structurally invalid, banner-style doc comments (4+ leading slashes) were re-segmented, and trailing top-level comments were always reattached to the next shape even when they read as commentary on the closing brace above them.

A new RelocateMemberComments pipeline pass moves non-inline comments out of VALUE_ASSIGNMENT > BR subtrees and into the surrounding member container's whitespace before the rest of the formatter runs, so the downstream passes only see comments in their structurally meaningful positions. FixBadDocComments is extended to demote same-line trailing doc comments inside VALUE_ASSIGNMENT and to demote banner-bearing doc-comment blocks separated from their target shape by a blank line. FormatVisitor now keys comment rendering off the IDL token type rather than the lexeme prefix, with a banner-preserving mode for doc comments and a banner-aware demotion path for plain comments. The BR visitor distributes top-level shape-statement comments three ways: same-line trailing inline, plain comments contiguous with the previous construct sticking to it, and everything else deferring forward.

A new FormatUtils collects shared tree-navigation helpers used across the pipeline, including a value-end-line helper that compensates for the BR newline token inflating member end lines. The ParseAndFormatTest corpus runner now asserts idempotency by re-formatting each expected output and confirming it is a fixed point across all 162 fixtures.

Fixes #2279
Fixes #2643


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The IDL formatter mishandled comments around members with default
value assignments and around shape boundaries: trailing comments were
hoisted to their own lines, doc comments after default values kept
their `///` prefix even when the position was structurally invalid,
banner-style doc comments (4+ leading slashes) were re-segmented, and
trailing top-level comments were always reattached to the next shape
even when they read as commentary on the closing brace above them.

A new `RelocateMemberComments` pipeline pass moves non-inline comments
out of `VALUE_ASSIGNMENT > BR` subtrees and into the surrounding member
container's whitespace before the rest of the formatter runs, so the
downstream passes only see comments in their structurally meaningful
positions. `FixBadDocComments` is extended to demote same-line trailing
doc comments inside `VALUE_ASSIGNMENT` and to demote banner-bearing
doc-comment blocks separated from their target shape by a blank line.
`FormatVisitor` now keys comment rendering off the IDL token type
rather than the lexeme prefix, with a banner-preserving mode for doc
comments and a banner-aware demotion path for plain comments. The BR
visitor distributes top-level shape-statement comments three ways:
same-line trailing inline, plain comments contiguous with the previous
construct sticking to it, and everything else deferring forward.

A new `FormatUtils` collects shared tree-navigation helpers used across
the pipeline, including a value-end-line helper that compensates for
the BR newline token inflating member end lines. The
`ParseAndFormatTest` corpus runner now asserts idempotency by
re-formatting each expected output and confirming it is a fixed point
across all 162 fixtures.
@kstich kstich requested a review from a team as a code owner May 15, 2026 21:52
@kstich kstich requested a review from JordonPhillips May 15, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter destroys slashes in service operation list Broken/unexpected formatting of comments after members

1 participant