Skip to content

Commit affe5cb

Browse files
authored
Merge pull request #315 from docker/compose-offset-completion-fix
Fix offset calculation issue when calculating Compose suggestions
2 parents bc115fa + cd4d64b commit affe5cb

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
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+
## [Unreleased]
6+
7+
### Fixed
8+
9+
- Compose
10+
- textDocument/completion
11+
- fix error case triggered by using code completion before the first node ([#314](https://github.com/docker/docker-language-server/issues/314))
12+
513
## [0.11.0] - 2025-06-10
614

715
### Added

internal/compose/completion.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ func Completion(ctx context.Context, params *protocol.CompletionParams, manager
206206
character := int(params.Position.Character) + 1
207207
path := constructCompletionNodePath(file, line)
208208
if len(path) == 0 {
209+
if topLevelNodeOffset != -1 && params.Position.Character != uint32(topLevelNodeOffset) {
210+
return nil, nil
211+
}
209212
return &protocol.CompletionList{Items: createTopLevelItems()}, nil
210213
} else if len(path) == 1 {
211214
return nil, nil
@@ -570,6 +573,8 @@ func NodeStructure(line int, rootNodes []*ast.MappingValueNode) []*ast.MappingVa
570573
candidate = node
571574
} else if node.GetToken().Position.Line == line {
572575
return []*ast.MappingValueNode{node}
576+
} else if candidate == nil {
577+
return []*ast.MappingValueNode{}
573578
} else {
574579
break
575580
}

internal/compose/completion_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,20 @@ services:
25592559
character: 0,
25602560
list: nil,
25612561
},
2562+
{
2563+
name: "completion is on a line before the first node and after it positionally",
2564+
content: " \nservices:",
2565+
line: 0,
2566+
character: 1,
2567+
list: nil,
2568+
},
2569+
{
2570+
name: "completion is on a line before the first node and before it positionally",
2571+
content: " \n services:",
2572+
line: 0,
2573+
character: 1,
2574+
list: nil,
2575+
},
25622576
}
25632577

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

0 commit comments

Comments
 (0)