printer: improvements on comment aligning

This commit is contained in:
Fatih Arslan 2015-10-28 01:07:37 +03:00
parent a16955dcad
commit 3a165313db
5 changed files with 11 additions and 21 deletions

View File

@ -158,16 +158,9 @@ func (p *printer) objectType(o *ast.ObjectType) []byte {
} }
} }
// fmt.Printf("len(oneLines) = %+v\n", len(oneLines))
// for _, i := range oneLines {
// a := i.Keys[0]
// fmt.Printf("a = %+v\n", a)
// }
if len(oneLines) != 0 { if len(oneLines) != 0 {
items := p.alignedItems(oneLines) items := p.alignedItems(oneLines)
buf.Write(p.indent(items)) buf.Write(p.indent(items))
if index != len(o.List.Items) { if index != len(o.List.Items) {
buf.WriteByte(newline) buf.WriteByte(newline)
} }
@ -183,7 +176,6 @@ func (p *printer) objectType(o *ast.ObjectType) []byte {
} }
buf.WriteString("}") buf.WriteString("}")
buf.WriteByte(newline)
return buf.Bytes() return buf.Bytes()
} }

View File

@ -24,9 +24,9 @@ type entry struct {
// Use go test -update to create/update the respective golden files. // Use go test -update to create/update the respective golden files.
var data = []entry{ var data = []entry{
// {"complexhcl.input", "complexhcl.golden"}, {"complexhcl.input", "complexhcl.golden"},
// {"list.input", "list.golden"}, {"list.input", "list.golden"},
// {"comment.input", "comment.golden"}, {"comment.input", "comment.golden"},
{"comment_aligned.input", "comment_aligned.golden"}, {"comment_aligned.input", "comment_aligned.golden"},
} }

View File

@ -20,4 +20,4 @@ variable = {
// lead comment // lead comment
foo = { foo = {
bar = "fatih" // line comment 2 bar = "fatih" // line comment 2
} // line comment 3 } // line comment 3

View File

@ -7,12 +7,10 @@ aligned = {
deneme = { deneme = {
bar = "fatih" bar = "fatih"
} }
bar = "bar" # yoo3
fatih = ["fatih", "arslan"] // yoo4
projects = ["vim-go"] # yoo5 deneme = {
default = "foo" # yoo6
example = {
bar = "fatih" bar = "fatih"
} }
}
}

View File

@ -6,9 +6,9 @@ aligned {
deneme = { deneme = {
bar = "fatih" bar = "fatih"
} }
projects = ["vim-go"] # yoo5 bar = "bar" # yoo3
default = "foo" # yoo6 fatih = ["fatih", "arslan"] // yoo4
example = { deneme = {
bar = "fatih" bar = "fatih"
} }
} }