Skip to content

Commit b8c8114

Browse files
authored
Implement for_each and each.* extensions (#145)
This provides completion hints inside blocks for `for_each` and `each.*` references within `resource`, `data` and `module` blocks anywhere the `for_each` meta-argument is supported. It detects if `for_each` is used already and does not suggest duplicates and detects when it is necessary to provide `each.*` completions. This does not complete the values for `each.key` and `each.value`, e.g. `each.value.something`. This also provides hover support for `for_each` and `each.*` references using the documentation as source. This also provides semantic token support for `for_each` and `each.*` references. Closes hashicorp/terraform-ls#861
1 parent e1208e5 commit b8c8114

11 files changed

+887
-35
lines changed

decoder/body_candidates.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ func (d *PathDecoder) bodySchemaCandidates(body *hclsyntax.Body, schema *schema.
2626
candidates.List = append(candidates.List, attributeSchemaToCandidate("count", countAttributeSchema(), editRng))
2727
}
2828
}
29+
30+
if schema.Extensions.ForEach {
31+
// check if for_each attribute is already declared, so we don't
32+
// suggest a duplicate
33+
if _, present := body.Attributes["for_each"]; !present {
34+
candidates.List = append(candidates.List, attributeSchemaToCandidate("for_each", forEachAttributeSchema(), editRng))
35+
}
36+
}
2937
}
3038

3139
if len(schema.Attributes) > 0 {

0 commit comments

Comments
 (0)