forked from hashicorp/hcl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hcl: Annotate diagnostics with expression EvalContext
When we're evaluating expressions, we may end up evaluating the same source-level expression a number of times in different contexts, such as in a 'for' expression, where each one may produce a different set of diagnostic messages. Now we'll attach the EvalContext to each expression diagnostic so that a diagnostic renderer can potentially show additional information to help distinguish the different iterations in rendered diagnostics.
- Loading branch information
1 parent
41cff85
commit 93562f8
Showing
7 changed files
with
270 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package hclsyntax | ||
|
||
import ( | ||
"github.com/hashicorp/hcl2/hcl" | ||
) | ||
|
||
// setDiagEvalContext is an internal helper that will impose a particular | ||
// EvalContext on a set of diagnostics in-place, for any diagnostic that | ||
// does not already have an EvalContext set. | ||
// | ||
// We generally expect diagnostics to be immutable, but this is safe to use | ||
// on any Diagnostics where none of the contained Diagnostic objects have yet | ||
// been seen by a caller. Its purpose is to apply additional context to a | ||
// set of diagnostics produced by a "deeper" component as the stack unwinds | ||
// during expression evaluation. | ||
func setDiagEvalContext(diags hcl.Diagnostics, ctx *hcl.EvalContext) { | ||
for _, diag := range diags { | ||
if diag.EvalContext == nil { | ||
diag.EvalContext = ctx | ||
} | ||
} | ||
} |
Oops, something went wrong.