Skip to content

Commit

Permalink
decoder: Implement reference origins for Set
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jan 30, 2023
1 parent d6ca315 commit b6dc7c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
8 changes: 0 additions & 8 deletions decoder/expr_set.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 Set struct {
cons schema.Set
pathCtx *PathContext
}

func (s Set) ReferenceOrigins(ctx context.Context, allowSelfRefs bool) reference.Origins {
// TODO
return nil
}
30 changes: 30 additions & 0 deletions decoder/expr_set_ref_origins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package decoder

import (
"context"

"github.com/hashicorp/hcl-lang/reference"
"github.com/hashicorp/hcl/v2/hclsyntax"
)

func (set Set) ReferenceOrigins(ctx context.Context, allowSelfRefs bool) reference.Origins {
eType, ok := set.expr.(*hclsyntax.TupleConsExpr)
if !ok {
return reference.Origins{}
}

if len(eType.Exprs) == 0 || set.cons.Elem == nil {
return reference.Origins{}
}

origins := make(reference.Origins, 0)

for _, elemExpr := range eType.Exprs {
expr := newExpression(set.pathCtx, elemExpr, set.cons.Elem)
if e, ok := expr.(ReferenceOriginsExpression); ok {
origins = append(origins, e.ReferenceOrigins(ctx, allowSelfRefs)...)
}
}

return origins
}

0 comments on commit b6dc7c6

Please sign in to comment.