File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -140,11 +140,23 @@ func (dec *hclDecoder) Decode() (*CandidateNode, error) {
140140 body := dec .file .Body .(* hclsyntax.Body )
141141 sortedAttrs := sortedAttributes (body .Attributes )
142142
143- // Extract file-level head comments from before the first attribute
143+ // Extract file-level head comments from before the first attribute or block
144144 var fileComment string
145+ var firstPos int = - 1
146+
145147 if len (sortedAttrs ) > 0 {
146- firstAttrPos := sortedAttrs [0 ].Attr .Range ().Start .Byte
147- fileComment = extractHeadComment (dec .fileBytes , firstAttrPos )
148+ firstPos = sortedAttrs [0 ].Attr .Range ().Start .Byte
149+ }
150+
151+ if len (body .Blocks ) > 0 {
152+ blockPos := body .Blocks [0 ].Range ().Start .Byte
153+ if firstPos == - 1 || blockPos < firstPos {
154+ firstPos = blockPos
155+ }
156+ }
157+
158+ if firstPos != - 1 {
159+ fileComment = extractHeadComment (dec .fileBytes , firstPos )
148160 if fileComment != "" {
149161 root .HeadComment = fileComment
150162 }
You can’t perform that action at this time.
0 commit comments