$ show zigtools/zls
ZLS (Zig Language Server) is a comprehensive implementation of the Language Server Protocol (LSP) for the Zig programming language. Written entirely in Zig, it provides rich IDE features including code completion, go-to-definition, hover information, semantic tokens, inlay hints, code actions, diagnostics, document symbols, folding ranges, signature help, and workspace symbol search. The server integrates with Zig's build system via the Build System Protocol (BSP) and can run `zig ast-check` for diagnostics, or use its own built-in semantic analysis engine. Architecturally, ZLS is a monolithic LSP server with a modular design. The core `Server` struct manages workspaces, document stores (`DocumentStore`), configuration (`Config`), and dispatches requests to feature modules under `src/features/`. The `Analyser` struct in `src/analysis.zig` provides type inference and symbol resolution using an `InternPool` for deduplicated type/value storage. A newer analysis backend under `src/analyser/` (InternPool, StringPool, degibberish) is partly implemented but not yet fully integrated. The test suite is extensive, with over 9,000 lines of completion tests alone, using a custom testing framework and placeholder-based assertions. Key dependencies include `known-folders` for platform-specific directory discovery, `diffz` for text diffing, `lsp_kit` for LSP protocol types, and `tracy` for profiling. The build system is managed via `build.zig` with dependency definitions in `build.zig.zon`. ZLS is highly configurable through a JSON configuration file, with options for snippets, inlay hints, build-on-save, and more. It is actively maintained, targets Zig master, and has a strong focus on correctness and performance, though some areas (like generic resolution and combinatorial types) remain heuristic-based.
The LLM identified 5 files worth highlighting for reuse:
A thread-safe InternPool for types, values, declarations, and composite types (struct, enum, union), modeled after the Zig compiler's InternPool. Uses hash-consing with read-write locks for concurrent access. Provides deduplication, coercion, peer-type resolution, and efficient type queries. Reusable in any system requiring canonical representation of complex types with fast equality checks.
Per-file trigram index for fast workspace symbol search. Splits identifiers into case-insensitive trigrams and stores them in a custom CuckooFilter for probabilistic membership testing. Supports multi-trigram merge-intersection queries for fuzzy matching. The CuckooFilter implementation (with alternating bucket fingerprinting and eviction) is a standalone reusable data structure for approximate set membership.
Thread-safe document registry managing opened files, AST trees, and build configurations. Uses a `Lazy<T, Context>` pattern to defer expensive computations (e.g., DocumentScope, TrigramStore) until first access. The `Handle.Future` mechanism allows asynchronous loading with event-based completion. This design pattern is reusable for any resource that needs lazy initialization with optional async loading.
Utility functions for the standard Zig AST (`std.zig.Ast`), including `Iterator` for depth-first traversal, `Walker` for breadth-first, and helpers for full nodes (e.g., `fullIf`, `fullWhile`, `fullPtrType`). Also provides `nodesOverlappingIndex` for range-based node lookup. These generics work with any AST node and can be extracted for use in other Zig AST analysis projects.
Generates LSP inlay hints for parameter names, variable types, and capture types. Uses a `Builder` struct that accumulates hints during a single AST walk, then finalizes with efficient offset conversion. The arena-allocated results avoid per-hint allocation overhead. This builder pattern is reusable for any feature that collects data while traversing a tree and produces a list of LSP items.