Skip to content

Update Compose schema to the latest version #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the Docker Language Server will be documented in this fil

## [Unreleased]

### Added

- updated Compose schema to the latest version ([#117](https://github.com/docker/docker-language-server/issues/117))

### Fixed

- Compose
Expand Down
31 changes: 23 additions & 8 deletions internal/compose/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,23 +549,38 @@ configs:
character: 0,
list: &protocol.CompletionList{
Items: []protocol.CompletionItem{
{Label: "configs"},
{
Documentation: "compose sub-projects to be included.",
Label: "configs",
Documentation: "Configurations for services in the project",
},
{
Label: "include",
Documentation: "compose sub-projects to be included.",
},
{
Documentation: "define the Compose project name, until user defines one explicitly.",
Label: "name",
Documentation: "define the Compose project name, until user defines one explicitly.",
},
{
Label: "networks",
Documentation: "Networks that are shared among multiple services",
},
{
Label: "secrets",
Documentation: "Secrets that are shared among multiple services",
},
{
Label: "services",
Documentation: "The services in your project",
},
{Label: "networks"},
{Label: "secrets"},
{Label: "services"},
{
Documentation: "declared for backward compatibility, ignored.",
Label: "version",
Documentation: "declared for backward compatibility, ignored.",
},
{
Label: "volumes",
Documentation: "Named volumes that are shared among multiple services",
},
{Label: "volumes"},
},
},
},
Expand Down
67 changes: 39 additions & 28 deletions internal/compose/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"$ref": "#/definitions/service"
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "The services in your project"
},

"networks": {
Expand All @@ -40,7 +41,8 @@
"^[a-zA-Z0-9._-]+$": {
"$ref": "#/definitions/network"
}
}
},
"description": "Networks that are shared among multiple services"
},

"volumes": {
Expand All @@ -50,7 +52,8 @@
"$ref": "#/definitions/volume"
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "Named volumes that are shared among multiple services"
},

"secrets": {
Expand All @@ -60,7 +63,8 @@
"$ref": "#/definitions/secret"
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "Secrets that are shared among multiple services"
},

"configs": {
Expand All @@ -70,7 +74,8 @@
"$ref": "#/definitions/config"
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "Configurations for services in the project"
}
},

