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 using ReferenceOriginsTargetingPos()/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 attribute name, its range spans from column 3 to column 45, which is effectively name = azurerm_resource_group.src.name, which is not recognised by ReferenceTargetsForOriginAtPos(). 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:
The underlying *hcl.Attribute for AttributeSymbol
The underlying *hcl.Block for BlockSymbol
For ExprSymbol, it is a bit complex:
If the parent Expression is a *hclsyntax.TupleConsExpr, adds the hcl.Expression to Expr field
If the parent Expression is a *hclsyntax.ObjectConsExpr, adds the hclsyntax.ObjectConsItem to Item field
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