Extend symbols with concrete *hcl.(Attribute/Block/Expression)
#409
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.
I have a use case of this module: I'd like to firstly call the
Decoder.Symbols
to get the target symbols of a query. Then iterate each symbols (recursively visiting its nested symbols). Then check whether those symbols are reference origins/targets, by usingReferenceOriginsTargetingPos()/ReferenceTargetsForOriginAtPos()
, with passing in the position of the symbols.The problem is that the symbol's position is larger than what those two functions expected. E.g. Given following HCL:
The symbol of
azurerm_resource_group.dst
's attributename
, its range spans from column 3 to column 45, which is effectivelyname = azurerm_resource_group.src.name
, which is not recognised byReferenceTargetsForOriginAtPos()
. Instead, it wants the pos is within range column 14 to column 45.Furthermore, we also want to get the exact position of, e.g. for
AttributeSymbol
, the key and value positions. These are missing in the current symbol types.This PR adds:
*hcl.Attribute
forAttributeSymbol
*hcl.Block
forBlockSymbol
ExprSymbol
, it is a bit complex:hcl.Expression
toExpr
fieldhclsyntax.ObjectConsItem
toItem
field