Docker Language Server

repository·main·Indexed 41 days ago

https://github.com/docker/docker-language-server

An LSP implementation providing linting, code completion, and navigation for Dockerfiles, Compose files, and Bake files. Features include integration with Docker Scout for vulnerability info and image tag updates, BuildKit/Buildx linting, and support for Visual Studio Code and JetBrains IDEs.

Tokens
4.6K
Snippets
23
Records
30
Agent score
51%

What's inside Docker Language Server

  1. Language features for Dockerfiles, Compose, and Bake files

    main

    The Docker Language Server provides specialized features for the following file types:

    Dockerfile

    • Hover support for images (showing vulnerability info from Docker Scout).
    • Suggested image tag updates from Docker Scout.
    • Linting support via BuildKit and Buildx.

    Compose files

    • Code completion and navigation.
    • Document outline support.
    • Error reporting and formatting.
    • Highlighting named references (services, networks, volumes, configs, secrets).
    • Hover tooltips and inlay hints for overridden attribute values.
    • Open links to images.
    • Rename preparation and renaming of named references.

    Bake files

    • Code completion and navigation.
    • Document outline support.
    • Error reporting and formatting.
    • Hover tooltips.
    • Inferring variable values.
  2. Configure telemetry collection settings

    main

    The Docker Language Server collects telemetry by default to improve usage patterns and diagnose crashes. You can control the level of telemetry collection using one of three settings:

    • "all": All telemetry is sent.
    • "error": Only errors and crash information are sent.
    • "off": No telemetry is sent.

    Telemetry can be configured during the initial connection or dynamically during a session.

  3. Update telemetry settings dynamically

    main

    If a user changes their configuration during an active session, the client must notify the server using the following workflow:

    1. Client sends a workspace/didChangeConfiguration notification.
    2. Server responds with a workspace/configuration request.
    3. Client responds to the request with the new setting ("all", "error", or "off").
  4. Use the Docker Language Server with JetBrains IDEs

    main

    To use the Docker Language Server in a JetBrains IDE, you must install the LSP4IJ plugin (an open source LSP client from Red Hat). After installing the plugin, follow the specific configuration steps for user-defined language servers to connect the Docker Language Server.

    https://github.com/redhat-developer/lsp4ij/blob/main/docs/user-defined-ls/docker-language-server.md
  5. Use the Docker Language Server with Visual Studio Code

    main

    The Docker Language Server is natively supported in Visual Studio Code via the official Docker DX extension. Installing this extension provides a seamless experience for Docker-related development within VS Code.

    https://marketplace.visualstudio.com/items?itemName=docker.docker
  6. Install the Docker Language Server

    main

    You can install the Docker Language Server using one of two methods:

    1. From source: Ensure you have Go 1.24 or greater installed, check out the repository, and run make install.
    2. Via Go install: Run the following command to get the latest version directly:
    go install github.com/docker/docker-language-server/cmd/docker-language-server@latest
    go install github.com/docker/docker-language-server/cmd/docker-language-server@latest
  7. Configure Initialization Options

    main

    Clients can pass configuration to the server during the initialize request using the initializationOptions field.

    Available Options:

    • dockercomposeExperimental.composeSupport: (Boolean, default true) Set to false to disable Compose file support. This is an experimental feature.
    • dockerfileExperimental.removeOverlappingIssues: (Boolean) Set to true to suppress duplicated diagnostic results if the client is also using rcjsuen/dockerfile-language-server. This is an experimental feature and subject to change.
    • telemetry: Configures telemetry settings. Valid values are "all", "error", or "off".
    {
      "initializationOptions": {
        "dockercomposeExperimental": {
          "composeSupport": true // or false
        },
        "dockerfileExperimental": {
          "removeOverlappingIssues": true // or false
        },
        "telemetry": "all" // "all" | "error" | "off"
      }
    }
  8. Register specialized LSP capabilities

    main

    The Docker Language Server uses a delayed registration pattern for certain capabilities to ensure the client is ready. This is particularly important for features like formatting and renaming that are scoped to specific languages (e.g., dockerbake or dockercompose).

    Internally, the server uses registerCapability which waits for registerCapabilityDelay (2 seconds) before sending the client/registerCapability request to the client. This prevents race conditions during the initial handshake.

  9. Enable Bake Build CodeLens via Experimental Capabilities

    main

    To support textDocument/codeLens for Bake HCL files, the client must explicitly declare support for the dockerLspClient.bake.build command in its capabilities object. If this capability is provided, the server will respond with support for code lens requests.

    {
      "capabilities": {
        "experimental": {
          "dockerLanguageServerCapabilities": {
            "commands": [
              "dockerLspClient.bake.build"
            ]
          }
        }
      }
    }
  10. Set telemetry via initialization options

    main

    To set the telemetry level when the language server first starts, include a telemetry property inside the initializationOptions object of the initialize request sent from the client to the server.

    {
      "clientInfo": {
          "name": "clientName",
          "version": "1.2.3"
      },
      "initializationOptions": {
        "telemetry": "all" | "error" | "off"
      }
    }
  11. Reference: Telemetry data collected

    main

    When telemetry is enabled, the following data points may be collected:

    • Name and version of the client
    • Action ID executed for resolving a diagnostic
    • Name of the function that triggered a crash
    • Stack trace of a crash
    • Hash of the Git remote of modified files
    • Hash of the path of modified files
    • Language identifier of modified files