@@ -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+ comments := []* ast.CommentGroup {}
118119 // In ast2, strip the import "C" line.
119120 if * godefs {
120121 w := 0
@@ -141,6 +142,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
141142 w ++
142143 }
143144 ast2 .Decls = ast2 .Decls [0 :w ]
145+ comments = ast2 .Comments [w :]
144146 } else {
145147 for _ , decl := range ast2 .Decls {
146148 d , ok := decl .(* ast.GenDecl )
@@ -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