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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ All notable changes to the Docker Language Server will be documented in this fil
- 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))
- Bake
- textDocument/inlineCompletion
- check that the request is within the document's bounds when processing the request ([#318](https://github.com/docker/docker-language-server/issues/318))

## [0.11.0] - 2025-06-10

Expand Down
14 changes: 13 additions & 1 deletion e2e-tests/inlineCompletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ func TestInlineCompletion(t *testing.T) {
testCases := []struct {
name string
content string
line protocol.UInteger
character protocol.UInteger
dockerfileContent string
items []protocol.InlineCompletionItem
}{
{
name: "one build stage",
content: "",
line: 0,
character: 0,
dockerfileContent: "FROM scratch AS simple",
items: []protocol.InlineCompletionItem{
{
Expand All @@ -48,6 +52,14 @@ func TestInlineCompletion(t *testing.T) {
},
},
},
{
name: "outside document bounds",
content: "",
line: 1,
character: 0,
dockerfileContent: "FROM scratch AS simple",
items: nil,
},
}

temporaryDockerfile := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "Dockerfile")), "/"))
Expand Down Expand Up @@ -81,7 +93,7 @@ func TestInlineCompletion(t *testing.T) {
err = conn.Call(context.Background(), protocol.MethodTextDocumentInlineCompletion, protocol.InlineCompletionParams{
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
TextDocument: protocol.TextDocumentIdentifier{URI: didOpenBakeFile.TextDocument.URI},
Position: protocol.Position{Line: 0, Character: 0},
Position: protocol.Position{Line: tc.line, Character: tc.character},
},
}, &result)
require.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions internal/bake/hcl/inlineCompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func shouldSuggest(content []byte, body *hclsyntax.Body, position protocol.Posit
}

lines := strings.Split(string(content), "\n")
if len(lines) <= int(position.Line) {
return false
}
return strings.TrimSpace(lines[position.Line]) != "}"
}

Expand Down
Loading