Expand All @@ -93,11 +98,11 @@
{
"type": "object",
"properties": {
"context": {"type": "string"},
"dockerfile": {"type": "string"},
"context": {"type": "string", "description": "The context used for building the image"},
"dockerfile": {"type": "string", "description": "The Dockerfile used for building the image"},
"dockerfile_inline": {"type": "string"},
"entitlements": {"type": "array", "items": {"type": "string"}},
"args": {"$ref": "#/definitions/list_or_dict"},
"args": {"$ref": "#/definitions/list_or_dict", "description": "Arguments used during the image build process"},
"ssh": {"$ref": "#/definitions/list_or_dict"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"type": "array", "items": {"type": "string"}},
Expand Down Expand Up @@ -152,9 +157,9 @@
"cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"cgroup": {"type": "string", "enum": ["host", "private"]},
"cgroup_parent": {"type": "string"},
"command": {"$ref": "#/definitions/command"},
"command": {"$ref": "#/definitions/command", "description": "The command that will be run in the container"},
"configs": {"$ref": "#/definitions/service_config_or_secret"},
"container_name": {"type": "string"},
"container_name": {"type": "string", "description": "The name that will be given to the container"},
"cpu_count": {"oneOf": [
{"type": "string"},
{"type": "integer", "minimum": 0}
Expand Down Expand Up @@ -206,7 +211,8 @@
}
}
}
]
],
"description": "Other services that this service depends on, which will be started before this one"
},
"device_cgroup_rules": {"$ref": "#/definitions/list_of_strings"},
"devices": {
Expand All @@ -232,17 +238,18 @@
"dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true},
"dns_search": {"$ref": "#/definitions/string_or_list"},
"domainname": {"type": "string"},
"entrypoint": {"$ref": "#/definitions/command"},
"env_file": {"$ref": "#/definitions/env_file"},
"entrypoint": {"$ref": "#/definitions/command", "description": "The entrypoint to the application in the container"},
"env_file": {"$ref": "#/definitions/env_file", "description": "Files containing environment variables that will be included"},
"label_file": {"$ref": "#/definitions/label_file"},
"environment": {"$ref": "#/definitions/list_or_dict"},
"environment": {"$ref": "#/definitions/list_or_dict", "description": "Environment variables that will be included"},

"expose": {
"type": "array",
"items": {
"type": ["string", "number"]
},
"uniqueItems": true
"uniqueItems": true,
"description": "Ports exposed to the other services but not to the host machine"
},
"extends": {
"oneOf": [
Expand Down Expand Up @@ -283,13 +290,13 @@
},
"uniqueItems": true
},
"healthcheck": {"$ref": "#/definitions/healthcheck"},
"healthcheck": {"$ref": "#/definitions/healthcheck", "description": "A command for checking if the container is healthy"},
"hostname": {"type": "string"},
"image": {"type": "string"},
"image": {"type": "string", "description": "The image that will be pulled for the service. If `build` is specified, the built image will be given this tag."},
"init": {"type": ["boolean", "string"]},
"ipc": {"type": "string"},
"isolation": {"type": "string"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"labels": {"$ref": "#/definitions/list_or_dict", "description": "Labels that will be given to the container"},
"links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"logging": {
"type": "object",
Expand All @@ -303,7 +310,8 @@
}
},
"additionalProperties": false,
"patternProperties": {"^x-": {}}
"patternProperties": {"^x-": {}},
"description": "Settings for logging for this service"
},
"mac_address": {"type": "string"},
"mem_limit": {"type": ["number", "string"]},
Expand Down Expand Up @@ -346,7 +354,8 @@
},
"additionalProperties": false
}
]
],
"description": "The service will be included in these networks, allowing it to reach other containers on the same network"
},
"oom_kill_disable": {"type": ["boolean", "string"]},
"oom_score_adj": {"oneOf": [
Expand Down Expand Up @@ -378,12 +387,13 @@
}
]
},
"uniqueItems": true
"uniqueItems": true,
"description": "Ports that will be exposed to the host"
},
"post_start": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
"pre_stop": {"type": "array", "items": {"$ref": "#/definitions/service_hook"}},
"privileged": {"type": ["boolean", "string"]},
"profiles": {"$ref": "#/definitions/list_of_strings"},
"profiles": {"$ref": "#/definitions/list_of_strings", "description": "Profiles that this service is a part of. When the profile is started, this service will be started."},
"pull_policy": {"type": "string",
"pattern": "always|never|build|if_not_present|missing|refresh|daily|weekly|every_([0-9]+[wdhms])+"
},
Expand All @@ -398,7 +408,7 @@
},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"shm_size": {"type": ["number", "string"]},
"secrets": {"$ref": "#/definitions/service_config_or_secret"},
"secrets": {"$ref": "#/definitions/service_config_or_secret", "description": "Secrets the service will have access to"},
"sysctls": {"$ref": "#/definitions/list_or_dict"},
"stdin_open": {"type": ["boolean", "string"]},
"stop_grace_period": {"type": "string"},
Expand All @@ -407,7 +417,7 @@
"tmpfs": {"$ref": "#/definitions/string_or_list"},
"tty": {"type": ["boolean", "string"]},
"ulimits": {"$ref": "#/definitions/ulimits"},
"user": {"type": "string"},
"user": {"type": "string", "description": "The username under which the app in the container will be started"},
"uts": {"type": "string"},
"userns_mode": {"type": "string"},
"volumes": {
Expand Down Expand Up @@ -475,14 +485,15 @@
}
]
},
"uniqueItems": true
"uniqueItems": true,
"description": "Named volumes and paths on the host mapped to paths in the container"
},
"volumes_from": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
},
"working_dir": {"type": "string"}
"working_dir": {"type": "string", "description": "The working directory in which the entrypoint or command will be run"}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false
Expand Down Expand Up @@ -710,7 +721,7 @@
"type": ["object", "null"],
"properties": {
"name": {"type": "string"},
"driver": {"type": "string"},
"driver": {"type": "string", "description": "The driver used for this network"},
"driver_opts": {
"type": "object",
"patternProperties": {
Expand Down Expand Up @@ -773,7 +784,7 @@
"type": ["object", "null"],
"properties": {
"name": {"type": "string"},
"driver": {"type": "string"},
"driver": {"type": "string", "description": "The driver used for this volume"},
"driver_opts": {
"type": "object",
"patternProperties": {
Expand Down
6 changes: 3 additions & 3 deletions internal/compose/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func Hover(ctx context.Context, params *protocol.HoverParams, doc document.Compo
lines := strings.Split(string(doc.Input()), "\n")
character := int(params.Position.Character) + 1
topLevel, _, _ := NodeStructure(line, root.Content[0].Content)
return hoverLookup(composeSchema, topLevel, character, len(lines[params.Position.Line])+1), nil
return hoverLookup(composeSchema, topLevel, line, character, len(lines[params.Position.Line])+1), nil
}
return nil, nil
}

func hoverLookup(schema *jsonschema.Schema, nodes []*yaml.Node, column, lineLength int) *protocol.Hover {
func hoverLookup(schema *jsonschema.Schema, nodes []*yaml.Node, line, column, lineLength int) *protocol.Hover {
for _, node := range nodes {
if schema.Ref != nil {
schema = schema.Ref
Expand Down Expand Up @@ -70,7 +70,7 @@ func hoverLookup(schema *jsonschema.Schema, nodes []*yaml.Node, column, lineLeng
}
}

if node.Column+len(node.Value) >= column && property.Description != "" {
if node.Line == line && node.Column+len(node.Value) >= column && property.Description != "" {
return &protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.MarkupKindPlainText,
Expand Down
3 changes: 1 addition & 2 deletions internal/compose/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ services:
require.Nil(t, result.Range)
markupContent, ok := result.Contents.(protocol.MarkupContent)
require.True(t, ok)
require.Equal(t, tc.result.Contents.(protocol.MarkupContent).Kind, markupContent.Kind)
require.Equal(t, tc.result.Contents.(protocol.MarkupContent).Value, markupContent.Value)
require.Equal(t, tc.result.Contents, markupContent)
}
})
}
Expand Down
Loading