Skip to content

pxf: the parser drops a trailing comment on an entry's line, so formatting moves or loses it #193

Open

Description

@bfrancojr

Found while porting the formatter fix (#188, PR #192). It was measured on main and is not related to directives.

What happens. The Java parser never attaches a comment that ends an entry's line to that entry. b = 1 # tc formats as b = 1. When another entry follows, # tc is written on the line above it, as that entry's leading comment. At the end of a block the comment is gone. protowire-go keeps it as the entry's trailing comment and writes it back in place.

Why it matters. pxf fmt on a Java build changes what a document's comments describe, or deletes them. It is the one difference between Java's and Go's formatter output in PR #192's byte comparison (13 of 14 documents identical, the 14th differs only here). The C# port has the same bug, trendvidia/protowire-csharp#108.

Done when: a comment after an entry on the same line is kept as that entry's trailing comment, both at the end of a block and in the middle of one, and formatting writes it back on the same line, byte-identical to protowire-go's FormatDocument. Each case has a test.

Activity

  1. bfrancojr commented on Nov 8, 2026

    @bfrancojr
    CollaboratorAuthor

    Same mechanism as #200 (comments that no entry follows, protowire-go#279/#282), in the same files, and the two depend on each other: x = 1 # tc just before } needs this fix to stay on its line. Planned as one PR closing both, one commit each.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions