diff --git a/decoder/expr_list.go b/decoder/expr_list.go index 4e13eb08..0b3bf79a 100644 --- a/decoder/expr_list.go +++ b/decoder/expr_list.go @@ -10,8 +10,9 @@ import ( ) type List struct { - expr hcl.Expression - cons schema.List + expr hcl.Expression + cons schema.List + pathCtx *PathContext } func (l List) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expr_map.go b/decoder/expr_map.go index 214ae5c3..61bbca11 100644 --- a/decoder/expr_map.go +++ b/decoder/expr_map.go @@ -10,8 +10,9 @@ import ( ) type Map struct { - expr hcl.Expression - cons schema.Map + expr hcl.Expression + cons schema.Map + pathCtx *PathContext } func (m Map) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expr_object.go b/decoder/expr_object.go index 0d662819..fbe52bba 100644 --- a/decoder/expr_object.go +++ b/decoder/expr_object.go @@ -10,8 +10,9 @@ import ( ) type Object struct { - expr hcl.Expression - cons schema.Object + expr hcl.Expression + cons schema.Object + pathCtx *PathContext } func (obj Object) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expr_one_of.go b/decoder/expr_one_of.go index b70e054f..41e4c922 100644 --- a/decoder/expr_one_of.go +++ b/decoder/expr_one_of.go @@ -10,8 +10,9 @@ import ( ) type OneOf struct { - expr hcl.Expression - cons schema.OneOf + expr hcl.Expression + cons schema.OneOf + pathCtx *PathContext } func (oo OneOf) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expr_set.go b/decoder/expr_set.go index 94974093..58a4d5ee 100644 --- a/decoder/expr_set.go +++ b/decoder/expr_set.go @@ -10,8 +10,9 @@ import ( ) type Set struct { - expr hcl.Expression - cons schema.Set + expr hcl.Expression + cons schema.Set + pathCtx *PathContext } func (s Set) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expr_tuple.go b/decoder/expr_tuple.go index 8af79edb..f07b2f5f 100644 --- a/decoder/expr_tuple.go +++ b/decoder/expr_tuple.go @@ -10,8 +10,9 @@ import ( ) type Tuple struct { - expr hcl.Expression - cons schema.Tuple + expr hcl.Expression + cons schema.Tuple + pathCtx *PathContext } func (t Tuple) CompletionAtPos(ctx context.Context, pos hcl.Pos) []lang.Candidate { diff --git a/decoder/expression.go b/decoder/expression.go index 6f427a10..7ef7cd1a 100644 --- a/decoder/expression.go +++ b/decoder/expression.go @@ -20,31 +20,79 @@ type Expression interface { } func (d *PathDecoder) newExpression(expr hcl.Expression, cons schema.Constraint) Expression { + return newExpression(d.pathCtx, expr, cons) +} + +func newExpression(pathContext *PathContext, expr hcl.Expression, cons schema.Constraint) Expression { switch c := cons.(type) { case schema.AnyExpression: - return Any{expr: expr, cons: c, pathCtx: d.pathCtx} + return Any{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.LiteralType: - return LiteralType{expr: expr, cons: c} - case schema.Reference: - return Reference{expr: expr, cons: c} + return LiteralType{ + expr: expr, + cons: c, + } + case schema.LiteralValue: + return LiteralValue{ + expr: expr, + cons: c, + } case schema.TypeDeclaration: - return TypeDeclaration{expr: expr, cons: c} + return TypeDeclaration{ + expr: expr, + cons: c, + } case schema.Keyword: - return Keyword{expr: expr, cons: c} + return Keyword{ + expr: expr, + cons: c, + } + case schema.Reference: + return Reference{ + expr: expr, + cons: c, + } case schema.List: - return List{expr: expr, cons: c} + return List{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.Set: - return Set{expr: expr, cons: c} + return Set{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.Tuple: - return Tuple{expr: expr, cons: c} + return Tuple{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.Object: - return Object{expr: expr, cons: c} + return Object{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.Map: - return Map{expr: expr, cons: c} + return Map{ + expr: expr, + cons: c, + pathCtx: pathContext, + } case schema.OneOf: - return OneOf{expr: expr, cons: c} - case schema.LiteralValue: - return LiteralValue{expr: expr, cons: c} + return OneOf{ + expr: expr, + cons: c, + pathCtx: pathContext, + } + } return unknownExpression{}