Skip to content

Commit

Permalink
decoder: Implement reference targets for Object
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Feb 21, 2023
1 parent 0da8e76 commit f9dcbf1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
8 changes: 0 additions & 8 deletions decoder/expr_object.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package decoder

import (
"context"

"github.com/hashicorp/hcl-lang/reference"
"github.com/hashicorp/hcl-lang/schema"
"github.com/hashicorp/hcl/v2"
)
Expand All @@ -13,8 +10,3 @@ type Object struct {
cons schema.Object
pathCtx *PathContext
}

func (obj Object) ReferenceTargets(ctx context.Context, targetCtx *TargetContext) reference.Targets {
// TODO
return nil
}
44 changes: 44 additions & 0 deletions decoder/expr_object_ref_targets.go
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
}

0 comments on commit f9dcbf1

Please sign in to comment.