Commit b5021f3f authored by Robert Griesemer's avatar Robert Griesemer

go/printer, gofmt: fix multi-line logic

A node spans multiple lines if the line difference
between start and end point is > 0 (rather than > 1).
Fixes some odd cases introduced by CL 5706055;
pointed out by dsymonds.

Added corresponding test case. The other change
in the .golden file reverts to the status before
the CL mentioned above and is correct.

gofmt -w src misc changes godoc.go back to where
it was before the CL mentioned above.

Fixes #3304.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5820044
parent 62bb39e2
......@@ -67,7 +67,7 @@ var (
// search index
indexEnabled = flag.Bool("index", false, "enable search index")
indexFiles = flag.String("index_files", "", "glob pattern specifying index files;"+
"if not empty, the index is read from these files in sorted order")
"if not empty, the index is read from these files in sorted order")
maxResults = flag.Int("maxresults", 10000, "maximum number of full text search results shown")
indexThrottle = flag.Float64("index_throttle", 0.75, "index throttle value; 0.0 = no time allocated, 1.0 = full throttle")
......
......@@ -365,7 +365,7 @@ func (p *printer) setLineComment(text string) {
}
func (p *printer) isMultiLine(n ast.Node) bool {
return p.lineFor(n.End())-p.lineFor(n.Pos()) > 1
return p.lineFor(n.End())-p.lineFor(n.Pos()) > 0
}
func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool) {
......
......@@ -500,7 +500,7 @@ type _ struct {
type _ struct {
a, b,
c, d int // this line should be indented
c, d int // this line should be indented
u, v, w, x float // this line should be indented
p, q,
r, s float // this line should be indented
......@@ -562,10 +562,21 @@ var a2, b2,
var (
a3, b3,
c3, d3 int // this line should be indented
c3, d3 int // this line should be indented
a4, b4, c4 int // this line should be indented
)
// Test case from issue 3304: multi-line declarations must end
// a formatting section and not influence indentation of the
// next line.
var (
minRefreshTimeSec = flag.Int64("min_refresh_time_sec", 604800,
"minimum time window between two refreshes for a given user.")
x = flag.Int64("refresh_user_rollout_percent", 100,
"temporary flag to ramp up the refresh user rpc")
aVeryLongVariableName = stats.GetVarInt("refresh-user-count")
)
func _() {
var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
Headers: map[string]string{},
......
......@@ -577,6 +577,16 @@ c3, d3 int // this line should be indented
a4, b4, c4 int // this line should be indented
)
// Test case from issue 3304: multi-line declarations must end
// a formatting section and not influence indentation of the
// next line.
var (
minRefreshTimeSec = flag.Int64("min_refresh_time_sec", 604800,
"minimum time window between two refreshes for a given user.")
x = flag.Int64("refresh_user_rollout_percent", 100,
"temporary flag to ramp up the refresh user rpc")
aVeryLongVariableName = stats.GetVarInt("refresh-user-count")
)
func _() {
var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment