1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:28:33 -06:00

x/tools/cmd/bundle: include comments inside functions

Fixes golang/go#20548

Change-Id: Ieff2323b63308cbc052a2883237520620965cf86
Reviewed-on: https://go-review.googlesource.com/45117
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-06-09 10:48:25 +09:00 committed by Brad Fitzpatrick
parent b9ad13c5e8
commit e493388965
4 changed files with 9 additions and 8 deletions

1
cmd/bundle/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
testdata/out.got

View File

@ -88,6 +88,7 @@ import (
"go/build"
"go/format"
"go/parser"
"go/printer"
"go/token"
"go/types"
"io/ioutil"
@ -348,18 +349,13 @@ func bundle(src, dst, dstpkg, prefix string) ([]byte, error) {
// Pretty-print package-level declarations.
// but no package or import declarations.
//
// TODO(adonovan): this may cause loss of comments
// preceding or associated with the package or import
// declarations or not associated with any declaration.
// Check.
var buf bytes.Buffer
for _, decl := range f.Decls {
if decl, ok := decl.(*ast.GenDecl); ok && decl.Tok == token.IMPORT {
continue
}
buf.Reset()
format.Node(&buf, lprog.Fset, decl)
format.Node(&buf, lprog.Fset, &printer.CommentedNode{Node: decl, Comments: f.Comments})
// Remove each "@@@." in the output.
// TODO(adonovan): not hygienic.
out.Write(bytes.Replace(buf.Bytes(), []byte("@@@."), nil, -1))

View File

@ -26,7 +26,9 @@ type prefixS struct {
}
// Function bar.
func prefixbar(s *prefixS) { fmt.Println(s.prefixt, s.u) }
func prefixbar(s *prefixS) {
fmt.Println(s.prefixt, s.u) // comment inside function
}
type prefixt int

View File

@ -12,4 +12,6 @@ type S struct {
}
// Function bar.
func bar(s *S) { fmt.Println(s.t, s.u) }
func bar(s *S) {
fmt.Println(s.t, s.u) // comment inside function
}