diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba8778..d4ab590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to the Docker Language Server will be documented in this file. +## [Unreleased] + +### Fixed + +- Bake + - textDocument/completion + - check the type of the block before suggesting items ([#422](https://github.com/docker/docker-language-server/issues/422)) + ## [0.16.0] - 2025-08-12 ### Added diff --git a/internal/bake/hcl/completion.go b/internal/bake/hcl/completion.go index bb1b885..613f38b 100644 --- a/internal/bake/hcl/completion.go +++ b/internal/bake/hcl/completion.go @@ -36,7 +36,7 @@ func Completion(ctx context.Context, params *protocol.CompletionParams, manager } for _, b := range body.Blocks { - if isInsideBodyRangeLines(b.Body, int(params.Position.Line)+1) { + if b.Type == "target" && isInsideBodyRangeLines(b.Body, int(params.Position.Line)+1) { attributes := b.Body.Attributes if attribute, ok := attributes["inherits"]; ok && isInsideRange(attribute.Expr.Range(), params.Position) { if tupleConsExpr, ok := attribute.Expr.(*hclsyntax.TupleConsExpr); ok { diff --git a/internal/bake/hcl/completion_test.go b/internal/bake/hcl/completion_test.go index b004ef5..c9d1df9 100644 --- a/internal/bake/hcl/completion_test.go +++ b/internal/bake/hcl/completion_test.go @@ -367,6 +367,20 @@ func TestCompletion(t *testing.T) { }, }, }, + { + name: "inherits attribute should not suggest anything in a variable block", + content: "variable \"var\" {\n inherits = [\"\"]\n}\ntarget \"base\" {}", + line: 1, + character: 15, + items: []protocol.CompletionItem{}, + }, + { + name: "network attribute should not suggest anything in a variable block", + content: "variable \"var\" {\n network = \"\"\n}\ntarget \"base\" {}", + line: 1, + character: 13, + items: []protocol.CompletionItem{}, + }, } bakeFilePath := filepath.Join(completionTestFolderPath, "docker-bake.hcl")