hcl: Deduplicate symbols when printing diagnostic messages
This commit is contained in:
parent
8dd89ebbb3
commit
f6fe9b5c69
@ -147,6 +147,7 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error {
|
|||||||
|
|
||||||
vars := expr.Variables()
|
vars := expr.Variables()
|
||||||
stmts := make([]string, 0, len(vars))
|
stmts := make([]string, 0, len(vars))
|
||||||
|
seen := make(map[string]struct{}, len(vars))
|
||||||
for _, traversal := range vars {
|
for _, traversal := range vars {
|
||||||
val, diags := traversal.TraverseAbs(ctx)
|
val, diags := traversal.TraverseAbs(ctx)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
@ -157,6 +158,9 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
traversalStr := w.traversalStr(traversal)
|
traversalStr := w.traversalStr(traversal)
|
||||||
|
if _, exists := seen[traversalStr]; exists {
|
||||||
|
continue // don't show duplicates when the same variable is referenced multiple times
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case !val.IsKnown():
|
case !val.IsKnown():
|
||||||
// Can't say anything about this yet, then.
|
// Can't say anything about this yet, then.
|
||||||
@ -166,6 +170,7 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error {
|
|||||||
default:
|
default:
|
||||||
stmts = append(stmts, fmt.Sprintf("%s as %s", traversalStr, w.valueStr(val)))
|
stmts = append(stmts, fmt.Sprintf("%s as %s", traversalStr, w.valueStr(val)))
|
||||||
}
|
}
|
||||||
|
seen[traversalStr] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(stmts) // FIXME: Should maybe use a traversal-aware sort that can sort numeric indexes properly?
|
sort.Strings(stmts) // FIXME: Should maybe use a traversal-aware sort that can sort numeric indexes properly?
|
||||||
|
Loading…
Reference in New Issue
Block a user