$ show latex-lsp/texlab
TexLab is a Rust-implemented Language Server Protocol (LSP) server for LaTeX and BibTeX. It provides rich IDE features including code completion, diagnostics (grammar, build errors, chktex), definitions, references, hover information, renaming, folding, document symbols, inlay hints, links, formatting, and build/forward-search commands. The architecture is a modular monolith with 20+ internal crates, each encapsulating a specific concern (parsing, syntax definitions, completion, diagnostics, etc.). The core relies on a custom recursive-descent parser using `logos` for lexing and `rowan` for a lossless concrete syntax tree, enabling precise source mappings. External dependencies include `latexmk`, `chktex`, `kpsewhich`, `latexindent`, and `tex-fmt` for build and formatting. Entry points are the binary `texlab` (CLI) and the LSP server loop in `crates/texlab/src/server.rs`. The data flow involves file system watching, parsing, semantic analysis (labels, citations, environments), and incremental updates via a workspace database.
The LLM identified 4 files worth highlighting for reuse:
Provides efficient line/column offset mapping with support for UTF-16 code units (required by LSP). Originally derived from rust-analyzer, this crate is fully self-contained, well-tested, and can be reused in any LSP server or text editor tooling that needs to convert between byte offsets and line/column positions.
Implements cross-platform inter-process communication using Unix domain sockets (via `uds_windows` on Windows) and Windows named pipes as a fallback. Encapsulates socket listening, connection handling, and message serialization. It is a standalone, reusable pattern for any Rust application that needs simple IPC without network overhead.
Parses and normalizes BibTeX text fields, handling LaTeX accent commands, special characters, and string references. It converts rich text into plain strings and also provides tokenization for human names. This utility is isolated from the rest of texlab and can be reused in any BibTeX processing tool or citation manager.
Provides a powerful test fixture system that embeds cursor markers (`<|>`, ranges `[|...|]`) in source comments. It sets up a virtual workspace with multiple files, runs completion or diagnostics, and asserts results against expected snapshots. This pattern is reusable for testing any LSP server or parser-based tool, drastically simplifying test authoring.