-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decoder: Implement reference targets for Object
- Loading branch information
1 parent
0da8e76
commit f9dcbf1
Showing
2 changed files
with
44 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package decoder | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/hcl-lang/reference" | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
) | ||
|
||
func (obj Object) ReferenceTargets(ctx context.Context, targetCtx *TargetContext) reference.Targets { | ||
eType, ok := obj.expr.(*hclsyntax.ObjectConsExpr) | ||
if !ok { | ||
return reference.Targets{} | ||
} | ||
|
||
if len(eType.Items) == 0 || len(obj.cons.Attributes) == 0 { | ||
return reference.Targets{} | ||
} | ||
|
||
targets := make(reference.Targets, 0) | ||
|
||
// TODO: collect parent target for the whole object | ||
|
||
// for _, item := range eType.Items { | ||
// keyName, _, ok := getRawObjectConsKeyName(item.KeyExpr) | ||
// if !ok { | ||
// // avoid collecting item w/ invalid key | ||
// continue | ||
// } | ||
|
||
// expr := newExpression(m.pathCtx, item.ValueExpr, m.cons.Elem) | ||
// if e, ok := expr.(ReferenceTargetsExpression); ok { | ||
|
||
// elemAddr := addr.Copy() | ||
// elemAddr = append(elemAddr, lang.IndexStep{ | ||
// Key: cty.StringVal(keyName), | ||
// }) | ||
|
||
// targets = append(targets, e.ReferenceTargets(ctx, elemTargetCtx)...) | ||
// } | ||
// } | ||
|
||
return targets | ||
} |