Skip to content

Fix offset calculation issue when calculating Compose suggestions #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

## [Unreleased]

### Fixed

- Compose
- textDocument/completion
- fix error case triggered by using code completion before the first node ([#314](https://github.com/docker/docker-language-server/issues/314))

## [0.11.0] - 2025-06-10

### Added
Expand Down
5 changes: 5 additions & 0 deletions internal/compose/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ func Completion(ctx context.Context, params *protocol.CompletionParams, manager
character := int(params.Position.Character) + 1
path := constructCompletionNodePath(file, line)
if len(path) == 0 {
if topLevelNodeOffset != -1 && params.Position.Character != uint32(topLevelNodeOffset) {
return nil, nil
}
return &protocol.CompletionList{Items: createTopLevelItems()}, nil
} else if len(path) == 1 {
return nil, nil
Expand Down Expand Up @@ -570,6 +573,8 @@ func NodeStructure(line int, rootNodes []*ast.MappingValueNode) []*ast.MappingVa
candidate = node
} else if node.GetToken().Position.Line == line {
return []*ast.MappingValueNode{node}
} else if candidate == nil {
return []*ast.MappingValueNode{}
} else {
break
}
Expand Down
14 changes: 14 additions & 0 deletions internal/compose/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,20 @@ services:
character: 0,
list: nil,
},
{
name: "completion is on a line before the first node and after it positionally",
content: " \nservices:",
line: 0,
character: 1,
list: nil,
},
{
name: "completion is on a line before the first node and before it positionally",
content: " \n services:",
line: 0,
character: 1,
list: nil,
},
}

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