Skip to content

Commit b7964ef

Browse files
authored
Merge pull request #113 from docker/fix-completion-panic
Prevent completion error with empty arrays
2 parents e0ff65b + 2b4db5a commit b7964ef

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to the Docker Language Server will be documented in this file.
44

5+
## [0.4.1] - 2025-04-29
6+
7+
### Fixed
8+
9+
- Compose
10+
- textDocument/completion
11+
- protect the completion calculation code from throwing errors when encountering empty array items ([#112](https://github.com/docker/docker-language-server/issues/112))
12+
513
## [0.4.0] - 2025-04-28
614

715
### Added

internal/compose/completion.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ func walkNodes(line int, nodes []*yaml.Node) ([]*yaml.Node, *yaml.Node) {
164164
if nodes[i].Kind == yaml.MappingNode {
165165
return walkNodes(line, nodes[i].Content)
166166
}
167-
if len(nodes) == 1 {
168-
return []*yaml.Node{nodes[i]}, nil
169-
}
170-
return []*yaml.Node{nodes[i]}, nodes[i+1]
167+
return []*yaml.Node{nodes[i]}, nil
171168
} else if line < nodes[i].Line {
172169
break
173170
}

internal/compose/completion_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,17 @@ services:
15981598
character: 22,
15991599
list: nil,
16001600
},
1601+
{
1602+
name: "bug",
1603+
content: `
1604+
networks:
1605+
-
1606+
-
1607+
- `,
1608+
line: 4,
1609+
character: 2,
1610+
list: nil,
1611+
},
16011612
}
16021613

16031614
composeFileURI := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "compose.yaml")), "/"))

0 commit comments

Comments
 (0)