@@ -396,25 +396,27 @@ func modifyTextEdit(file *ast.File, manager *document.Manager, documentPath docu
396
396
}
397
397
398
398
func folderStructureCompletionItems (documentPath document.DocumentPath , path []* ast.MappingValueNode , prefix string ) []protocol.CompletionItem {
399
- folder := directoryForNode (documentPath , path , prefix )
399
+ folder , hideFiles := directoryForNode (documentPath , path , prefix )
400
400
if folder != "" {
401
401
items := []protocol.CompletionItem {}
402
402
entries , _ := os .ReadDir (folder )
403
403
for _ , entry := range entries {
404
- item := protocol.CompletionItem {Label : entry .Name ()}
405
404
if entry .IsDir () {
405
+ item := protocol.CompletionItem {Label : entry .Name ()}
406
406
item .Kind = types .CreateCompletionItemKindPointer (protocol .CompletionItemKindFolder )
407
- } else {
407
+ items = append (items , item )
408
+ } else if ! hideFiles {
409
+ item := protocol.CompletionItem {Label : entry .Name ()}
408
410
item .Kind = types .CreateCompletionItemKindPointer (protocol .CompletionItemKindFile )
411
+ items = append (items , item )
409
412
}
410
- items = append (items , item )
411
413
}
412
414
return items
413
415
}
414
416
return nil
415
417
}
416
418
417
- func directoryForNode (documentPath document.DocumentPath , path []* ast.MappingValueNode , prefix string ) string {
419
+ func directoryForNode (documentPath document.DocumentPath , path []* ast.MappingValueNode , prefix string ) ( folder string , hideFiles bool ) {
418
420
if len (path ) == 3 {
419
421
switch path [0 ].Key .GetToken ().Value {
420
422
case "services" :
@@ -426,63 +428,72 @@ func directoryForNode(documentPath document.DocumentPath, path []*ast.MappingVal
426
428
// - ...
427
429
switch path [2 ].Key .GetToken ().Value {
428
430
case "env_file" :
429
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
431
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
430
432
case "label_file" :
431
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
433
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
432
434
case "volumes" :
433
- return directoryForPrefix (documentPath , prefix , "" , true )
435
+ return directoryForPrefix (documentPath , prefix , "" , true ), false
434
436
}
435
437
case "configs" :
436
438
// configs:
437
439
// configA:
438
440
// file: ...
439
441
if path [2 ].Key .GetToken ().Value == "file" {
440
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
442
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
441
443
}
442
444
case "secrets" :
443
445
// secrets:
444
446
// secretA:
445
447
// file: ...
446
448
if path [2 ].Key .GetToken ().Value == "file" {
447
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
449
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
448
450
}
449
451
}
450
452
} else if len (path ) == 4 && path [0 ].Key .GetToken ().Value == "services" {
451
453
// services:
452
454
// serviceA:
453
455
// build:
456
+ // context: ... (folders only)
454
457
// dockerfile: ...
455
458
// credential_spec:
456
459
// file: ...
460
+ // env_file:
461
+ // - path: ...
457
462
// extends:
458
463
// file: ...
459
464
// volumes:
460
465
// - type: bind
461
466
// source: ...
462
- if path [2 ].Key .GetToken ().Value == "build" && path [3 ].Key .GetToken ().Value == "dockerfile" {
463
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
464
- }
465
- if (path [2 ].Key .GetToken ().Value == "extends" || path [2 ].Key .GetToken ().Value == "credential_spec" ) && path [3 ].Key .GetToken ().Value == "file" {
466
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , false )
467
- }
468
- if path [2 ].Key .GetToken ().Value == "volumes" && path [3 ].Key .GetToken ().Value == "source" {
467
+ if path [2 ].Key .GetToken ().Value == "build" {
468
+ if path [3 ].Key .GetToken ().Value == "context" {
469
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), true
470
+ } else if path [3 ].Key .GetToken ().Value == "dockerfile" {
471
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
472
+ }
473
+ } else if (path [2 ].Key .GetToken ().Value == "extends" || path [2 ].Key .GetToken ().Value == "credential_spec" ) && path [3 ].Key .GetToken ().Value == "file" {
474
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
475
+ } else if path [2 ].Key .GetToken ().Value == "env_file" && path [3 ].Key .GetToken ().Value == "path" {
476
+ if _ , ok := path [2 ].Value .(* ast.SequenceNode ); ok {
477
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , false ), false
478
+ }
479
+ } else if path [2 ].Key .GetToken ().Value == "volumes" && path [3 ].Key .GetToken ().Value == "source" {
469
480
if volumes , ok := path [2 ].Value .(* ast.SequenceNode ); ok {
470
481
for _ , node := range volumes .Values {
471
482
if volume , ok := node .(* ast.MappingNode ); ok {
472
483
if slices .Contains (volume .Values , path [3 ]) {
473
484
for _ , property := range volume .Values {
474
485
if property .Key .GetToken ().Value == "type" && property .Value .GetToken ().Value == "bind" {
475
- return directoryForPrefix (documentPath , prefix , documentPath .Folder , true )
486
+ return directoryForPrefix (documentPath , prefix , documentPath .Folder , true ), false
476
487
}
477
488
}
478
- return ""
489
+ return "" , false
479
490
}
480
491
}
481
492
}
482
493
}
483
494
}
484
495
}
485
- return ""
496
+ return "" , false
486
497
}
487
498
488
499
func directoryForPrefix (documentPath document.DocumentPath , prefix , defaultValue string , prefixRequired bool ) string {
0 commit comments