Dockerfile Language Server

0.15.0 · active · verified Sun Apr 19

The Dockerfile Language Server provides robust Language Server Protocol (LSP) support for Dockerfiles, enhancing developer experience across various code editors. Written in TypeScript and powered by Node.js, it offers features such as code completion, diagnostics, formatting, hover information, code actions, and semantic highlighting. Currently stable at version `0.15.0`, the project sees a consistent release cadence driven by updates to its core logic libraries. Unlike monolithic language servers, this package is designed specifically as the LSP server frontend, delegating the heavy lifting of Dockerfile parsing and language intelligence to the separate `dockerfile-ast`, `dockerfile-language-service`, and `dockerfile-utils` libraries. This architecture allows for a lean server implementation and flexible integration, as demonstrated by its adoption in popular extensions like VS Code Docker, Sublime Text LSP-dockerfile, and clients for Zed, Atom, Sourcegraph, Theia, and Emacs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically spawn the `docker-langserver` CLI as a child process and establish an LSP connection over standard I/O (stdio). It sets up a minimal `vscode-languageserver` client to send an `initialize` request, showcasing how an editor extension would interact with the server.

import { spawn } from 'child_process';
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node';
import type { InitializeParams } from 'vscode-languageserver';

const serverProcess = spawn('docker-langserver', ['--stdio'], {
  stdio: ['pipe', 'pipe', 'inherit'],
  windowsHide: true
});

const connection = createConnection(ProposedFeatures.all, serverProcess.stdin, serverProcess.stdout);

connection.onInitialize(async (params: InitializeParams) => {
  console.log('LSP Client: Received initialize request from server.');
  return {
    capabilities: {
      textDocumentSync: 1, // Full
      completionProvider: { resolveProvider: true, triggerCharacters: [' ', '.', '-', ':'] },
      hoverProvider: true,
      definitionProvider: true,
      documentFormattingProvider: true,
      diagnosticProvider: { interFileDependencies: false, workspaceDiagnostics: false }
    },
    serverInfo: { name: 'Test Dockerfile LSP Client', version: '1.0.0' }
  };
});

connection.onInitialized(() => {
  console.log('LSP Client: Initialized. Language Server is ready.');
});

connection.listen();

serverProcess.on('exit', (code, signal) => {
  console.log(`LSP Server process exited with code ${code} and signal ${signal}`);
  process.exit(code || 0);
});

serverProcess.on('error', (err) => {
  console.error('Failed to start LSP server process:', err);
  process.exit(1);
});

console.log('LSP Client: Connecting to Dockerfile Language Server...');
// In a real scenario, you'd send a didOpen notification here for a Dockerfile.
// For this quickstart, we just establish the connection.

view raw JSON →