diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go index d69f65b..476025d 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go | |||
@@ -9,6 +9,10 @@ import ( | |||
9 | 9 | ||
10 | // AsHCLBlock returns the block data expressed as a *hcl.Block. | 10 | // AsHCLBlock returns the block data expressed as a *hcl.Block. |
11 | func (b *Block) AsHCLBlock() *hcl.Block { | 11 | func (b *Block) AsHCLBlock() *hcl.Block { |
12 | if b == nil { | ||
13 | return nil | ||
14 | } | ||
15 | |||
12 | lastHeaderRange := b.TypeRange | 16 | lastHeaderRange := b.TypeRange |
13 | if len(b.LabelRanges) > 0 { | 17 | if len(b.LabelRanges) > 0 { |
14 | lastHeaderRange = b.LabelRanges[len(b.LabelRanges)-1] | 18 | lastHeaderRange = b.LabelRanges[len(b.LabelRanges)-1] |
@@ -43,8 +47,8 @@ type Body struct { | |||
43 | var assertBodyImplBody hcl.Body = &Body{} | 47 | var assertBodyImplBody hcl.Body = &Body{} |
44 | 48 | ||
45 | func (b *Body) walkChildNodes(w internalWalkFunc) { | 49 | func (b *Body) walkChildNodes(w internalWalkFunc) { |
46 | b.Attributes = w(b.Attributes).(Attributes) | 50 | w(b.Attributes) |
47 | b.Blocks = w(b.Blocks).(Blocks) | 51 | w(b.Blocks) |
48 | } | 52 | } |
49 | 53 | ||
50 | func (b *Body) Range() hcl.Range { | 54 | func (b *Body) Range() hcl.Range { |
@@ -82,8 +86,8 @@ func (b *Body) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostic | |||
82 | 86 | ||
83 | diags = append(diags, &hcl.Diagnostic{ | 87 | diags = append(diags, &hcl.Diagnostic{ |
84 | Severity: hcl.DiagError, | 88 | Severity: hcl.DiagError, |
85 | Summary: "Unsupported attribute", | 89 | Summary: "Unsupported argument", |
86 | Detail: fmt.Sprintf("An attribute named %q is not expected here.%s", name, suggestion), | 90 | Detail: fmt.Sprintf("An argument named %q is not expected here.%s", name, suggestion), |
87 | Subject: &attr.NameRange, | 91 | Subject: &attr.NameRange, |
88 | }) | 92 | }) |
89 | } | 93 | } |
@@ -103,7 +107,7 @@ func (b *Body) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostic | |||
103 | // Is there an attribute of the same name? | 107 | // Is there an attribute of the same name? |
104 | for _, attrS := range schema.Attributes { | 108 | for _, attrS := range schema.Attributes { |
105 | if attrS.Name == blockTy { | 109 | if attrS.Name == blockTy { |
106 | suggestion = fmt.Sprintf(" Did you mean to define attribute %q?", blockTy) | 110 | suggestion = fmt.Sprintf(" Did you mean to define argument %q? If so, use the equals sign to assign it a value.", blockTy) |
107 | break | 111 | break |
108 | } | 112 | } |
109 | } | 113 | } |
@@ -147,8 +151,8 @@ func (b *Body) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Bod | |||
147 | if attrS.Required { | 151 | if attrS.Required { |
148 | diags = append(diags, &hcl.Diagnostic{ | 152 | diags = append(diags, &hcl.Diagnostic{ |
149 | Severity: hcl.DiagError, | 153 | Severity: hcl.DiagError, |
150 | Summary: "Missing required attribute", | 154 | Summary: "Missing required argument", |
151 | Detail: fmt.Sprintf("The attribute %q is required, but no definition was found.", attrS.Name), | 155 | Detail: fmt.Sprintf("The argument %q is required, but no definition was found.", attrS.Name), |
152 | Subject: b.MissingItemRange().Ptr(), | 156 | Subject: b.MissingItemRange().Ptr(), |
153 | }) | 157 | }) |
154 | } | 158 | } |
@@ -251,9 +255,9 @@ func (b *Body) JustAttributes() (hcl.Attributes, hcl.Diagnostics) { | |||
251 | example := b.Blocks[0] | 255 | example := b.Blocks[0] |
252 | diags = append(diags, &hcl.Diagnostic{ | 256 | diags = append(diags, &hcl.Diagnostic{ |
253 | Severity: hcl.DiagError, | 257 | Severity: hcl.DiagError, |
254 | Summary: fmt.Sprintf("Unexpected %s block", example.Type), | 258 | Summary: fmt.Sprintf("Unexpected %q block", example.Type), |
255 | Detail: "Blocks are not allowed here.", | 259 | Detail: "Blocks are not allowed here.", |
256 | Context: &example.TypeRange, | 260 | Subject: &example.TypeRange, |
257 | }) | 261 | }) |
258 | // we will continue processing anyway, and return the attributes | 262 | // we will continue processing anyway, and return the attributes |
259 | // we are able to find so that certain analyses can still be done | 263 | // we are able to find so that certain analyses can still be done |
@@ -275,15 +279,19 @@ func (b *Body) JustAttributes() (hcl.Attributes, hcl.Diagnostics) { | |||
275 | } | 279 | } |
276 | 280 | ||
277 | func (b *Body) MissingItemRange() hcl.Range { | 281 | func (b *Body) MissingItemRange() hcl.Range { |
278 | return b.EndRange | 282 | return hcl.Range{ |
283 | Filename: b.SrcRange.Filename, | ||
284 | Start: b.SrcRange.Start, | ||
285 | End: b.SrcRange.Start, | ||
286 | } | ||
279 | } | 287 | } |
280 | 288 | ||
281 | // Attributes is the collection of attribute definitions within a body. | 289 | // Attributes is the collection of attribute definitions within a body. |
282 | type Attributes map[string]*Attribute | 290 | type Attributes map[string]*Attribute |
283 | 291 | ||
284 | func (a Attributes) walkChildNodes(w internalWalkFunc) { | 292 | func (a Attributes) walkChildNodes(w internalWalkFunc) { |
285 | for k, attr := range a { | 293 | for _, attr := range a { |
286 | a[k] = w(attr).(*Attribute) | 294 | w(attr) |
287 | } | 295 | } |
288 | } | 296 | } |
289 | 297 | ||
@@ -317,7 +325,7 @@ type Attribute struct { | |||
317 | } | 325 | } |
318 | 326 | ||
319 | func (a *Attribute) walkChildNodes(w internalWalkFunc) { | 327 | func (a *Attribute) walkChildNodes(w internalWalkFunc) { |
320 | a.Expr = w(a.Expr).(Expression) | 328 | w(a.Expr) |
321 | } | 329 | } |
322 | 330 | ||
323 | func (a *Attribute) Range() hcl.Range { | 331 | func (a *Attribute) Range() hcl.Range { |
@@ -326,6 +334,9 @@ func (a *Attribute) Range() hcl.Range { | |||
326 | 334 | ||
327 | // AsHCLAttribute returns the block data expressed as a *hcl.Attribute. | 335 | // AsHCLAttribute returns the block data expressed as a *hcl.Attribute. |
328 | func (a *Attribute) AsHCLAttribute() *hcl.Attribute { | 336 | func (a *Attribute) AsHCLAttribute() *hcl.Attribute { |
337 | if a == nil { | ||
338 | return nil | ||
339 | } | ||
329 | return &hcl.Attribute{ | 340 | return &hcl.Attribute{ |
330 | Name: a.Name, | 341 | Name: a.Name, |
331 | Expr: a.Expr, | 342 | Expr: a.Expr, |
@@ -339,8 +350,8 @@ func (a *Attribute) AsHCLAttribute() *hcl.Attribute { | |||
339 | type Blocks []*Block | 350 | type Blocks []*Block |
340 | 351 | ||
341 | func (bs Blocks) walkChildNodes(w internalWalkFunc) { | 352 | func (bs Blocks) walkChildNodes(w internalWalkFunc) { |
342 | for i, block := range bs { | 353 | for _, block := range bs { |
343 | bs[i] = w(block).(*Block) | 354 | w(block) |
344 | } | 355 | } |
345 | } | 356 | } |
346 | 357 | ||
@@ -371,9 +382,13 @@ type Block struct { | |||
371 | } | 382 | } |
372 | 383 | ||
373 | func (b *Block) walkChildNodes(w internalWalkFunc) { | 384 | func (b *Block) walkChildNodes(w internalWalkFunc) { |
374 | b.Body = w(b.Body).(*Body) | 385 | w(b.Body) |
375 | } | 386 | } |
376 | 387 | ||
377 | func (b *Block) Range() hcl.Range { | 388 | func (b *Block) Range() hcl.Range { |
378 | return hcl.RangeBetween(b.TypeRange, b.CloseBraceRange) | 389 | return hcl.RangeBetween(b.TypeRange, b.CloseBraceRange) |
379 | } | 390 | } |
391 | |||
392 | func (b *Block) DefRange() hcl.Range { | ||
393 | return hcl.RangeBetween(b.TypeRange, b.OpenBraceRange) | ||
394 | } | ||