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 @@ -9,6 +9,9 @@ All notable changes to the Docker Language Server will be documented in this fil
- Dockerfile
- textDocument/codeAction
- `InvalidBaseImagePlatform` warnings can now be ignored with a code action ([#464](https://github.com/docker/docker-language-server/issues/464))
- Bake
- textDocument/publishDiagnostics
- flag `annotations` in a `target` block without an equals sign as an error ([#99](https://github.com/docker/docker-language-server/issues/99))

### Fixed

Expand Down
20 changes: 20 additions & 0 deletions internal/bake/hcl/diagnosticsCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ func (c *BakeHCLDiagnosticsCollector) CollectDiagnostics(source, workspaceFolder
}
}

if attribute, ok := block.Body.Attributes["annotations"]; ok {
if expr, ok := attribute.Expr.(*hclsyntax.TupleConsExpr); ok {
for _, e := range expr.Exprs {
if templateExpr, ok := e.(*hclsyntax.TemplateExpr); ok {
if templateExpr.IsStringLiteral() {
value, _ := templateExpr.Value(&hcl.EvalContext{})
if len(strings.Split(value.AsString(), "=")) < 2 {
diagnostics = append(diagnostics, protocol.Diagnostic{
Message: fmt.Sprintf(`invalid annotation "%v", expected key=value`, value.AsString()),
Source: types.CreateStringPointer(source),
Severity: types.CreateDiagnosticSeverityPointer(protocol.DiagnosticSeverityError),
Range: createProtocolRange(templateExpr.SrcRange, false),
})
}
}
}
}
}
}

_, dockerfilePath, err := bakeDoc.DockerfileForTarget(block)
if dockerfilePath == "" || err != nil {
continue
Expand Down
18 changes: 18 additions & 0 deletions internal/bake/hcl/diagnosticsCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ target "build" {
},
},
},
{
name: "annotations attribute has no equals sign",
content: `
target "t1" {
annotations = [ "abc" ]
}`,
diagnostics: []protocol.Diagnostic{
{
Message: `invalid annotation "abc", expected key=value`,
Source: types.CreateStringPointer("docker-language-server"),
Severity: types.CreateDiagnosticSeverityPointer(protocol.DiagnosticSeverityError),
Range: protocol.Range{
Start: protocol.Position{Line: 2, Character: 18},
End: protocol.Position{Line: 2, Character: 23},
},
},
},
},
}

wd, err := os.Getwd()
Expand Down
Loading