astral-sh/ruff
ty_server
ty's Language Server Protocol implementation. Source: crates/ty_server/.
Purpose
Expose ty's type checker as an LSP so editors can show type errors, hover types, completions, go-to-definition, references, and renames in real time.
Directory layout
crates/ty_server/src/
├── lib.rs
├── server/ # request/notification handlers
├── session/ # workspace + project state
├── document/ # in-memory document model
├── capabilities.rs
├── db.rs # ProjectDatabase wrapper for the LSP
├── system.rs # System impl that prefers in-memory buffers
└── logging.rsThe binary entry is ty server, defined in crates/ty/src/main.rs.
Why Salsa matters here
Unlike ruff_server, ty's server is built on top of Salsa via ProjectDatabase. Each text-document edit invalidates only the inputs that changed; downstream queries (type inference, scope graph, diagnostic accumulation) are recomputed only where necessary.
This is why the rule "any function touching .node() must be #[salsa::tracked]" matters in practice: forgetting it means the LSP returns stale results after an edit.
Capabilities
ty's server advertises:
- Diagnostics
- Hover (type information)
- Go-to definition / declaration / type-definition
- Find references
- Rename (single-file and cross-file where unambiguous)
- Completion (string-literal-aware where applicable)
- Inlay hints (subset)
- Document symbols
The IDE-specific queries live in ty_ide. ty_server mostly translates LSP requests into ty_ide / ty_python_semantic calls.
How a didChange is processed
sequenceDiagram
Editor->>Server: textDocument/didChange
Server->>Session: update buffer + bump revision
Server->>Db: invalidate file inputs
Editor->>Server: textDocument/hover
Server->>Db: salsa query (cached or recomputed)
Db-->>Server: type info
Server->>Editor: hover responseIntegration points
- Consumes
ty_python_semantic,ty_project,ty_ide,ruff_db. - Speaks LSP via
tower-lsp. - Shipped inside the
tybinary.
Modifying
- New LSP feature: usually means adding a tracked query in
ty_ide(orty_python_semantic), then a handler inserver/. Updatecapabilities.rsto advertise. - Editor-specific quirks: keep workarounds in
server/and document why. - Add a test in
crates/ty_server/tests/for every behavior change.
For Ruff's LSP, see ruff_server. 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.