Skip to content

Add experimental/ast/printer package#657

Draft
emcfarlane wants to merge 11 commits intomainfrom
ed/printer2
Draft

Add experimental/ast/printer package#657
emcfarlane wants to merge 11 commits intomainfrom
ed/printer2

Conversation

@emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Jan 22, 2026

This adds experimental/ast/printer, an AST printer for protobuf files. It does not yet implement formatting, but uses the dom library to produce correct indentation for synthetic edits. Formatting support will be added later.

The printer preserves comments and whitespace using a trivia index. Each comment is classified as either attached (bound to a specific token) or detached (bound to a positional slot between declarations). Attached comments travel with their token when declarations are moved; detached comments stay in place. At print time, the printer zips slot trivia with children within each scope, and looks up attached trivia when emitting individual tokens. This works identically for natural and synthetic tokens (no special-casing needed).

Copy link
Member

@doriable doriable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API looks very reasonable to me, I just had a few nitpicks/discussion points for clarifying a few things. Thank you!

@emcfarlane emcfarlane changed the title Add experimental/printer package Add experimental/ast/printer package Feb 6, 2026
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.

2 participants