Introduce support for self.*
references
#163
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Architecture Background
One vs Two schema flags (targets vs origins)
Originally the hope/plan was to have just a single "flag" in the schema under the
Extensions
-SelfRef: true
, just like we have for Count and ForEach and will have for dynamic blocks. However, it turns out that isn't most practical. This is because we collect reference targets with the appropriate addresses separately from origins and because we would have to traverse through the rest of a potentially deeply nested and long block, to find out whether a particular target needs a localself
address or not.So we instead introduce the additional
DependentBodySelfRef: true
which implies that any attributes and blocks within the body will be collected as a target with an additionalself.*
local address. This will then be enabled for Terraform within theresource
anddata
blocks and allows us to do the target collection without knowing whether that address is needed or not in the rest of the block.Contextual Address
Since reference targets can now have both local (
LocalAddr
) and "absolute" (Addr
) address, this needs to be considered when rendering the address in completion, hover and elsewhere. In Terraform,self.*
addresses are relevant underprovisioner
,connection
and some other blocks, and the assumption is that these refer to the outermost block/body, i.e.resource
block.UX Impact
Completion
Hover
Go-to-*
Semantic Token Highlighting