MCPcopy
hub / github.com/hashicorp/hcl / PartialContent

Method PartialContent

ext/dynblock/expand_body.go:52–90  ·  view source on GitHub ↗
(schema *hcl.BodySchema)

Source from the content-addressed store, hash-verified

50}
51
52func (b *expandBody) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Body, hcl.Diagnostics) {
53 extSchema := b.extendSchema(schema)
54 rawContent, _, diags := b.original.PartialContent(extSchema)
55 // We discard the "remain" argument above because we're going to construct
56 // our own remain that also takes into account remaining "dynamic" blocks.
57
58 blocks, blockDiags := b.expandBlocks(schema, rawContent.Blocks, true)
59 diags = append(diags, blockDiags...)
60 attrs := b.prepareAttributes(rawContent.Attributes)
61
62 content := &hcl.BodyContent{
63 Attributes: attrs,
64 Blocks: blocks,
65 MissingItemRange: b.original.MissingItemRange(),
66 }
67
68 remain := &expandBody{
69 original: b.original,
70 forEachCtx: b.forEachCtx,
71 iteration: b.iteration,
72 checkForEach: b.checkForEach,
73 hiddenAttrs: make(map[string]struct{}),
74 hiddenBlocks: make(map[string]hcl.BlockHeaderSchema),
75 }
76 for name := range b.hiddenAttrs {
77 remain.hiddenAttrs[name] = struct{}{}
78 }
79 for typeName, blockS := range b.hiddenBlocks {
80 remain.hiddenBlocks[typeName] = blockS
81 }
82 for _, attrS := range schema.Attributes {
83 remain.hiddenAttrs[attrS.Name] = struct{}{}
84 }
85 for _, blockS := range schema.Blocks {
86 remain.hiddenBlocks[blockS.Type] = blockS
87 }
88
89 return content, remain, diags
90}
91
92func (b *expandBody) extendSchema(schema *hcl.BodySchema) *hcl.BodySchema {
93 // We augment the requested schema to also include our special "dynamic"

Callers

nothing calls this directly

Calls 5

extendSchemaMethod · 0.95
expandBlocksMethod · 0.95
prepareAttributesMethod · 0.95
PartialContentMethod · 0.65
MissingItemRangeMethod · 0.65

Tested by

no test coverage detected