Skip to content

Commit 5a7f4b1

Browse files
Extract function comments
Allows generators like defaulters and conversions to use information about generated conversions.
1 parent 4a9ebba commit 5a7f4b1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

parser/parse.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ func (b *Builder) findTypesIn(pkgPath string, u *types.Universe) error {
453453
if ok {
454454
t := b.walkType(*u, nil, tn.Type())
455455
c1 := b.priorCommentLines(obj.Pos(), 1)
456+
// c1.Text() is safe if c1 is nil
456457
t.CommentLines = splitLines(c1.Text())
457458
if c1 == nil {
458459
t.SecondClosestCommentLines = splitLines(b.priorCommentLines(obj.Pos(), 2).Text())
@@ -463,7 +464,15 @@ func (b *Builder) findTypesIn(pkgPath string, u *types.Universe) error {
463464
tf, ok := obj.(*tc.Func)
464465
// We only care about functions, not concrete/abstract methods.
465466
if ok && tf.Type() != nil && tf.Type().(*tc.Signature).Recv() == nil {
466-
b.addFunction(*u, nil, tf)
467+
t := b.addFunction(*u, nil, tf)
468+
c1 := b.priorCommentLines(obj.Pos(), 1)
469+
// c1.Text() is safe if c1 is nil
470+
t.CommentLines = splitLines(c1.Text())
471+
if c1 == nil {
472+
t.SecondClosestCommentLines = splitLines(b.priorCommentLines(obj.Pos(), 2).Text())
473+
} else {
474+
t.SecondClosestCommentLines = splitLines(b.priorCommentLines(c1.List[0].Slash, 2).Text())
475+
}
467476
}
468477
tv, ok := obj.(*tc.Var)
469478
if ok && !tv.IsField() {

0 commit comments

Comments
 (0)