-
Notifications
You must be signed in to change notification settings - Fork 7
/
diagnostics.go
42 lines (37 loc) · 911 Bytes
/
diagnostics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package lsp
import (
lsp "github.com/Azure/azapi-lsp/internal/protocol"
"github.com/hashicorp/hcl/v2"
)
func HCLSeverityToLSP(severity hcl.DiagnosticSeverity) lsp.DiagnosticSeverity {
var sev lsp.DiagnosticSeverity
switch severity {
case hcl.DiagError:
sev = lsp.SeverityError
case hcl.DiagWarning:
sev = lsp.SeverityWarning
case hcl.DiagInvalid:
panic("invalid diagnostic")
}
return sev
}
func HCLDiagsToLSP(hclDiags hcl.Diagnostics, source string) []lsp.Diagnostic {
diags := []lsp.Diagnostic{}
for _, hclDiag := range hclDiags {
msg := hclDiag.Summary
if hclDiag.Detail != "" {
msg += ": " + hclDiag.Detail
}
var rnge lsp.Range
if hclDiag.Subject != nil {
rnge = HCLRangeToLSP(*hclDiag.Subject)
}
diags = append(diags, lsp.Diagnostic{
Range: rnge,
Severity: HCLSeverityToLSP(hclDiag.Severity),
Source: source,
Message: msg,
})
}
return diags
}