@@ -173,27 +173,51 @@ func constraintsAtPos(expr hcl.Expression, constraints ExprConstraints, pos hcl.
173
173
174
174
type pathKey struct {}
175
175
176
+ // WithPath is not intended to be used outside this package
177
+ // except for testing hooks downstream.
178
+ func WithPath (ctx context.Context , path lang.Path ) context.Context {
179
+ return context .WithValue (ctx , pathKey {}, path )
180
+ }
181
+
176
182
func PathFromContext (ctx context.Context ) (lang.Path , bool ) {
177
183
p , ok := ctx .Value (pathKey {}).(lang.Path )
178
184
return p , ok
179
185
}
180
186
181
187
type posKey struct {}
182
188
189
+ // WithPos is not intended to be used outside this package
190
+ // except for testing hooks downstream.
191
+ func WithPos (ctx context.Context , pos hcl.Pos ) context.Context {
192
+ return context .WithValue (ctx , posKey {}, pos )
193
+ }
194
+
183
195
func PosFromContext (ctx context.Context ) (hcl.Pos , bool ) {
184
196
p , ok := ctx .Value (posKey {}).(hcl.Pos )
185
197
return p , ok
186
198
}
187
199
188
200
type filenameKey struct {}
189
201
202
+ // WithFilename is not intended to be used outside this package
203
+ // except for testing hooks downstream.
204
+ func WithFilename (ctx context.Context , filename string ) context.Context {
205
+ return context .WithValue (ctx , filenameKey {}, filename )
206
+ }
207
+
190
208
func FilenameFromContext (ctx context.Context ) (string , bool ) {
191
209
f , ok := ctx .Value (filenameKey {}).(string )
192
210
return f , ok
193
211
}
194
212
195
213
type maxCandidatesKey struct {}
196
214
215
+ // WithMaxCandidates is not intended to be used outside this package
216
+ // except for testing hooks downstream.
217
+ func WithMaxCandidates (ctx context.Context , maxCandidates uint ) context.Context {
218
+ return context .WithValue (ctx , maxCandidatesKey {}, maxCandidates )
219
+ }
220
+
197
221
func MaxCandidatesFromContext (ctx context.Context ) (uint , bool ) {
198
222
mc , ok := ctx .Value (maxCandidatesKey {}).(uint )
199
223
return mc , ok
@@ -243,10 +267,10 @@ func (d *PathDecoder) candidatesFromHooks(ctx context.Context, attr *hclsyntax.A
243
267
prefix := string (prefixBytes )
244
268
prefix = strings .TrimLeft (prefix , `"` )
245
269
246
- ctx = context . WithValue (ctx , pathKey {} , d .path )
247
- ctx = context . WithValue (ctx , filenameKey {} , attr .Expr .Range ().Filename )
248
- ctx = context . WithValue (ctx , posKey {} , pos )
249
- ctx = context . WithValue (ctx , maxCandidatesKey {} , d .maxCandidates )
270
+ ctx = WithPath (ctx , d .path )
271
+ ctx = WithFilename (ctx , attr .Expr .Range ().Filename )
272
+ ctx = WithPos (ctx , pos )
273
+ ctx = WithMaxCandidates (ctx , d .maxCandidates )
250
274
251
275
count := 0
252
276
for _ , hook := range schema .CompletionHooks {
0 commit comments