// 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]
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 {
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,
})
}
// 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
}
}
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(),
})
}
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
}
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)
}
}
}
func (a *Attribute) walkChildNodes(w internalWalkFunc) {
- a.Expr = w(a.Expr).(Expression)
+ w(a.Expr)
}
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,
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)
}
}
}
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)
+}