Skip to content

Commit ecf8c06

Browse files
committed
Ignore inline completion request if parameters are out of bounds
Signed-off-by: Remy Suen <remy.suen@docker.com>
1 parent 9a4babb commit ecf8c06

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ All notable changes to the Docker Language Server will be documented in this fil
1515
- Compose
1616
- textDocument/completion
1717
- fix error case triggered by using code completion before the first node ([#314](https://github.com/docker/docker-language-server/issues/314))
18+
- Bake
19+
- textDocument/inlineCompletion
20+
- check that the request is within the document's bounds when processing the request ([#318](https://github.com/docker/docker-language-server/issues/318))
1821

1922
## [0.11.0] - 2025-06-10
2023

e2e-tests/inlineCompletion_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ func TestInlineCompletion(t *testing.T) {
3131
testCases := []struct {
3232
name string
3333
content string
34+
line protocol.UInteger
35+
character protocol.UInteger
3436
dockerfileContent string
3537
items []protocol.InlineCompletionItem
3638
}{
3739
{
3840
name: "one build stage",
3941
content: "",
42+
line: 0,
43+
character: 0,
4044
dockerfileContent: "FROM scratch AS simple",
4145
items: []protocol.InlineCompletionItem{
4246
{
@@ -48,6 +52,14 @@ func TestInlineCompletion(t *testing.T) {
4852
},
4953
},
5054
},
55+
{
56+
name: "outside document bounds",
57+
content: "",
58+
line: 1,
59+
character: 0,
60+
dockerfileContent: "FROM scratch AS simple",
61+
items: nil,
62+
},
5163
}
5264

5365
temporaryDockerfile := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "Dockerfile")), "/"))
@@ -81,7 +93,7 @@ func TestInlineCompletion(t *testing.T) {
8193
err = conn.Call(context.Background(), protocol.MethodTextDocumentInlineCompletion, protocol.InlineCompletionParams{
8294
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
8395
TextDocument: protocol.TextDocumentIdentifier{URI: didOpenBakeFile.TextDocument.URI},
84-
Position: protocol.Position{Line: 0, Character: 0},
96+
Position: protocol.Position{Line: tc.line, Character: tc.character},
8597
},
8698
}, &result)
8799
require.NoError(t, err)

internal/bake/hcl/inlineCompletion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func shouldSuggest(content []byte, body *hclsyntax.Body, position protocol.Posit
4040
}
4141

4242
lines := strings.Split(string(content), "\n")
43+
if len(lines) <= int(position.Line) {
44+
return false
45+
}
4346
return strings.TrimSpace(lines[position.Line]) != "}"
4447
}
4548

0 commit comments

Comments
 (0)