Open-Source Wikis

/

Ruff

/

Crates

/

`ruff_server`

astral-sh/ruff

ruff_server

The Ruff Language Server Protocol implementation. Source: crates/ruff_server/.

Purpose

Implement the LSP for Ruff so editors can fetch diagnostics, code actions, and formatting on demand. Replaces the older Python ruff-lsp shim with a native Rust server.

Directory layout

crates/ruff_server/src/
├── lib.rs
├── server/        # JSON-RPC routing
├── session/       # client + workspace state
├── edit/          # text-document edits
├── format.rs      # formatting requests
├── lint.rs        # diagnostics on change/save
├── fix.rs         # code actions for diagnostics
├── resolve.rs     # config resolution per workspace
├── workspace.rs
└── logging.rs

The binary entry point is ruff server, defined in crates/ruff/src/commands/server.rs.

Key abstractions

Type Purpose
Server The top-level event loop, request dispatcher.
Session Per-process state: open documents, settings, cancellation tokens.
Document An open text document with version + content.
Workspace A workspace folder, its resolved Ruff config, file watchers.

Capabilities

The server advertises capabilities for:

  • Synchronization (full and incremental document syncs)
  • Diagnostics (textDocument/publishDiagnostics)
  • Formatting and range formatting
  • Code actions (autofix, source actions for ruff: lint, ruff: fix all, ruff: format, ruff: organize imports)
  • Document symbol (where applicable)
  • Configuration via workspace/configuration

How a didChange is processed

sequenceDiagram
    Editor->>Server: textDocument/didChange
    Server->>Session: update Document
    Server->>Linter: ruff_linter::check_path
    Linter-->>Server: Vec<Diagnostic>
    Server->>Editor: textDocument/publishDiagnostics

ruff_server is intentionally not Salsa-based. Each lint run is a one-shot computation; the server keeps documents in memory but recomputes diagnostics from scratch on each edit. This keeps the implementation simple and matches Ruff's CLI semantics.

Settings

Each workspace gets its own resolved Settings (built via ruff_workspace), updated when configuration files change or the client pushes new settings.

Integration points

Modifying

  • New LSP request: extend server/, register in capabilities, implement handler.
  • New code action: extend fix.rs.
  • Changing diagnostic publishing cadence: edit lint.rs.
  • Always add a unit/integration test in crates/ruff_server/tests/.

For the user-facing perspective, see LSP servers.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

`ruff_server` – Ruff wiki | Factory