Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to the Docker Language Server will be documented in this fil
- Compose
- textDocument/completion
- prevent errors if an empty JSON object is the content of the YAML file ([#330](https://github.com/docker/docker-language-server/issues/330))
- check character offset before processing to prevent errors ([#333](https://github.com/docker/docker-language-server/issues/333))

## [0.12.0] - 2025-06-12

Expand Down
5 changes: 3 additions & 2 deletions internal/compose/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ func buildTargetCompletionItems(params *protocol.CompletionParams, manager *docu
} else if prefix, ok := path[3].Value.(*ast.StringNode); ok {
if int(params.Position.Line) == path[3].Value.GetToken().Position.Line-1 {
offset := int(params.Position.Character) - path[3].Value.GetToken().Position.Column + 1
// offset can be greater than the length if there's just empty whitespace after the string value
if offset <= len(prefix.Value) {
// offset can be greater than the length if there's just empty whitespace after the string value,
// must be non-negative, if negative it suggests the cursor is in the whitespace before the attribute's value
if offset >= 0 && offset <= len(prefix.Value) {
return createBuildStageItems(params, manager, dockerfilePath, prefix.Value[0:offset], prefixLength), true
}
}
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 @@ -4269,6 +4269,20 @@ services:
}
},
},
{
name: "target attribute finds nothing",
dockerfileContent: "FROM scratch",
content: `
services:
postgres:
build:
target: base`,
line: 4,
character: 14,
list: func() *protocol.CompletionList {
return nil
},
},
}

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