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 // SourceRangeFromHCL constructs a SourceRange from the corresponding range
44 // type within the HCL package.
45 func SourceRangeFromHCL(hclRange hcl.Range) SourceRange {
47 Filename: hclRange.Filename,
49 Line: hclRange.Start.Line,
50 Column: hclRange.Start.Column,
51 Byte: hclRange.Start.Byte,
54 Line: hclRange.End.Line,
55 Column: hclRange.End.Column,
56 Byte: hclRange.End.Byte,
61 // ToHCL constructs a HCL Range from the receiving SourceRange. This is the
62 // opposite of SourceRangeFromHCL.
63 func (r SourceRange) ToHCL() hcl.Range {
68 Column: r.Start.Column,