hclsyntax: Fix error diagnostic for blocks inside JustAttributes

The range was incorrectly being reported as "Context", rather than
"Subject". The Context field has meaning only in conjunction with Subject.

While here, this also tweaks the summary to show the block type name in
quotes, since otherwise the sentence can read oddly for certain block type
names.
This commit is contained in:
Martin Atkins 2019-02-13 17:14:54 -08:00
parent 89dbc5eb3d
commit 504b920607

View File

@ -255,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