Skip to content

Commit

Permalink
fix merging schema extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Oct 19, 2022
1 parent 54dd8af commit 32e493e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 6 additions & 3 deletions decoder/body_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,11 @@ func TestCompletionAtPos_BodySchema_Extensions(t *testing.T) {
{
Label: "for_each",
Description: lang.MarkupContent{
Value: "A set or a map where each item represents an instance",
Kind: lang.PlainTextKind,
Value: "A meta-argument that accepts a map or a set of strings, and creates an instance for each item in that map or set." +
" Each instance has a distinct infrastructure object associated with it, and each is separately created, updated, or" +
" destroyed when the configuration is applied.\n\n" +
"**Note**: A given resource or module block cannot use both count and for_each.",
Kind: lang.MarkdownKind,
},
Detail: "optional, set or map of any type",
TextEdit: lang.TextEdit{
Expand All @@ -533,7 +536,7 @@ func TestCompletionAtPos_BodySchema_Extensions(t *testing.T) {
},
},
NewText: "for_each",
Snippet: "for_each = ${1:1}",
Snippet: "for_each {\n ${1}\n}",
},
Kind: lang.AttributeCandidateKind,
},
Expand Down
15 changes: 9 additions & 6 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func mergeBlockBodySchemas(block *hcl.Block, blockSchema *schema.BlockSchema) (*
mergedSchema.ImpliedOrigins = append(mergedSchema.ImpliedOrigins, depSchema.ImpliedOrigins...)
mergedSchema.Targets = depSchema.Targets.Copy()
mergedSchema.DocsLink = depSchema.DocsLink.Copy()
mergedSchema.Extensions = depSchema.Extensions.Copy()

if depSchema.Extensions != nil {
mergedSchema.Extensions = depSchema.Extensions.Copy()
}
}

return mergedSchema, nil
Expand Down Expand Up @@ -200,13 +203,13 @@ func countAttributeHoverData(editRng hcl.Range) *lang.HoverData {

func forEachAttributeCandidate(editRng hcl.Range) lang.Candidate {
return lang.Candidate{
Label: "foreach",
Detail: "optional, string", // this should be a map or set of strings
Label: "for_each",
Detail: "optional, set or map of any type",
Description: lang.MarkupContent{
Kind: lang.MarkdownKind,
Value: "A meta-argument that accepts a map or a set of strings, and creates an instance for each item in that map or set." +
" Each instance has a distinct infrastructure object associated with it, and each is separately created, updated, or" +
" destroyed when the configuration is applied. " +
" destroyed when the configuration is applied.\n\n" +
"**Note**: A given resource or module block cannot use both count and for_each.",
},
Kind: lang.AttributeCandidateKind,
Expand All @@ -220,7 +223,7 @@ func forEachAttributeCandidate(editRng hcl.Range) lang.Candidate {

func foreachEachCandidate(editRng hcl.Range) []lang.Candidate {
return []lang.Candidate{
lang.Candidate{
{
Label: "each.key",
Detail: "string",
Description: lang.MarkupContent{
Expand All @@ -234,7 +237,7 @@ func foreachEachCandidate(editRng hcl.Range) []lang.Candidate {
Range: editRng,
},
},
lang.Candidate{
{
Label: "each.value",
Detail: "string",
Description: lang.MarkupContent{
Expand Down

0 comments on commit 32e493e

Please sign in to comment.