printer: fix leadcomments for multiple comments

This commit is contained in:
Fatih Arslan 2015-10-27 01:42:05 +03:00
parent bbc2d19923
commit 3ee0cb44fa
3 changed files with 24 additions and 14 deletions

View File

@ -42,21 +42,15 @@ func (p *printer) output(n interface{}) []byte {
return buf.Bytes()
}
func (p *printer) comment(c *ast.CommentGroup) []byte {
var buf bytes.Buffer
for _, comment := range c.List {
buf.WriteString(comment.Text)
}
return buf.Bytes()
}
func (p *printer) objectItem(o *ast.ObjectItem) []byte {
var buf bytes.Buffer
if o.LeadComment != nil {
buf.Write(p.comment(o.LeadComment))
for _, comment := range o.LeadComment.List {
buf.WriteString(comment.Text)
buf.WriteByte(newline)
}
}
for i, k := range o.Keys {
buf.WriteString(k.Token.Text)
@ -73,7 +67,9 @@ func (p *printer) objectItem(o *ast.ObjectItem) []byte {
if o.Val.Pos().Line == o.Keys[0].Pos().Line && o.LineComment != nil {
buf.WriteByte(blank)
buf.Write(p.comment(o.LineComment))
for _, comment := range o.LineComment.List {
buf.WriteString(comment.Text)
}
}
return buf.Bytes()

View File

@ -4,6 +4,13 @@ variable "foo" {
description = "bar" # yooo
}
aligned = {
a = "bar" # yoo1
default = "bar" #yoo2
bar = "bar" # yoo3
}
// fatih arslan
/* This is a developer test
account and a multine comment */
developer = ["fatih", "arslan"] // fatih arslan

View File

@ -4,6 +4,13 @@ variable "foo" {
description = "bar" # yooo
}
aligned {
a = "bar" # yoo1
default = "bar" #yoo2
bar = "bar" # yoo3
}
// fatih arslan
/* This is a developer test
account and a multine comment */
developer = [ "fatih", "arslan"] // fatih arslan