cue/format: improve indentation of field values

now indented on consecutive lines in case of overflow

Change-Id: Ifd312c958eb37fd584e8309130980510bb418e8c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1790
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/format/node.go b/cue/format/node.go
index 8c19372..a683890 100644
--- a/cue/format/node.go
+++ b/cue/format/node.go
@@ -163,7 +163,14 @@
 
 		f.print(n.Colon, token.COLON, tab)
 		if n.Value != nil {
-			f.expr(n.Value)
+			switch n.Value.(type) {
+			case *ast.ListComprehension, *ast.ListLit, *ast.StructLit:
+				f.expr(n.Value)
+			default:
+				f.print(indent)
+				f.expr(n.Value)
+				f.markUnindentLine()
+			}
 		} else {
 			f.current.pos++
 			f.visitComments(f.current.pos)
@@ -609,7 +616,6 @@
 
 	printBlank := prec < cutoff
 
-	ws := indent
 	f.expr1(x.X, prec, depth+diffPrec(x.X, prec))
 	f.print(nooverride)
 	if printBlank {
@@ -628,9 +634,6 @@
 		f.print(blank)
 	}
 	f.expr1(x.Y, prec+1, depth+1)
-	if ws == ignore {
-		f.print(unindent)
-	}
 }
 
 func isBinary(expr ast.Expr) bool {
diff --git a/cue/format/testdata/expressions.golden b/cue/format/testdata/expressions.golden
index 15480aa..47cf2c1 100644
--- a/cue/format/testdata/expressions.golden
+++ b/cue/format/testdata/expressions.golden
@@ -51,6 +51,15 @@
 	e: s[2*3]
 	e: s[1+2*3]
 
+	e: a |
+		b |
+		c
+
+	e:
+		a |
+		b | c |
+		d
+
 	e: f(3 + 4 + 5)
 	e: f(3 * 4 * 5)
 	e: f(3 + 4*5)
diff --git a/cue/format/testdata/expressions.input b/cue/format/testdata/expressions.input
index cebb633..e613f06 100644
--- a/cue/format/testdata/expressions.input
+++ b/cue/format/testdata/expressions.input
@@ -51,6 +51,15 @@
     e: s[2*3]
     e: s[1+2*3]
 
+    e: a |
+    b|
+    c
+
+    e:
+    a|
+    b| c |
+    d
+
     e: f(3+4+5)
     e: f(3*4*5)
     e: f(3+4*5)