Skip to content

Commit

Permalink
Rename CandidatesAtPos to CompletionAtPos (#356)
Browse files Browse the repository at this point in the history
* Rename CandidatesAtPos to CompletionAtPos

* Rename attrValueCandidatesAtPos to attrValueCompletionAtPos
  • Loading branch information
dbanck authored Jan 3, 2024
1 parent 4168ffe commit 47e2378
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion decoder/attribute_candidates_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestLegacyDecoder_CompletionAtPos_EmptyCompletionData(t *testing.T) {
d.PrefillRequiredFields = true

ctx := context.Background()
candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", hcl.InitialPos)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions decoder/body_candidates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestDecoder_CandidateAtPos_incompleteAttributes(t *testing.T) {
})
d.maxCandidates = 1

candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{
candidates, err := d.CompletionAtPos(ctx, "test.tf", hcl.Pos{
Line: 2,
Column: 7,
Byte: 29,
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestDecoder_CandidateAtPos_computedAttributes(t *testing.T) {
},
})

candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{
candidates, err := d.CompletionAtPos(ctx, "test.tf", hcl.Pos{
Line: 2,
Column: 7,
Byte: 29,
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestDecoder_CandidateAtPos_incompleteBlocks(t *testing.T) {
})
d.maxCandidates = 1

candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.Pos{
candidates, err := d.CompletionAtPos(ctx, "test.tf", hcl.Pos{
Line: 3,
Column: 8,
Byte: 42,
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestDecoder_CandidateAtPos_duplicateNames(t *testing.T) {
})
d.PrefillRequiredFields = true

candidates, err := d.CandidatesAtPos(ctx, "test.tf", hcl.InitialPos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", hcl.InitialPos)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions decoder/body_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ variable "test" {
ReferenceTargets: tc.referenceTargets,
})

candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", tc.pos)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ for_each =
ReferenceTargets: tc.referenceTargets,
})

candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", tc.pos)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1651,7 +1651,7 @@ func TestCompletionAtPos_BodySchema_Extensions_SelfRef(t *testing.T) {
ReferenceTargets: targets,
})

candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", tc.pos)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -2701,7 +2701,7 @@ resource "aws_elastic_beanstalk_environment" "example" {
},
})

candidates, err := d.CandidatesAtPos(ctx, "test.tf", tc.pos)
candidates, err := d.CompletionAtPos(ctx, "test.tf", tc.pos)

if err != nil {
if tc.expectedErr != "" && err.Error() != tc.expectedErr {
Expand Down
18 changes: 9 additions & 9 deletions decoder/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"github.com/hashicorp/hcl/v2/hclsyntax"
)

// CandidatesAtPos returns completion candidates for a given position in a file
// CompletionAtPos returns completion candidates for a given position in a file
//
// Schema is required in order to return any candidates and method will return
// error if there isn't one.
func (d *PathDecoder) CandidatesAtPos(ctx context.Context, filename string, pos hcl.Pos) (lang.Candidates, error) {
func (d *PathDecoder) CompletionAtPos(ctx context.Context, filename string, pos hcl.Pos) (lang.Candidates, error) {
f, err := d.fileByName(filename)
if err != nil {
return lang.ZeroCandidates(), err
Expand All @@ -44,10 +44,10 @@ func (d *PathDecoder) CandidatesAtPos(ctx context.Context, filename string, pos

ctx = schema.WithPrefillRequiredFields(ctx, d.PrefillRequiredFields)

return d.candidatesAtPos(ctx, rootBody, outerBodyRng, d.pathCtx.Schema, pos)
return d.completionAtPos(ctx, rootBody, outerBodyRng, d.pathCtx.Schema, pos)
}

func (d *PathDecoder) candidatesAtPos(ctx context.Context, body *hclsyntax.Body, outerBodyRng hcl.Range, bodySchema *schema.BodySchema, pos hcl.Pos) (lang.Candidates, error) {
func (d *PathDecoder) completionAtPos(ctx context.Context, body *hclsyntax.Body, outerBodyRng hcl.Range, bodySchema *schema.BodySchema, pos hcl.Pos) (lang.Candidates, error) {
if bodySchema == nil {
return lang.ZeroCandidates(), nil
}
Expand All @@ -60,16 +60,16 @@ func (d *PathDecoder) candidatesAtPos(ctx context.Context, body *hclsyntax.Body,
ctx = schema.WithActiveSelfRefs(ctx)
}
if bodySchema.Extensions != nil && bodySchema.Extensions.Count && attr.Name == "count" {
return d.attrValueCandidatesAtPos(ctx, attr, schemahelper.CountAttributeSchema(), outerBodyRng, pos)
return d.attrValueCompletionAtPos(ctx, attr, schemahelper.CountAttributeSchema(), outerBodyRng, pos)
}
if bodySchema.Extensions != nil && bodySchema.Extensions.ForEach && attr.Name == "for_each" {
return d.attrValueCandidatesAtPos(ctx, attr, schemahelper.ForEachAttributeSchema(), outerBodyRng, pos)
return d.attrValueCompletionAtPos(ctx, attr, schemahelper.ForEachAttributeSchema(), outerBodyRng, pos)
}
if aSchema, ok := bodySchema.Attributes[attr.Name]; ok {
return d.attrValueCandidatesAtPos(ctx, attr, aSchema, outerBodyRng, pos)
return d.attrValueCompletionAtPos(ctx, attr, aSchema, outerBodyRng, pos)
}
if bodySchema.AnyAttribute != nil {
return d.attrValueCandidatesAtPos(ctx, attr, bodySchema.AnyAttribute, outerBodyRng, pos)
return d.attrValueCompletionAtPos(ctx, attr, bodySchema.AnyAttribute, outerBodyRng, pos)
}

return lang.ZeroCandidates(), nil
Expand Down Expand Up @@ -144,7 +144,7 @@ func (d *PathDecoder) candidatesAtPos(ctx context.Context, body *hclsyntax.Body,

if block.Body != nil && block.Body.Range().ContainsPos(pos) {
mergedSchema, _ := schemahelper.MergeBlockBodySchemas(block.AsHCLBlock(), blockSchema)
return d.candidatesAtPos(ctx, block.Body, outerBodyRng, mergedSchema, pos)
return d.completionAtPos(ctx, block.Body, outerBodyRng, mergedSchema, pos)
}
}
}
Expand Down
Loading

0 comments on commit 47e2378

Please sign in to comment.