Skip to content

go/ast: Free-floating comments are single-biggest issue when manipulating the AST #20744

Open
@griesemer

Description

@griesemer

Reminder issue.

The original design of the go/ast makes it very difficult to update the AST and retain correct comment placement for printing. The culprit is that the comments are "free-floating" and printed based on their positions relative to the AST nodes. (The go/ast package is one of the earliest Go packages in existence, and this is clearly a major design flaw.)

Instead, a newer/updated ast should associate all comments (not just Doc and Comment comments) with nodes. That would make it much easier to manipulate a syntax tree and have comments correctly attached. The main complexity with that approach is the heuristic that decides which comments are attached to which nodes.

Metadata

Metadata

Labels

RefactoringIssues related to refactoring tools

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions