@@ -1473,6 +1473,7 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1473
1473
name string
1474
1474
attrSchema map [string ]* schema.AttributeSchema
1475
1475
refs reference.Targets
1476
+ origins reference.Origins
1476
1477
cfg string
1477
1478
expectedTokens []lang.SemanticToken
1478
1479
}{
@@ -1486,6 +1487,27 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1486
1487
},
1487
1488
},
1488
1489
reference.Targets {},
1490
+ reference.Origins {
1491
+ reference.LocalOrigin {
1492
+ Addr : lang.Address {
1493
+ lang.RootStep {Name : "var" },
1494
+ lang.AttrStep {Name : "blah" },
1495
+ },
1496
+ Range : hcl.Range {
1497
+ Filename : "test.tf" ,
1498
+ Start : hcl.Pos {
1499
+ Line : 1 ,
1500
+ Column : 7 ,
1501
+ Byte : 6 ,
1502
+ },
1503
+ End : hcl.Pos {
1504
+ Line : 1 ,
1505
+ Column : 15 ,
1506
+ Byte : 14 ,
1507
+ },
1508
+ },
1509
+ },
1510
+ },
1489
1511
`attr = var.blah
1490
1512
` ,
1491
1513
[]lang.SemanticToken {
@@ -1526,6 +1548,32 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1526
1548
Type : cty .Bool ,
1527
1549
},
1528
1550
},
1551
+ reference.Origins {
1552
+ reference.LocalOrigin {
1553
+ Addr : lang.Address {
1554
+ lang.RootStep {Name : "var" },
1555
+ lang.AttrStep {Name : "blah" },
1556
+ },
1557
+ Range : hcl.Range {
1558
+ Filename : "test.tf" ,
1559
+ Start : hcl.Pos {
1560
+ Line : 1 ,
1561
+ Column : 7 ,
1562
+ Byte : 6 ,
1563
+ },
1564
+ End : hcl.Pos {
1565
+ Line : 1 ,
1566
+ Column : 15 ,
1567
+ Byte : 14 ,
1568
+ },
1569
+ },
1570
+ Constraints : reference.OriginConstraints {
1571
+ reference.OriginConstraint {
1572
+ OfType : cty .String ,
1573
+ },
1574
+ },
1575
+ },
1576
+ },
1529
1577
`attr = var.blah
1530
1578
` ,
1531
1579
[]lang.SemanticToken {
@@ -1566,6 +1614,32 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1566
1614
Type : cty .String ,
1567
1615
},
1568
1616
},
1617
+ reference.Origins {
1618
+ reference.LocalOrigin {
1619
+ Addr : lang.Address {
1620
+ lang.RootStep {Name : "var" },
1621
+ lang.AttrStep {Name : "blah" },
1622
+ },
1623
+ Range : hcl.Range {
1624
+ Filename : "test.tf" ,
1625
+ Start : hcl.Pos {
1626
+ Line : 1 ,
1627
+ Column : 7 ,
1628
+ Byte : 6 ,
1629
+ },
1630
+ End : hcl.Pos {
1631
+ Line : 1 ,
1632
+ Column : 15 ,
1633
+ Byte : 14 ,
1634
+ },
1635
+ },
1636
+ Constraints : reference.OriginConstraints {
1637
+ reference.OriginConstraint {
1638
+ OfType : cty .String ,
1639
+ },
1640
+ },
1641
+ },
1642
+ },
1569
1643
`attr = var.blah
1570
1644
` ,
1571
1645
[]lang.SemanticToken {
@@ -1640,6 +1714,32 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1640
1714
ScopeId : lang .ScopeId ("foo" ),
1641
1715
},
1642
1716
},
1717
+ reference.Origins {
1718
+ reference.LocalOrigin {
1719
+ Addr : lang.Address {
1720
+ lang.RootStep {Name : "var" },
1721
+ lang.AttrStep {Name : "blah" },
1722
+ },
1723
+ Range : hcl.Range {
1724
+ Filename : "test.tf" ,
1725
+ Start : hcl.Pos {
1726
+ Line : 1 ,
1727
+ Column : 7 ,
1728
+ Byte : 6 ,
1729
+ },
1730
+ End : hcl.Pos {
1731
+ Line : 1 ,
1732
+ Column : 15 ,
1733
+ Byte : 14 ,
1734
+ },
1735
+ },
1736
+ Constraints : reference.OriginConstraints {
1737
+ reference.OriginConstraint {
1738
+ OfScopeId : lang .ScopeId ("foo" ),
1739
+ },
1740
+ },
1741
+ },
1742
+ },
1643
1743
`attr = var.blah
1644
1744
` ,
1645
1745
[]lang.SemanticToken {
@@ -1716,6 +1816,33 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1716
1816
},
1717
1817
},
1718
1818
},
1819
+ reference.Origins {
1820
+ reference.LocalOrigin {
1821
+ Addr : lang.Address {
1822
+ lang.RootStep {Name : "var" },
1823
+ lang.AttrStep {Name : "foo" },
1824
+ lang.IndexStep {Key : cty .StringVal ("test" )},
1825
+ lang.AttrStep {Name : "bar" },
1826
+ lang.IndexStep {Key : cty .NumberIntVal (4 )},
1827
+ },
1828
+ Range : hcl.Range {
1829
+ Filename : "test.tf" ,
1830
+ Start : hcl.Pos {
1831
+ Line : 1 ,
1832
+ Column : 7 ,
1833
+ Byte : 6 ,
1834
+ },
1835
+ End : hcl.Pos {
1836
+ Line : 1 ,
1837
+ Column : 29 ,
1838
+ Byte : 28 ,
1839
+ },
1840
+ },
1841
+ Constraints : reference.OriginConstraints {
1842
+ reference.OriginConstraint {},
1843
+ },
1844
+ },
1845
+ },
1719
1846
`attr = var.foo["test"].bar[4]
1720
1847
` ,
1721
1848
[]lang.SemanticToken {
@@ -1841,6 +1968,33 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1841
1968
Type : cty .DynamicPseudoType ,
1842
1969
},
1843
1970
},
1971
+ reference.Origins {
1972
+ reference.LocalOrigin {
1973
+ Addr : lang.Address {
1974
+ lang.RootStep {Name : "var" },
1975
+ lang.AttrStep {Name : "foo" },
1976
+ lang.AttrStep {Name : "bar" },
1977
+ },
1978
+ Range : hcl.Range {
1979
+ Filename : "test.tf" ,
1980
+ Start : hcl.Pos {
1981
+ Line : 1 ,
1982
+ Column : 7 ,
1983
+ Byte : 6 ,
1984
+ },
1985
+ End : hcl.Pos {
1986
+ Line : 1 ,
1987
+ Column : 18 ,
1988
+ Byte : 17 ,
1989
+ },
1990
+ },
1991
+ Constraints : reference.OriginConstraints {
1992
+ reference.OriginConstraint {
1993
+ OfType : cty .String ,
1994
+ },
1995
+ },
1996
+ },
1997
+ },
1844
1998
`attr = var.foo.bar
1845
1999
` ,
1846
2000
[]lang.SemanticToken {
@@ -1914,6 +2068,47 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1914
2068
},
1915
2069
},
1916
2070
},
2071
+ {
2072
+ "matching target but missing collected origin" ,
2073
+ map [string ]* schema.AttributeSchema {
2074
+ "attr" : {
2075
+ Expr : schema.ExprConstraints {
2076
+ schema.TraversalExpr {OfType : cty .String },
2077
+ },
2078
+ },
2079
+ },
2080
+ reference.Targets {
2081
+ reference.Target {
2082
+ Addr : lang.Address {
2083
+ lang.RootStep {Name : "var" },
2084
+ lang.AttrStep {Name : "blah" },
2085
+ },
2086
+ Type : cty .String ,
2087
+ },
2088
+ },
2089
+ reference.Origins {},
2090
+ `attr = var.blah
2091
+ ` ,
2092
+ []lang.SemanticToken {
2093
+ { // attr
2094
+ Type : lang .TokenAttrName ,
2095
+ Modifiers : []lang.SemanticTokenModifier {},
2096
+ Range : hcl.Range {
2097
+ Filename : "test.tf" ,
2098
+ Start : hcl.Pos {
2099
+ Line : 1 ,
2100
+ Column : 1 ,
2101
+ Byte : 0 ,
2102
+ },
2103
+ End : hcl.Pos {
2104
+ Line : 1 ,
2105
+ Column : 5 ,
2106
+ Byte : 4 ,
2107
+ },
2108
+ },
2109
+ },
2110
+ },
2111
+ },
1917
2112
}
1918
2113
1919
2114
ctx := context .Background ()
@@ -1932,6 +2127,7 @@ func TestDecoder_SemanticTokensInFile_traversalExpression(t *testing.T) {
1932
2127
d := testPathDecoder (t , & PathContext {
1933
2128
Schema : bodySchema ,
1934
2129
ReferenceTargets : tc .refs ,
2130
+ ReferenceOrigins : tc .origins ,
1935
2131
Files : map [string ]* hcl.File {
1936
2132
"test.tf" : f ,
1937
2133
},
0 commit comments