4 "github.com/hashicorp/hcl2/hcl"
7 // hclDiagnostic is a Diagnostic implementation that wraps a HCL Diagnostic
8 type hclDiagnostic struct {
12 var _ Diagnostic = hclDiagnostic{}
14 func (d hclDiagnostic) Severity() Severity {
15 switch d.diag.Severity {
23 func (d hclDiagnostic) Description() Description {
25 Summary: d.diag.Summary,
26 Detail: d.diag.Detail,
30 func (d hclDiagnostic) Source() Source {
32 if d.diag.Subject != nil {
33 rng := SourceRangeFromHCL(*d.diag.Subject)
36 if d.diag.Context != nil {
37 rng := SourceRangeFromHCL(*d.diag.Context)
43 func (d hclDiagnostic) FromExpr() *FromExpr {
44 if d.diag.Expression == nil || d.diag.EvalContext == nil {
48 Expression: d.diag.Expression,
49 EvalContext: d.diag.EvalContext,
53 // SourceRangeFromHCL constructs a SourceRange from the corresponding range
54 // type within the HCL package.
55 func SourceRangeFromHCL(hclRange hcl.Range) SourceRange {
57 Filename: hclRange.Filename,
59 Line: hclRange.Start.Line,
60 Column: hclRange.Start.Column,
61 Byte: hclRange.Start.Byte,
64 Line: hclRange.End.Line,
65 Column: hclRange.End.Column,
66 Byte: hclRange.End.Byte,
71 // ToHCL constructs a HCL Range from the receiving SourceRange. This is the
72 // opposite of SourceRangeFromHCL.
73 func (r SourceRange) ToHCL() hcl.Range {
78 Column: r.Start.Column,