Skip to content

Commit e898426

Browse files
authored
Merge pull request #144 from docker/highlighting-long-form-services
Support highlighting of the long form syntax for services in depends_on
2 parents 9c7d6fc + 2d4dc50 commit e898426

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to the Docker Language Server will be documented in this fil
1616
- suggest dependent secret names for the `secrets` attribute ([#135](https://github.com/docker/docker-language-server/issues/135))
1717
- textDocument/documentHighlight
1818
- support highlighting the short form `depends_on` syntax for services ([#70](https://github.com/docker/docker-language-server/issues/70))
19+
- support highlighting the long form `depends_on` syntax for services ([#71](https://github.com/docker/docker-language-server/issues/71))
1920

2021
### Fixed
2122

internal/compose/documentHighlight.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ func serviceReferences(node *ast.MappingValueNode, dependencyAttributeName strin
1818
for _, service := range sequenceNode.Values {
1919
tokens = append(tokens, service.GetToken())
2020
}
21+
} else if dependentService, ok := attributeNode.Value.(*ast.StringNode); ok {
22+
tokens = append(tokens, dependentService.GetToken())
23+
} else if mappingNode, ok := attributeNode.Value.(*ast.MappingNode); ok {
24+
for _, dependentService := range mappingNode.Values {
25+
tokens = append(tokens, dependentService.Key.GetToken())
26+
}
2127
}
2228
}
2329
}

internal/compose/documentHighlight_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ services:
4545
documentHighlight(4, 8, 4, 13, protocol.DocumentHighlightKindRead),
4646
},
4747
},
48+
{
49+
name: "read highlight on an undefined service object with no properties",
50+
content: `
51+
services:
52+
test:
53+
depends_on:
54+
test2:`,
55+
line: 4,
56+
character: 9,
57+
ranges: []protocol.DocumentHighlight{
58+
documentHighlight(4, 6, 4, 11, protocol.DocumentHighlightKindRead),
59+
},
60+
},
61+
{
62+
name: "read highlight on an undefined service object with properties",
63+
content: `
64+
services:
65+
test:
66+
depends_on:
67+
test2:
68+
condition: service_started`,
69+
line: 4,
70+
character: 9,
71+
ranges: []protocol.DocumentHighlight{
72+
documentHighlight(4, 6, 4, 11, protocol.DocumentHighlightKindRead),
73+
},
74+
},
4875
{
4976
name: "cursor not on anything meaningful",
5077
content: `

0 commit comments

Comments
 (0)