mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/doc: make comments inside functions appear with -src
The old godoc didn't do this either, perhaps because it's a little tricky, but it can be done using a special type from the go/printer package. (Usually we just use go/format). Fixes #28195. Change-Id: Ic6d3df3953ba71128398ceaf9a133c798551b6b8 Reviewed-on: https://go-review.googlesource.com/c/143037 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
4158734097
commit
e0a97a5928
2 changed files with 14 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"go/doc"
|
||||
"go/format"
|
||||
"go/parser"
|
||||
"go/printer"
|
||||
"go/token"
|
||||
"io"
|
||||
"log"
|
||||
|
|
@ -206,7 +207,17 @@ func (pkg *Package) newlines(n int) {
|
|||
// clears the stuff we don't want to print anyway. It's a bit of a magic trick.
|
||||
func (pkg *Package) emit(comment string, node ast.Node) {
|
||||
if node != nil {
|
||||
err := format.Node(&pkg.buf, pkg.fs, node)
|
||||
var err error
|
||||
if showSrc {
|
||||
// Need an extra little dance to get internal comments to appear.
|
||||
commentedNode := &printer.CommentedNode{
|
||||
Node: node,
|
||||
Comments: pkg.file.Comments,
|
||||
}
|
||||
err = format.Node(&pkg.buf, pkg.fs, commentedNode)
|
||||
} else {
|
||||
err = format.Node(&pkg.buf, pkg.fs, node)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue