@@ -54,7 +54,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
54
54
// In cgo mode, we ignore ast2 and just apply edits directly
55
55
// the text behind ast1. In godefs mode we modify and print ast2.
56
56
ast1 := parse (abspath , src , parser .SkipObjectResolution | parser .ParseComments )
57
- ast2 := parse (abspath , src , parser .SkipObjectResolution )
57
+ ast2 := parse (abspath , src , parser .SkipObjectResolution | parser . ParseComments )
58
58
59
59
f .Package = ast1 .Name .Name
60
60
f .Name = make (map [string ]* Name )
@@ -115,6 +115,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
115
115
error_ (ast1 .Package , `cannot find import "C"` )
116
116
}
117
117
118
+ var comments []* ast.CommentGroup
118
119
// In ast2, strip the import "C" line.
119
120
if * godefs {
120
121
w := 0
@@ -137,6 +138,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
137
138
continue
138
139
}
139
140
d .Specs = d .Specs [0 :ws ]
141
+ ast2 .Comments = ast2 .Comments [ws :]
140
142
ast2 .Decls [w ] = d
141
143
w ++
142
144
}
@@ -157,6 +159,7 @@ func (f *File) ParseGo(abspath string, src []byte) {
157
159
}
158
160
}
159
161
}
162
+ ast2 .Comments = comments
160
163
161
164
// Accumulate pointers to uses of C.x.
162
165
if f .Ref == nil {
0 commit comments