-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Limit label completion items to maxCandidates (100) (#85)
- Loading branch information
1 parent
30c25ae
commit 5f3f065
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package decoder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/hcl-lang/lang" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
func TestDecoder_CandidateAtPos_incompleteLabels(t *testing.T) { | ||
bodySchema := &schema.BodySchema{ | ||
Blocks: map[string]*schema.BlockSchema{ | ||
"customblock": { | ||
Labels: []*schema.LabelSchema{ | ||
{ | ||
Name: "type", | ||
IsDepKey: true, | ||
Completable: true, | ||
}, | ||
}, | ||
DependentBody: map[schema.SchemaKey]*schema.BodySchema{ | ||
schema.NewSchemaKey(schema.DependencyKeys{ | ||
Labels: []schema.LabelDependent{ | ||
{ | ||
Index: 0, | ||
Value: "first", | ||
}, | ||
}, | ||
}): { | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"attr1": {Expr: schema.LiteralTypeOnly(cty.Number)}, | ||
}, | ||
}, | ||
schema.NewSchemaKey(schema.DependencyKeys{ | ||
Labels: []schema.LabelDependent{ | ||
{ | ||
Index: 0, | ||
Value: "second", | ||
}, | ||
}, | ||
}): { | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"attr2": {Expr: schema.LiteralTypeOnly(cty.Number)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
d := NewDecoder() | ||
d.maxCandidates = 1 | ||
d.SetSchema(bodySchema) | ||
|
||
f, _ := hclsyntax.ParseConfig([]byte(`customblock "" { | ||
} | ||
`), "test.tf", hcl.InitialPos) | ||
err := d.LoadFile("test.tf", f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
candidates, err := d.CandidatesAtPos("test.tf", hcl.Pos{ | ||
Line: 1, | ||
Column: 14, | ||
Byte: 13, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
expectedCandidates := lang.Candidates{ | ||
List: []lang.Candidate{ | ||
{ | ||
Label: "first", | ||
TextEdit: lang.TextEdit{ | ||
Range: hcl.Range{ | ||
Filename: "test.tf", | ||
Start: hcl.Pos{ | ||
Line: 1, | ||
Column: 14, | ||
Byte: 13, | ||
}, | ||
End: hcl.Pos{ | ||
Line: 1, | ||
Column: 14, | ||
Byte: 13, | ||
}, | ||
}, | ||
NewText: "first", | ||
Snippet: "first", | ||
}, | ||
Kind: lang.LabelCandidateKind, | ||
}, | ||
}, | ||
IsComplete: false, | ||
} | ||
if diff := cmp.Diff(expectedCandidates, candidates); diff != "" { | ||
t.Fatalf("unexpected candidates: %s", diff) | ||
} | ||
} |