@@ -35,7 +35,7 @@ func CommentForObject(obj types.Object, pkg *packages.Package) []bindings.Synthe
3535 continue
3636 }
3737
38- var found []* ast. CommentGroup
38+ var found []bindings. SyntheticComment
3939 ast .Inspect (f , func (n ast.Node ) bool {
4040 // The decl nodes "cover" the types they comment on. So we can check quickly if
4141 // the node is relevant.
@@ -47,7 +47,7 @@ func CommentForObject(obj types.Object, pkg *packages.Package) []bindings.Synthe
4747 case * ast.FuncDecl :
4848 // Match function/method name token exactly.
4949 if nd .Name != nil && nd .Name .Pos () == pos {
50- found = nd .Doc
50+ found = syntheticComments ( true , nd .Doc )
5151 return false
5252 }
5353
@@ -63,9 +63,9 @@ func CommentForObject(obj types.Object, pkg *packages.Package) []bindings.Synthe
6363 for _ , name := range spec .Names {
6464 if name .Pos () == pos {
6565 if spec .Doc != nil {
66- found = spec .Doc
66+ found = syntheticComments ( true , nd .Doc )
6767 } else {
68- found = nd .Doc
68+ found = syntheticComments ( true , spec .Doc )
6969 }
7070 return false
7171 }
@@ -76,9 +76,9 @@ func CommentForObject(obj types.Object, pkg *packages.Package) []bindings.Synthe
7676 if spec .Name != nil && spec .Name .Pos () == pos {
7777 // comment on the type itself
7878 if spec .Doc != nil {
79- found = spec .Doc
79+ found = syntheticComments ( true , spec .Doc )
8080 } else {
81- found = nd .Doc
81+ found = syntheticComments ( true , nd .Doc )
8282 }
8383 return false
8484 }
@@ -107,10 +107,7 @@ func CommentForObject(obj types.Object, pkg *packages.Package) []bindings.Synthe
107107 return true
108108 })
109109
110- if len (found ) > 0 {
111- return found [0 ]
112- }
113- return nil
110+ return found
114111 }
115112
116113 return nil
@@ -130,15 +127,15 @@ func commentForFieldList(fl *ast.FieldList, pos token.Pos) []bindings.SyntheticC
130127 for _ , nm := range fld .Names {
131128 if nm .Pos () == pos {
132129 cmts = append (cmts , syntheticComments (true , fld .Doc )... )
133- cmts = append (cmts , syntheticComments (true , fld .Doc )... )
130+ cmts = append (cmts , syntheticComments (false , fld .Comment )... )
134131 return cmts
135132 }
136133 }
137134 } else {
138135 // Embedded field (anonymous): no Names; match on the Type span.
139136 if covers (fld .Type , pos ) {
140137 cmts = append (cmts , syntheticComments (true , fld .Doc )... )
141- cmts = append (cmts , syntheticComments (true , fld .Doc )... )
138+ cmts = append (cmts , syntheticComments (false , fld .Comment )... )
142139 return cmts
143140 }
144141 }
@@ -152,6 +149,9 @@ func covers(n ast.Node, p token.Pos) bool {
152149
153150func syntheticComments (leading bool , grp * ast.CommentGroup ) []bindings.SyntheticComment {
154151 cmts := []bindings.SyntheticComment {}
152+ if grp == nil {
153+ return cmts
154+ }
155155 for _ , c := range grp .List {
156156 cmts = append (cmts , bindings.SyntheticComment {
157157 Leading : leading ,
0 commit comments