]> Cypherpunks repositories - gostls13.git/commit
cmd/doc: properly display interface methods
authorAgniva De Sarker <agnivade@yahoo.co.in>
Thu, 17 Dec 2020 07:13:19 +0000 (12:43 +0530)
committerRob Pike <r@golang.org>
Fri, 19 Mar 2021 03:05:26 +0000 (03:05 +0000)
commited3ae9a340e506d873e57444a8eb28cd06e933a2
tree3c7fdf961e97c1dc5372bd02c0455f9a05995c3b
parent9136d958ab258bc4f128c8582ab713c482ec33ed
cmd/doc: properly display interface methods

Previously, we used to call doc.ToText to print each comment
in a comment group attached to an interface method. This broke any
preformatted code block attached to the comment, and displayed everything
aligned to a single column. Additionally, the name of the interface
also wasn't displayed which didn't show which interface
the method belonged to.

To fix this, we print the entire interface node using format.Node
which takes care of displaying the comments correctly, and we also
filter out the methods that don't match, so that the method can be
displayed as belonging to an interface.

As an example, previously it would show:

// Comment before exported method.
//
// // Code block showing how to use ExportedMethod
// func DoSomething() error {
// ExportedMethod()
// return nil
// }
func ExportedMethod()  // Comment on line with exported method.

Now, it shows:

type ExportedInterface interface {
// Comment before exported method.
//
// // Code block showing how to use ExportedMethod
// func DoSomething() error {
// ExportedMethod()
// return nil
// }
ExportedMethod() // Comment on line with exported method.

}

Fixes #43188

Change-Id: I28099fe4aab35e08049b2616a3506240f57133cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/279433
Trust: Agniva De Sarker <agniva.quicksilver@gmail.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/doc/doc_test.go
src/cmd/doc/pkg.go
src/cmd/doc/testdata/pkg.go