@@ -1231,6 +1231,172 @@ output "test" {
1231
1231
}` )
1232
1232
}
1233
1233
1234
+ func TestVarReferenceCompletion_withValidData (t * testing.T ) {
1235
+ tmpDir := TempDir (t )
1236
+ InitPluginCache (t , tmpDir .Path ())
1237
+
1238
+ variableDecls := `variable "aaa" {}
1239
+ variable "bbb" {}
1240
+ variable "ccc" {}
1241
+ `
1242
+ f , err := os .Create (filepath .Join (tmpDir .Path (), "variables.tf" ))
1243
+ if err != nil {
1244
+ t .Fatal (err )
1245
+ }
1246
+ _ , err = f .WriteString (variableDecls )
1247
+ if err != nil {
1248
+ t .Fatal (err )
1249
+ }
1250
+ f .Close ()
1251
+
1252
+ var testSchema tfjson.ProviderSchemas
1253
+ err = json .Unmarshal ([]byte (testModuleSchemaOutput ), & testSchema )
1254
+ if err != nil {
1255
+ t .Fatal (err )
1256
+ }
1257
+
1258
+ ls := langserver .NewLangServerMock (t , NewMockSession (& MockSessionInput {
1259
+ TerraformCalls : & exec.TerraformMockCalls {
1260
+ PerWorkDir : map [string ][]* mock.Call {
1261
+ tmpDir .Path (): {
1262
+ {
1263
+ Method : "Version" ,
1264
+ Repeatability : 1 ,
1265
+ Arguments : []interface {}{
1266
+ mock .AnythingOfType ("" ),
1267
+ },
1268
+ ReturnArguments : []interface {}{
1269
+ version .Must (version .NewVersion ("0.12.0" )),
1270
+ nil ,
1271
+ nil ,
1272
+ },
1273
+ },
1274
+ {
1275
+ Method : "GetExecPath" ,
1276
+ Repeatability : 1 ,
1277
+ ReturnArguments : []interface {}{
1278
+ "" ,
1279
+ },
1280
+ },
1281
+ {
1282
+ Method : "ProviderSchemas" ,
1283
+ Repeatability : 1 ,
1284
+ Arguments : []interface {}{
1285
+ mock .AnythingOfType ("" ),
1286
+ },
1287
+ ReturnArguments : []interface {}{
1288
+ & testSchema ,
1289
+ nil ,
1290
+ },
1291
+ },
1292
+ },
1293
+ },
1294
+ }}))
1295
+ stop := ls .Start (t )
1296
+ defer stop ()
1297
+
1298
+ ls .Call (t , & langserver.CallRequest {
1299
+ Method : "initialize" ,
1300
+ ReqParams : fmt .Sprintf (`{
1301
+ "capabilities": {},
1302
+ "rootUri": %q,
1303
+ "processId": 12345
1304
+ }` , tmpDir .URI )})
1305
+ ls .Notify (t , & langserver.CallRequest {
1306
+ Method : "initialized" ,
1307
+ ReqParams : "{}" ,
1308
+ })
1309
+ ls .Call (t , & langserver.CallRequest {
1310
+ Method : "textDocument/didOpen" ,
1311
+ ReqParams : fmt .Sprintf (`{
1312
+ "textDocument": {
1313
+ "version": 0,
1314
+ "languageId": "terraform",
1315
+ "text": "output \"test\" {\n value = var.\n}\n",
1316
+ "uri": "%s/outputs.tf"
1317
+ }
1318
+ }` , tmpDir .URI )})
1319
+ ls .CallAndExpectResponse (t , & langserver.CallRequest {
1320
+ Method : "textDocument/completion" ,
1321
+ ReqParams : fmt .Sprintf (`{
1322
+ "textDocument": {
1323
+ "uri": "%s/outputs.tf"
1324
+ },
1325
+ "position": {
1326
+ "character": 14,
1327
+ "line": 1
1328
+ }
1329
+ }` , tmpDir .URI )}, `{
1330
+ "jsonrpc": "2.0",
1331
+ "id": 3,
1332
+ "result": {
1333
+ "isIncomplete": false,
1334
+ "items": [
1335
+ {
1336
+ "label": "var.aaa",
1337
+ "labelDetails": {},
1338
+ "kind": 6,
1339
+ "detail": "dynamic",
1340
+ "insertTextFormat": 1,
1341
+ "textEdit": {
1342
+ "range": {
1343
+ "start": {
1344
+ "line": 1,
1345
+ "character": 10
1346
+ },
1347
+ "end": {
1348
+ "line": 1,
1349
+ "character": 14
1350
+ }
1351
+ },
1352
+ "newText": "var.aaa"
1353
+ }
1354
+ },
1355
+ {
1356
+ "label": "var.bbb",
1357
+ "labelDetails": {},
1358
+ "kind": 6,
1359
+ "detail": "dynamic",
1360
+ "insertTextFormat": 1,
1361
+ "textEdit": {
1362
+ "range": {
1363
+ "start": {
1364
+ "line": 1,
1365
+ "character": 10
1366
+ },
1367
+ "end": {
1368
+ "line": 1,
1369
+ "character": 14
1370
+ }
1371
+ },
1372
+ "newText": "var.bbb"
1373
+ }
1374
+ },
1375
+ {
1376
+ "label": "var.ccc",
1377
+ "labelDetails": {},
1378
+ "kind": 6,
1379
+ "detail": "dynamic",
1380
+ "insertTextFormat": 1,
1381
+ "textEdit": {
1382
+ "range": {
1383
+ "start": {
1384
+ "line": 1,
1385
+ "character": 10
1386
+ },
1387
+ "end": {
1388
+ "line": 1,
1389
+ "character": 14
1390
+ }
1391
+ },
1392
+ "newText": "var.ccc"
1393
+ }
1394
+ }
1395
+ ]
1396
+ }
1397
+ }` )
1398
+ }
1399
+
1234
1400
func tfExecutor (t * testing.T , workdir , tfVersion string ) exec.TerraformExecutor {
1235
1401
ctx := context .Background ()
1236
1402
installDir := filepath .Join (t .TempDir (), "hcinstall" )
0 commit comments