this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/format: avoid indenting a lone leading comment

We would often precede a comment with a vertical tab for alignment,
even when a comment began at the start of the line,
where vertical alignment is completely pointless.

This was largely harmless, except in a few edge cases such as
a single comment followed by a declaration, where we would indent.

Instead, only add the vertical tab if the comment does not begin
at the start of the line, resolving these issues.

Note that this change requires no longer using internal.NewComment
for top-level comments in a file, as the API always sets either of
the Doc or Line booleans in ast.Comment, causing extra and unwanted
blank spaces or newlines. A lone comment at the start of a file
is neither a doc comment nor a line (inline) comment.

Fixes #722.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: If9f1afb3f3e6dbdf65d5ee28c76a0f279c97aa49
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196134
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Aram Hăvărneanu <aram@cue.works>

+14 -13
+3 -1
cmd/cue/cmd/get_go.go
··· 529 529 addDoc(f.Doc, pkg) 530 530 531 531 f := &cueast.File{Decls: []cueast.Decl{ 532 - internal.NewComment(false, "Code generated by cue get go. DO NOT EDIT."), 532 + &cueast.CommentGroup{List: []*cueast.Comment{ 533 + {Text: "// Code generated by cue get go. DO NOT EDIT."}, 534 + }}, 533 535 &cueast.CommentGroup{List: []*cueast.Comment{ 534 536 {Text: "//cue:generate cue get go " + args}, 535 537 }},
+1 -1
cue/ast/astutil/sanitize_test.go
··· 101 101 spec2 := ast.NewImport(nil, "foo/bar") 102 102 spec3 := ast.NewImport(ast.NewIdent("bar"), "foo") 103 103 return &ast.File{Decls: []ast.Decl{ 104 - internal.NewComment(false, "File comment"), 104 + &ast.CommentGroup{List: []*ast.Comment{{Text: "// File comment"}}}, 105 105 &ast.Package{Name: ast.NewIdent("pkg")}, 106 106 &ast.Field{ 107 107 Label: ast.NewIdent("a"),
+2 -3
cue/format/format.go
··· 313 313 func (f *formatter) printComment(cg *ast.CommentGroup) { 314 314 f.Print(cg) 315 315 316 - printBlank := false 317 316 if cg.Doc && len(f.output) > 0 { 318 317 f.Print(newline) 319 - printBlank = true 320 318 } 321 319 for _, c := range cg.List { 322 - if !printBlank { 320 + if f.pos.Column > 1 { 321 + // Vertically align inline comments. 323 322 f.Print(vtab) 324 323 } 325 324 f.Print(c.Slash)
+2 -2
cue/format/testdata/comments.txtar
··· 334 334 -- comment_alone.golden -- 335 335 // Just one comment on its own. 336 336 -- comment_field.input -- 337 - // Just one comment on a field. TODO(mvdan): do not indent. 337 + // Just one comment on a field. 338 338 foo: string 339 339 -- comment_field.golden -- 340 - // Just one comment on a field. TODO(mvdan): do not indent. 340 + // Just one comment on a field. 341 341 foo: string 342 342 -- comments_alone.input -- 343 343 // Just a few comments
+1 -1
cue/format/testdata/expressions.txtar
··· 589 589 // skip_create_image: true 590 590 } 591 591 -- issue2496.golden -- 592 - // TODO(mvdan): we indent the list elements too much. 592 + // TODO(mvdan): we indent the list elements too much. 593 593 machine_type: [ 594 594 if arch == "amd" {"n2-standard-2"}, 595 595 if arch == "arm" {"t2a-standard-2"},
+2 -2
encoding/protobuf/jsonpb/testdata/decoder/null.txtar
··· 88 88 // comment a10 89 89 a10: null 90 90 -- out/jsonpb/data.yaml -- 91 - // comment a0 91 + // comment a0 92 92 a0: 0 93 93 94 94 // comment a1 ··· 121 121 // comment a10 122 122 a10: null 123 123 -- out/jsonpb/data.cue -- 124 - // comment a0 124 + // comment a0 125 125 a0: 0 126 126 127 127 // comment a1
+1 -1
internal/core/export/testdata/main/disjunction.txtar
··· 4 4 b: *2 | int 5 5 c: *(a & b) | 3 6 6 -- out/definition -- 7 - // Issue #950 7 + // Issue #950 8 8 a: *1 | int 9 9 b: *2 | int 10 10 c: *(a & b) | 3
+1 -1
internal/core/export/testdata/selfcontained/import.txtar
··· 137 137 +++ new 138 138 @@ -1,10 +1,7 @@ 139 139 import "tool/exec" 140 - 140 + 141 141 // Can be inlined. 142 142 -v: { 143 143 - x: 3
+1 -1
pkg/math/testdata/mult.txtar
··· 12 12 f2: math.MultipleOf(100.01, 4) 13 13 14 14 -- out/math -- 15 - // should be true 15 + // should be true 16 16 t1: true 17 17 t2: true 18 18 t3: true