Skip to content

Commit 533e459

Browse files
committed
remove context pkg
1 parent b1a4452 commit 533e459

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

context/context.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

decoder/candidates.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
icontext "github.com/hashicorp/hcl-lang/context"
87
"github.com/hashicorp/hcl-lang/lang"
98
"github.com/hashicorp/hcl-lang/schema"
109
"github.com/hashicorp/hcl/v2"
@@ -53,7 +52,7 @@ func (d *PathDecoder) candidatesAtPos(ctx context.Context, body *hclsyntax.Body,
5352
if bodySchema.Extensions.Count {
5453
if _, ok := body.Attributes["count"]; ok {
5554
// append to context we need count completed
56-
ctx = icontext.WithActiveCount(ctx)
55+
ctx = schema.WithActiveCount(ctx)
5756
}
5857
}
5958
}

decoder/expression_candidates.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/zclconf/go-cty/cty"
1111

12-
icontext "github.com/hashicorp/hcl-lang/context"
1312
"github.com/hashicorp/hcl-lang/lang"
1413
"github.com/hashicorp/hcl-lang/reference"
1514
"github.com/hashicorp/hcl-lang/schema"
@@ -462,7 +461,7 @@ func (d *PathDecoder) constraintToCandidates(ctx context.Context, constraint sch
462461
func (d *PathDecoder) candidatesForTraversalConstraint(ctx context.Context, tc schema.TraversalExpr, outerBodyRng, prefixRng, editRng hcl.Range) []lang.Candidate {
463462
candidates := make([]lang.Candidate, 0)
464463

465-
if icontext.ActiveCountFromContext(ctx) {
464+
if schema.ActiveCountFromContext(ctx) {
466465
candidates = append(candidates, countIndexCandidate(editRng))
467466
}
468467

decoder/hover.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/zclconf/go-cty/cty"
1010

11-
icontext "github.com/hashicorp/hcl-lang/context"
1211
"github.com/hashicorp/hcl-lang/lang"
1312
"github.com/hashicorp/hcl-lang/reference"
1413
"github.com/hashicorp/hcl-lang/schema"
@@ -50,7 +49,7 @@ func (d *PathDecoder) hoverAtPos(ctx context.Context, body *hclsyntax.Body, body
5049
if bodySchema.Extensions.Count {
5150
if _, ok := body.Attributes["count"]; ok {
5251
// append to context we need count provided
53-
ctx = icontext.WithActiveCount(ctx)
52+
ctx = schema.WithActiveCount(ctx)
5453
}
5554
}
5655
}
@@ -259,7 +258,7 @@ func (d *PathDecoder) hoverDataForExpr(ctx context.Context, expr hcl.Expression,
259258
lang.AttrStep{
260259
Name: "index",
261260
},
262-
}) && icontext.ActiveCountFromContext(ctx) {
261+
}) && schema.ActiveCountFromContext(ctx) {
263262
return countAttributeHoverData(expr.Range()), nil
264263
}
265264

decoder/semantic_tokens.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/zclconf/go-cty/cty"
88

9-
icontext "github.com/hashicorp/hcl-lang/context"
109
"github.com/hashicorp/hcl-lang/lang"
1110
"github.com/hashicorp/hcl-lang/reference"
1211
"github.com/hashicorp/hcl-lang/schema"
@@ -52,7 +51,7 @@ func (d *PathDecoder) tokensForBody(ctx context.Context, body *hclsyntax.Body, b
5251
if bodySchema.Extensions.Count {
5352
if _, ok := body.Attributes["count"]; ok {
5453
// append to context we need count provided
55-
ctx = icontext.WithActiveCount(ctx)
54+
ctx = schema.WithActiveCount(ctx)
5655
}
5756
}
5857
}
@@ -131,7 +130,7 @@ func (d *PathDecoder) tokensForBody(ctx context.Context, body *hclsyntax.Body, b
131130
if blockSchema.Body.Extensions.Count {
132131
if _, ok := block.Body.Attributes["count"]; ok {
133132
// append to context we need count provided
134-
ctx = icontext.WithActiveCount(ctx)
133+
ctx = schema.WithActiveCount(ctx)
135134
}
136135
}
137136
}
@@ -173,7 +172,7 @@ func (d *PathDecoder) tokensForExpression(ctx context.Context, expr hclsyntax.Ex
173172
Name: "index",
174173
},
175174
}
176-
countAvailable := icontext.ActiveCountFromContext(ctx)
175+
countAvailable := schema.ActiveCountFromContext(ctx)
177176
// TODO why is countAvailable not true here?
178177
// if address.Equals(countIndexAttr) && countAvailable {
179178
if address.Equals(countIndexAttr) && countAvailable {

schema/schema.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package schema
22

3+
import (
4+
"context"
5+
)
6+
37
type schemaImplSigil struct{}
48

59
// Schema represents any schema (e.g. attribute, label, or a block)
610
type Schema interface {
711
isSchemaImpl() schemaImplSigil
812
}
13+
14+
type bodyExtCtxKey struct{}
15+
16+
type bodyActiveCountCtxKey struct{}
17+
18+
func WithActiveCount(ctx context.Context) context.Context {
19+
return context.WithValue(ctx, bodyActiveCountCtxKey{}, true)
20+
}
21+
22+
func ActiveCountFromContext(ctx context.Context) bool {
23+
return ctx.Value(bodyActiveCountCtxKey{}) != nil
24+
}

0 commit comments

Comments
 (0)