LSP client infrastructure for the AI coding agent
This crate provides Language Server Protocol (LSP) integration, enabling the agent to leverage code intelligence from language servers like rust-analyzer, typescript-language-server, pyright, and gopls.
Architecture
The crate is organized into several modules:
- [
server]: LSP server definitions and spawning - [
client]: LSP client with JSON-RPC communication - [
facade]: High-level API with lazy initialization and caching - [
types]: LSP types and utilities - [
language]: File extension to language ID mappings
Usage
use ;
use PathBuf;
// Initialize the LSP subsystem
let working_dir = from;
init;
// Get the LSP instance
let lsp = lsp.unwrap;
// Touch a file to notify LSP servers
lsp.touch_file.await?;
// Go to definition
let locations = lsp.definition.await?;
Supported Language Servers
| Language | Server | Extensions |
|---|---|---|
| Rust | rust-analyzer | .rs |
| TypeScript/JavaScript | typescript-language-server | .ts, .tsx, .js, .jsx |
| Python | pyright | .py, .pyi |
| Go | gopls | .go |
LSP Operations
The following LSP operations are supported:
goToDefinition- Find where a symbol is definedfindReferences- Find all references to a symbolhover- Get hover information (documentation, types)documentSymbol- Get all symbols in a documentworkspaceSymbol- Search for symbols across the workspacegoToImplementation- Find implementations of a trait/interfaceprepareCallHierarchy- Get call hierarchy item at a positionincomingCalls- Find all callers of a functionoutgoingCalls- Find all functions called by a function