Skip to content

Commit

Permalink
Implement for_each and each.* extensions (#145)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jpogran authored Oct 28, 2022
1 parent e1208e5 commit b8c8114
Show file tree
Hide file tree
Showing 11 changed files with 887 additions and 35 deletions.
8 changes: 8 additions & 0 deletions decoder/body_candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func (d *PathDecoder) bodySchemaCandidates(body *hclsyntax.Body, schema *schema.
candidates.List = append(candidates.List, attributeSchemaToCandidate("count", countAttributeSchema(), editRng))
}
}

if schema.Extensions.ForEach {
// check if for_each attribute is already declared, so we don't
// suggest a duplicate
if _, present := body.Attributes["for_each"]; !present {
candidates.List = append(candidates.List, attributeSchemaToCandidate("for_each", forEachAttributeSchema(), editRng))
}
}
}

if len(schema.Attributes) > 0 {
Expand Down
Loading

0 comments on commit b8c8114

Please sign in to comment.