Skip to content

Commit

Permalink
cmd/doc: stop showing interface methods while matching symbols
Browse files Browse the repository at this point in the history
Fixes golang#31961

Change-Id: I9db9ecfd2f8ca7cf51df4413a6e0d66de5da7043
Reviewed-on: https://go-review.googlesource.com/c/go/+/178457
Run-TryBot: Agniva De Sarker <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Rob Pike <[email protected]>
  • Loading branch information
agnivade authored and robpike committed May 23, 2019
1 parent e2970a4 commit 65ef999
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/cmd/doc/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@ var tests = []test{
`Comment about exported interface`,
},
},
// Interface method at package level.
{
"interface method at package level",
[]string{p, `ExportedMethod`},
[]string{
`func \(ExportedType\) ExportedMethod\(a int\) bool`,
`Comment about exported method`,
},
[]string{
`Comment before exported method.*\n.*ExportedMethod\(\)` +
`.*Comment on line with exported method`,
},
},

// Method.
{
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/doc/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,8 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis
}

// printMethodDoc prints the docs for matches of symbol.method.
// If symbol is empty, it prints all methods that match the name.
// It reports whether it found any methods.
// If symbol is empty, it prints all methods for any concrete type
// that match the name. It reports whether it found any methods.
func (pkg *Package) printMethodDoc(symbol, method string) bool {
defer pkg.flush()
types := pkg.findTypes(symbol)
Expand All @@ -937,6 +937,9 @@ func (pkg *Package) printMethodDoc(symbol, method string) bool {
}
continue
}
if symbol == "" {
continue
}
// Type may be an interface. The go/doc package does not attach
// an interface's methods to the doc.Type. We need to dig around.
spec := pkg.findTypeSpec(typ.Decl, typ.Name)
Expand Down

0 comments on commit 65ef999

Please sign in to comment.