Fix several formatter issues moving docs/comments#3132
Open
kstich wants to merge 1 commit into
Open
Conversation
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.
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.
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
RelocateMemberCommentspipeline pass moves non-inline comments out ofVALUE_ASSIGNMENT > BRsubtrees 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.FixBadDocCommentsis extended to demote same-line trailing doc comments insideVALUE_ASSIGNMENTand to demote banner-bearing doc-comment blocks separated from their target shape by a blank line.FormatVisitornow 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
FormatUtilscollects 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. TheParseAndFormatTestcorpus 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.