aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc/testdata/pkg.go
diff options
context:
space:
mode:
authorAgniva De Sarker <agnivade@yahoo.co.in>2020-12-17 12:43:19 +0530
committerRob Pike <r@golang.org>2021-03-19 03:05:26 +0000
commited3ae9a340e506d873e57444a8eb28cd06e933a2 (patch)
tree3c7fdf961e97c1dc5372bd02c0455f9a05995c3b /src/cmd/doc/testdata/pkg.go
parent9136d958ab258bc4f128c8582ab713c482ec33ed (diff)
downloadgo-ed3ae9a340e506d873e57444a8eb28cd06e933a2.tar.xz
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>
Diffstat (limited to 'src/cmd/doc/testdata/pkg.go')
-rw-r--r--src/cmd/doc/testdata/pkg.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/doc/testdata/pkg.go b/src/cmd/doc/testdata/pkg.go
index d695bdf1c5..5ece832565 100644
--- a/src/cmd/doc/testdata/pkg.go
+++ b/src/cmd/doc/testdata/pkg.go
@@ -111,6 +111,13 @@ const unexportedTypedConstant ExportedType = 1 // In a separate section to test
// Comment about exported interface.
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.
unexportedMethod() // Comment on line with unexported method.
io.Reader // Comment on line with embedded Reader.