mirror of
https://github.com/golang/go
synced 2024-11-17 04:04:46 -07:00
go/printer: if comment gets formatted away, don't squash
We were dropping the preceding whitespace. Fixes #53059 Change-Id: Ide0d6a76c463a7481ec4883a8568f7f7b5e87e9f Reviewed-on: https://go-review.googlesource.com/c/go/+/408394 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
757f3c802a
commit
557244cef7
@ -747,6 +747,18 @@ func (p *printer) intersperseComments(next token.Position, tok token.Token) (wro
|
|||||||
// a top-level doc comment.
|
// a top-level doc comment.
|
||||||
list = formatDocComment(list)
|
list = formatDocComment(list)
|
||||||
changed = true
|
changed = true
|
||||||
|
|
||||||
|
if len(p.comment.List) > 0 && len(list) == 0 {
|
||||||
|
// The doc comment was removed entirely.
|
||||||
|
// Keep preceding whitespace.
|
||||||
|
p.writeCommentPrefix(p.posFor(p.comment.Pos()), next, last, tok)
|
||||||
|
// Change print state to continue at next.
|
||||||
|
p.pos = next
|
||||||
|
p.last = next
|
||||||
|
// There can't be any more comments.
|
||||||
|
p.nextComment()
|
||||||
|
return p.writeCommentSuffix(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, c := range list {
|
for _, c := range list {
|
||||||
p.writeCommentPrefix(p.posFor(c.Pos()), next, last, tok)
|
p.writeCommentPrefix(p.posFor(c.Pos()), next, last, tok)
|
||||||
|
4
src/go/printer/testdata/comments.golden
vendored
4
src/go/printer/testdata/comments.golden
vendored
@ -767,4 +767,8 @@ var _ = []T{ // lone comments
|
|||||||
// in composite lit
|
// in composite lit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _() {}
|
||||||
|
|
||||||
|
func _() {}
|
||||||
|
|
||||||
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
||||||
|
5
src/go/printer/testdata/comments.input
vendored
5
src/go/printer/testdata/comments.input
vendored
@ -765,4 +765,9 @@ var _ = []T{// lone comments
|
|||||||
// in composite lit
|
// in composite lit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _() {}
|
||||||
|
|
||||||
|
//
|
||||||
|
func _() {}
|
||||||
|
|
||||||
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
||||||
|
Loading…
Reference in New Issue
Block a user