Skip to content

Commit 7a2fb40

Browse files
committed
go/ast: improved documentation for comments associated with an AST
Fixes #18593. Change-Id: Ibe33ad9b536fee909120b3654b9d831e469eb285 Reviewed-on: https://go-review.googlesource.com/46370 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 0b6fbaa commit 7a2fb40

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/go/ast/ast.go

+13
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,19 @@ func (*FuncDecl) declNode() {}
967967
// appearance, including the comments that are pointed to from other nodes
968968
// via Doc and Comment fields.
969969
//
970+
// For correct printing of source code containing comments (using packages
971+
// go/format and go/printer), special care must be taken to update comments
972+
// when a File's syntax tree is modified: For printing, comments are inter-
973+
// spersed between tokens based on their position. If syntax tree nodes are
974+
// removed or moved, relevant comments in their vicinity must also be removed
975+
// (from the File.Comments list) or moved accordingly (by updating their
976+
// positions). A CommentMap may be used to facilitate some of these operations.
977+
//
978+
// Whether and how a comment is associated with a node depends on the inter-
979+
// pretation of the syntax tree by the manipulating program: Except for Doc
980+
// and Comment comments directly associated with nodes, the remaining comments
981+
// are "free-floating" (see also issues #18593, #20744).
982+
//
970983
type File struct {
971984
Doc *CommentGroup // associated documentation; or nil
972985
Package token.Pos // position of "package" keyword

0 commit comments

Comments
 (0)