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>