@@ -86,6 +86,104 @@ func TestCompletionAtPos_BodySchema_Extensions(t *testing.T) {
86
86
},
87
87
}),
88
88
},
89
+ {
90
+ "count attribute completion with DependentBody" ,
91
+ & schema.BodySchema {
92
+ Blocks : map [string ]* schema.BlockSchema {
93
+ "resource" : {
94
+ Labels : []* schema.LabelSchema {
95
+ {
96
+ Name : "type" ,
97
+ IsDepKey : true ,
98
+ },
99
+ {
100
+ Name : "name" ,
101
+ },
102
+ },
103
+ Body : & schema.BodySchema {
104
+ Extensions : & schema.BodyExtensions {
105
+ Count : true ,
106
+ },
107
+ },
108
+ DependentBody : map [schema.SchemaKey ]* schema.BodySchema {
109
+ schema .NewSchemaKey (schema.DependencyKeys {
110
+ Labels : []schema.LabelDependent {
111
+ {Index : 0 , Value : "aws_instance" },
112
+ },
113
+ }): {
114
+ Attributes : map [string ]* schema.AttributeSchema {
115
+ "instance_size" : {
116
+ IsOptional : true ,
117
+ Expr : schema .LiteralTypeOnly (cty .String ),
118
+ },
119
+ },
120
+ },
121
+ },
122
+ },
123
+ },
124
+ },
125
+ reference.Targets {},
126
+ `resource "aws_instance" "foo" {
127
+
128
+ }
129
+ ` ,
130
+ hcl.Pos {
131
+ Line : 2 ,
132
+ Column : 1 ,
133
+ Byte : 32 ,
134
+ },
135
+ lang .CompleteCandidates ([]lang.Candidate {
136
+ {
137
+ Label : "count" ,
138
+ Description : lang.MarkupContent {
139
+ Value : "The distinct index number (starting with 0) corresponding to the instance" ,
140
+ Kind : lang .MarkdownKind ,
141
+ },
142
+ Detail : "optional, number" ,
143
+ TextEdit : lang.TextEdit {
144
+ Range : hcl.Range {
145
+ Filename : "test.tf" ,
146
+ Start : hcl.Pos {
147
+ Line : 2 ,
148
+ Column : 1 ,
149
+ Byte : 32 ,
150
+ },
151
+ End : hcl.Pos {
152
+ Line : 2 ,
153
+ Column : 1 ,
154
+ Byte : 32 ,
155
+ },
156
+ },
157
+ NewText : "count" ,
158
+ Snippet : "count = " ,
159
+ },
160
+ TriggerSuggest : true ,
161
+ Kind : lang .AttributeCandidateKind ,
162
+ },
163
+ {
164
+ Label : "instance_size" ,
165
+ Detail : "optional, string" ,
166
+ TextEdit : lang.TextEdit {
167
+ Range : hcl.Range {
168
+ Filename : "test.tf" ,
169
+ Start : hcl.Pos {
170
+ Line : 2 ,
171
+ Column : 1 ,
172
+ Byte : 32 ,
173
+ },
174
+ End : hcl.Pos {
175
+ Line : 2 ,
176
+ Column : 1 ,
177
+ Byte : 32 ,
178
+ },
179
+ },
180
+ NewText : "instance_size" ,
181
+ Snippet : `instance_size = "${1:value}"` ,
182
+ },
183
+ Kind : lang .AttributeCandidateKind ,
184
+ },
185
+ }),
186
+ },
89
187
{
90
188
"count attribute completion does not complete count when extensions not enabled" ,
91
189
& schema.BodySchema {
0 commit comments