diff --git a/aligned.go b/aligned.go index 6376cf1..4ef549e 100644 --- a/aligned.go +++ b/aligned.go @@ -10,11 +10,11 @@ type aligned struct { var ( alignedEquals = leftAligned(" = ") - alignedShortEquals = notAligned("=") + alignedShortEquals = leftAligned("=") alignedSpace = leftAligned(" ") alignedComma = leftAligned(", ") - alignedEmpty = notAligned("") - alignedSemicolon = notAligned(";") + alignedEmpty = leftAligned("") + alignedSemicolon = leftAligned(";") ) func leftAligned(src string) aligned { return aligned{src, true, true} } diff --git a/import.go b/import.go index b612636..dd9cd84 100644 --- a/import.go +++ b/import.go @@ -6,6 +6,7 @@ import "fmt" type Import struct { Filename string Kind string // weak, public, + Comment *Comment } // Accept dispatches the call to the visitor. @@ -13,6 +14,11 @@ func (i *Import) Accept(v Visitor) { v.VisitImport(i) } +// inlineComment is part of commentInliner. +func (i *Import) inlineComment(c *Comment) { + i.Comment = c +} + // columns returns printable source tokens func (i *Import) columns() (cols []aligned) { cols = append(cols, leftAligned("import ")) @@ -21,7 +27,10 @@ func (i *Import) columns() (cols []aligned) { } else { cols = append(cols, alignedEmpty) } - cols = append(cols, alignedEmpty, notAligned(fmt.Sprintf("%q", i.Filename))) + cols = append(cols, alignedSpace, notAligned(fmt.Sprintf("%q", i.Filename)), alignedSemicolon) + if i.Comment != nil { + cols = append(cols, notAligned(" //"), notAligned(i.Comment.Message)) + } return } diff --git a/option.go b/option.go index 94640db..4f2d42b 100644 --- a/option.go +++ b/option.go @@ -8,6 +8,12 @@ type Option struct { Name string Constant Literal IsEmbedded bool + Comment *Comment +} + +// inlineComment is part of commentInliner. +func (o *Option) inlineComment(c *Comment) { + o.Comment = c } // Accept dispatches the call to the visitor. @@ -26,6 +32,12 @@ func (o *Option) columns() (cols []aligned) { if o.IsEmbedded { cols = append(cols, leftAligned("]")) } + if !o.IsEmbedded { + cols = append(cols, alignedSemicolon) + if o.Comment != nil { + cols = append(cols, notAligned(" //"), notAligned(o.Comment.Message)) + } + } return }