]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer, gofmt: fix multi-line logic
authorRobert Griesemer <gri@golang.org>
Tue, 13 Mar 2012 23:15:58 +0000 (16:15 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 13 Mar 2012 23:15:58 +0000 (16:15 -0700)
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

src/cmd/godoc/godoc.go
src/pkg/go/printer/nodes.go
src/pkg/go/printer/testdata/declarations.golden
src/pkg/go/printer/testdata/declarations.input

index f689b4a8406a10e62ff4e63221e763b8e5663181..5faba2b1815addb62cc687913f904913c5224244 100644 (file)
@@ -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")
 
index 6be3c09382e06b3b6b826dda59b56771a72f608a..727d2a37147286845bb7e37748ceb4fd3a627e49 100644 (file)
@@ -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) {
index 7ed7cb61ae5cddbeea5d076f8e23419b6f0f2515..71ed32ed145df34bf4e0f3e0c7c80e4cc3143985 100644 (file)
@@ -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{},
index df8c2b167e16bcb719196f47d462184ee74e4337..d74cff25d1f4ccf70e14379b3edbbcf13d2f0584 100644 (file)
@@ -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",