Skip to content

Commit 60b562d

Browse files
committed
Prevent file structure code completion if it's not a service
Signed-off-by: Remy Suen <[email protected]>
1 parent d88a227 commit 60b562d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

internal/compose/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,12 @@ func folderStructureCompletionItems(documentPath document.DocumentPath, path []*
415415
}
416416

417417
func directoryForPrefix(documentPath document.DocumentPath, path []*ast.MappingValueNode, prefix string) string {
418-
if len(path) == 3 && path[2].Key.GetToken().Value == "volumes" {
418+
if len(path) == 3 && path[0].Key.GetToken().Value == "services" && path[2].Key.GetToken().Value == "volumes" {
419419
if strings.HasPrefix(prefix, "./") {
420420
_, folder := types.Concatenate(documentPath.Folder, prefix[0:strings.LastIndex(prefix, "/")], documentPath.WSLDollarSignHost)
421421
return folder
422422
}
423-
} else if len(path) == 4 && path[2].Key.GetToken().Value == "volumes" && path[3].Key.GetToken().Value == "source" {
423+
} else if len(path) == 4 && path[0].Key.GetToken().Value == "services" && path[2].Key.GetToken().Value == "volumes" && path[3].Key.GetToken().Value == "source" {
424424
if volumes, ok := path[2].Value.(*ast.SequenceNode); ok {
425425
for _, node := range volumes.Values {
426426
if volume, ok := node.(*ast.MappingNode); ok {

internal/compose/completion_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,29 @@ services:
46574657
character: 18,
46584658
list: nil,
46594659
},
4660+
{
4661+
name: "suggests nothing when volumes not under a services node",
4662+
content: `
4663+
services2:
4664+
test:
4665+
volumes:
4666+
- ./`,
4667+
line: 4,
4668+
character: 10,
4669+
list: nil,
4670+
},
4671+
{
4672+
name: "suggests nothing when volumes object not under a services node",
4673+
content: `
4674+
services2:
4675+
test:
4676+
volumes:
4677+
- type: bind
4678+
source: `,
4679+
line: 5,
4680+
character: 16,
4681+
list: nil,
4682+
},
46604683
{
46614684
name: "suggest file structure with a ./ prefix",
46624685
content: `

0 commit comments

Comments
 (0)