From 3b2aa0ad0d30e05dd413f1c1e82f1679f294bcf0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 1 Nov 2016 11:08:08 -0700 Subject: [PATCH] vendor: update HCL for printing updates --- .../hashicorp/hcl/hcl/printer/nodes.go | 43 ++++++++++++----- vendor/vendor.json | 48 +++++++++---------- 2 files changed, 54 insertions(+), 37 deletions(-) diff --git a/vendor/github.com/hashicorp/hcl/hcl/printer/nodes.go b/vendor/github.com/hashicorp/hcl/hcl/printer/nodes.go index 83f6a4f0c..7903c4d26 100644 --- a/vendor/github.com/hashicorp/hcl/hcl/printer/nodes.go +++ b/vendor/github.com/hashicorp/hcl/hcl/printer/nodes.go @@ -118,17 +118,27 @@ func (p *printer) output(n interface{}) []byte { defer un(trace(p, "ObjectList")) var index int - var nextItem token.Pos for { - // TODO(arslan): refactor below comment printing, we have the same in objectType - for _, c := range p.standaloneComments { - for _, comment := range c.List { - if index != len(t.Items) { - nextItem = t.Items[index].Pos() - } else { - nextItem = token.Pos{Offset: infinity, Line: infinity} - } + // Determine the location of the next actual non-comment + // item. If we're at the end, the next item is at "infinity" + var nextItem token.Pos + if index != len(t.Items) { + nextItem = t.Items[index].Pos() + } else { + nextItem = token.Pos{Offset: infinity, Line: infinity} + } + // Go through the standalone comments in the file and print out + // the comments that we should be for this object item. + for _, c := range p.standaloneComments { + // Go through all the comments in the group. The group + // should be printed together, not separated by double newlines. + printed := false + for _, comment := range c.List { + // We only care about comments after the previous item + // we've printed so that comments are printed in the + // correct locations (between two objects for example). + // And before the next item. if comment.Pos().After(p.prev) && comment.Pos().Before(nextItem) { // if we hit the end add newlines so we can print the comment // we don't do this if prev is invalid which means the @@ -138,14 +148,21 @@ func (p *printer) output(n interface{}) []byte { buf.Write([]byte{newline, newline}) } + // Write the actual comment. buf.WriteString(comment.Text) - buf.WriteByte(newline) - if index != len(t.Items) { - buf.WriteByte(newline) - } + + // Set printed to true to note that we printed something + printed = true } } + + // If we're not at the last item, write a new line so + // that there is a newline separating this comment from + // the next object. + if printed && index != len(t.Items) { + buf.WriteByte(newline) + } } if index == len(t.Items) { diff --git a/vendor/vendor.json b/vendor/vendor.json index cd6674c05..d276d7192 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1300,70 +1300,70 @@ "revision": "7e3c02b30806fa5779d3bdfc152ce4c6f40e7b38" }, { - "checksumSHA1": "8OPDk+bKyRGJoKcS4QNw9F7dpE8=", + "checksumSHA1": "gjNr5WSUuPicxQzLLKpv5VsjFg0=", "path": "github.com/hashicorp/hcl", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "XQmjDva9JCGGkIecOgwtBEMCJhU=", "path": "github.com/hashicorp/hcl/hcl/ast", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "5HVecyfmcTm6OTffEi6LGayQf5M=", "path": "github.com/hashicorp/hcl/hcl/fmtcmd", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "croNloscHsjX87X+4/cKOURf1EY=", "path": "github.com/hashicorp/hcl/hcl/parser", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { - "checksumSHA1": "QjoxNbg+jBmtewexLaBZ8EJEl24=", + "checksumSHA1": "JXmCiZ1N2Zv2DIYz8UmnipOgLqQ=", "path": "github.com/hashicorp/hcl/hcl/printer", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "lgR7PSAZ0RtvAc9OCtCnNsF/x8g=", "path": "github.com/hashicorp/hcl/hcl/scanner", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "JlZmnzqdmFFyb1+2afLyR3BOE/8=", "path": "github.com/hashicorp/hcl/hcl/strconv", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "c6yprzj06ASwCo18TtbbNNBHljA=", "path": "github.com/hashicorp/hcl/hcl/token", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "138aCV5n8n7tkGYMsMVQQnnLq+0=", "path": "github.com/hashicorp/hcl/json/parser", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "YdvFsNOMSWMLnY6fcliWQa0O5Fw=", "path": "github.com/hashicorp/hcl/json/scanner", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "fNlXQCQEnb+B3k5UDL/r15xtSJY=", "path": "github.com/hashicorp/hcl/json/token", - "revision": "8fa153c5b4e9d1ccecda7075821ffc7c1f6d912b", - "revisionTime": "2016-10-28T23:32:40Z" + "revision": "6e968a3fcdcbab092f5307fd0d85479d5af1e4dc", + "revisionTime": "2016-11-01T18:00:25Z" }, { "checksumSHA1": "RYz/9y1RMZfg+oMgEyJIWiSl1dU=",