go/go2go: add line comments to rewritten files

Change-Id: I6fe3de668381d89131825ba00cc202f49c7971cf
This commit is contained in:
Ian Lance Taylor 2020-01-17 15:24:02 -08:00 committed by Robert Griesemer
parent f95754ecff
commit 10c3db1727
1 changed files with 7 additions and 2 deletions

View File

@ -8,13 +8,18 @@ import (
"bufio"
"fmt"
"go/ast"
"go/format"
"go/printer"
"go/token"
"path/filepath"
"os"
"strings"
)
var config = printer.Config{
Mode: printer.UseSpaces | printer.TabIndent | printer.SourcePos,
Tabwidth: 8,
}
// rewrite rewrites the contents of one file.
func rewrite(dir string, fset *token.FileSet, filename string, ast *ast.File) (err error) {
filename = filepath.Base(filename)
@ -37,5 +42,5 @@ func rewrite(dir string, fset *token.FileSet, filename string, ast *ast.File) (e
}()
fmt.Fprintln(w, rewritePrefix)
return format.Node(w, fset, ast)
return config.Fprint(w, fset, ast)
}