]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/structure.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcl / hclsyntax / structure.go
index d69f65b62e3b9ed0db89ea6e7a2c5f12b613c63f..476025d1ba404d3dcfe2a93dea667334caf4116c 100644 (file)
@@ -9,6 +9,10 @@ import (
 
 // AsHCLBlock returns the block data expressed as a *hcl.Block.
 func (b *Block) AsHCLBlock() *hcl.Block {
+       if b == nil {
+               return nil
+       }
+
        lastHeaderRange := b.TypeRange
        if len(b.LabelRanges) > 0 {
                lastHeaderRange = b.LabelRanges[len(b.LabelRanges)-1]
@@ -43,8 +47,8 @@ type Body struct {
 var assertBodyImplBody hcl.Body = &Body{}
 
 func (b *Body) walkChildNodes(w internalWalkFunc) {
-       b.Attributes = w(b.Attributes).(Attributes)
-       b.Blocks = w(b.Blocks).(Blocks)
+       w(b.Attributes)
+       w(b.Blocks)
 }
 
 func (b *Body) Range() hcl.Range {
@@ -82,8 +86,8 @@ func (b *Body) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostic
 
                        diags = append(diags, &hcl.Diagnostic{
                                Severity: hcl.DiagError,
-                               Summary:  "Unsupported attribute",
-                               Detail:   fmt.Sprintf("An attribute named %q is not expected here.%s", name, suggestion),
+                               Summary:  "Unsupported argument",
+                               Detail:   fmt.Sprintf("An argument named %q is not expected here.%s", name, suggestion),
                                Subject:  &attr.NameRange,
                        })
                }
@@ -103,7 +107,7 @@ func (b *Body) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostic
                                // Is there an attribute of the same name?
                                for _, attrS := range schema.Attributes {
                                        if attrS.Name == blockTy {
-                                               suggestion = fmt.Sprintf(" Did you mean to define attribute %q?", blockTy)
+                                               suggestion = fmt.Sprintf(" Did you mean to define argument %q? If so, use the equals sign to assign it a value.", blockTy)
                                                break
                                        }
                                }
@@ -147,8 +151,8 @@ func (b *Body) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Bod
                        if attrS.Required {
                                diags = append(diags, &hcl.Diagnostic{
                                        Severity: hcl.DiagError,
-                                       Summary:  "Missing required attribute",
-                                       Detail:   fmt.Sprintf("The attribute %q is required, but no definition was found.", attrS.Name),
+                                       Summary:  "Missing required argument",
+                                       Detail:   fmt.Sprintf("The argument %q is required, but no definition was found.", attrS.Name),
                                        Subject:  b.MissingItemRange().Ptr(),
                                })
                        }
@@ -251,9 +255,9 @@ func (b *Body) JustAttributes() (hcl.Attributes, hcl.Diagnostics) {
                example := b.Blocks[0]
                diags = append(diags, &hcl.Diagnostic{
                        Severity: hcl.DiagError,
-                       Summary:  fmt.Sprintf("Unexpected %s block", example.Type),
+                       Summary:  fmt.Sprintf("Unexpected %q block", example.Type),
                        Detail:   "Blocks are not allowed here.",
-                       Context:  &example.TypeRange,
+                       Subject:  &example.TypeRange,
                })
                // we will continue processing anyway, and return the attributes
                // 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) {
 }
 
 func (b *Body) MissingItemRange() hcl.Range {
-       return b.EndRange
+       return hcl.Range{
+               Filename: b.SrcRange.Filename,
+               Start:    b.SrcRange.Start,
+               End:      b.SrcRange.Start,
+       }
 }
 
 // Attributes is the collection of attribute definitions within a body.
 type Attributes map[string]*Attribute
 
 func (a Attributes) walkChildNodes(w internalWalkFunc) {
-       for k, attr := range a {
-               a[k] = w(attr).(*Attribute)
+       for _, attr := range a {
+               w(attr)
        }
 }
 
@@ -317,7 +325,7 @@ type Attribute struct {
 }
 
 func (a *Attribute) walkChildNodes(w internalWalkFunc) {
-       a.Expr = w(a.Expr).(Expression)
+       w(a.Expr)
 }
 
 func (a *Attribute) Range() hcl.Range {
@@ -326,6 +334,9 @@ func (a *Attribute) Range() hcl.Range {
 
 // AsHCLAttribute returns the block data expressed as a *hcl.Attribute.
 func (a *Attribute) AsHCLAttribute() *hcl.Attribute {
+       if a == nil {
+               return nil
+       }
        return &hcl.Attribute{
                Name: a.Name,
                Expr: a.Expr,
@@ -339,8 +350,8 @@ func (a *Attribute) AsHCLAttribute() *hcl.Attribute {
 type Blocks []*Block
 
 func (bs Blocks) walkChildNodes(w internalWalkFunc) {
-       for i, block := range bs {
-               bs[i] = w(block).(*Block)
+       for _, block := range bs {
+               w(block)
        }
 }
 
@@ -371,9 +382,13 @@ type Block struct {
 }
 
 func (b *Block) walkChildNodes(w internalWalkFunc) {
-       b.Body = w(b.Body).(*Body)
+       w(b.Body)
 }
 
 func (b *Block) Range() hcl.Range {
        return hcl.RangeBetween(b.TypeRange, b.CloseBraceRange)
 }
+
+func (b *Block) DefRange() hcl.Range {
+       return hcl.RangeBetween(b.TypeRange, b.OpenBraceRange)
+}