Skip to content

Commit 7dd71a7

Browse files
authored
Merge pull request #325 from docker/compose-definition-casting-check
Check node types before casting when looking up references in other files
2 parents d130e78 + 9c3ea82 commit 7dd71a7

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ All notable changes to the Docker Language Server will be documented in this fil
1818
- Compose
1919
- textDocument/completion
2020
- fix error case triggered by using code completion before the first node ([#314](https://github.com/docker/docker-language-server/issues/314))
21+
- textDocument/definition
22+
- check the type of a dependency node's value before assuming it is a map and recursing into it ([#324](https://github.com/docker/docker-language-server/issues/324))
2123
- textDocument/hover
2224
- protect the processing of included files if the node is not a proper array ([#322](https://github.com/docker/docker-language-server/issues/322))
2325
- Bake

internal/compose/definition.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ func dependencyLookup(doc document.ComposeDocument, dependencyType, name string)
6868
if mappingNode, ok := doc.Body.(*ast.MappingNode); ok {
6969
for _, node := range mappingNode.Values {
7070
if s, ok := node.Key.(*ast.StringNode); ok && s.Value == dependencyType {
71-
for _, service := range node.Value.(*ast.MappingNode).Values {
72-
if s, ok := service.Key.(*ast.StringNode); ok && s.Value == name {
73-
return service, u
71+
if m, ok := node.Value.(*ast.MappingNode); ok {
72+
for _, service := range m.Values {
73+
if s, ok := service.Key.(*ast.StringNode); ok && s.Value == name {
74+
return service, u
75+
}
7476
}
7577
}
7678
}

internal/compose/definition_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,22 @@ services:
443443
},
444444
},
445445
},
446+
{
447+
name: "dependent file is not defined properly",
448+
content: `
449+
include:
450+
- compose.other.yaml
451+
services:
452+
test:
453+
networks:
454+
- other`,
455+
otherContent: `
456+
networks: string`,
457+
line: 6,
458+
character: 11,
459+
locations: nil,
460+
links: nil,
461+
},
446462
}
447463

448464
for _, tc := range testCases {

0 commit comments

Comments
 (0)