@@ -54,7 +54,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
5454 // In cgo mode, we ignore ast2 and just apply edits directly
5555 // the text behind ast1. In godefs mode we modify and print ast2.
5656 ast1 := parse (abspath , src , parser .SkipObjectResolution | parser .ParseComments )
57- ast2 := parse (abspath , src , parser .SkipObjectResolution )
57+ ast2 := parse (abspath , src , parser .SkipObjectResolution | parser . ParseComments )
5858
5959 f .Package = ast1 .Name .Name
6060 f .Name = make (map [string ]* Name )
@@ -115,6 +115,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
115115 error_ (ast1 .Package , `cannot find import "C"` )
116116 }
117117
118+ var comments []* ast.CommentGroup
118119 // In ast2, strip the import "C" line.
119120 if * godefs {
120121 w := 0
@@ -137,6 +138,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
137138 continue
138139 }
139140 d .Specs = d .Specs [0 :ws ]
141+ ast2 .Comments = ast2 .Comments [ws :]
140142 ast2 .Decls [w ] = d
141143 w ++
142144 }
@@ -157,6 +159,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
157159 }
158160 }
159161 }
162+ ast2 .Comments = comments
160163
161164 // Accumulate pointers to uses of C.x.
162165 if f .Ref == nil {
0 commit comments