Skip to content

Commit 7eceda0

Browse files
authored
Merge pull request #134 from hashicorp/expression_extensions
Support `count` and `count.index` references in blocks This adds supports for count and count.index completion, hover, and semantic tokens inside blocks by introducing an `Extensions` field to the `BodySchema` struct, and then adds `Count` as an extension point. Code is then added to detect if `Count` is set to true and the current block supports `count` usage. Whether or not the current block supports `count` is determined by the schema held in terraform-schema, which is added in hashicorp/terraform-schema#143. Effort is made to only suggest `count` or `count.index` when appropriate. `Count` will be suggested if the current block schema supports it, and `count.index` will be suggested when `count` is defined in the current block. Hover data for `count` and `count.index` is added here, and shows appropriate information depending on where it is requested. Hover information is *not* supported for string interpolation yet, that is to be added in a different set of work. Semantic tokens are resolved for `count` and `count.index` inside blocks. Semantic tokens are *not* supported for string interpolation yet, that is to be added in a different set of work.
2 parents 369f0e2 + 2aced95 commit 7eceda0

14 files changed

+1568
-68
lines changed

decoder/body_candidates.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ func (d *PathDecoder) bodySchemaCandidates(body *hclsyntax.Body, schema *schema.
1717
candidates := lang.NewCandidates()
1818
count := 0
1919

20+
if schema.Extensions != nil {
21+
// check if count attribute "extension" is enabled here
22+
if schema.Extensions.Count {
23+
// check if count attribute is already declared, so we don't
24+
// suggest a duplicate
25+
if _, ok := body.Attributes["count"]; !ok {
26+
candidates.List = append(candidates.List, countAttributeCandidate(editRng))
27+
}
28+
}
29+
}
30+
2031
if len(schema.Attributes) > 0 {
2132
attrNames := sortedAttributeNames(schema.Attributes)
2233
for _, name := range attrNames {

0 commit comments

Comments
 (0)