LSP Bridge
A comprehensive Rust library that provides a bridge between Language Server Protocol (LSP) servers and clients. It simplifies the integration of LSP capabilities into applications, tools, and IDEs by handling the complexity of protocol communication, lifecycle management, and feature negotiation.
Features
- 🚀 Complete LSP Protocol Support - Full implementation of LSP 3.17+ specification
- 🔄 Server Lifecycle Management - Automatic startup, shutdown, and crash recovery
- ⚡ Asynchronous Communication - Built on Tokio for high-performance async operations
- 🎯 Automatic Capability Detection - Negotiates and adapts to server capabilities
- 🔗 Request/Notification Routing - Intelligent message routing and multiplexing
- 🧩 Custom LSP Extensions - Support for custom LSP extensions and protocols
- 📝 Document Synchronization - Automatic document state management
- 🎨 Content Formatting - Built-in support for document formatting
- 💡 Smart Completion - Advanced completion handling and filtering
- 🔍 Symbol Search - Project-wide symbol search and navigation
- 🩺 Diagnostics Collection - Comprehensive error and warning reporting
- 🏗️ Multi-Server Coordination - Manage multiple LSP servers simultaneously
- 📊 Performance Profiling - Built-in profiling of LSP operations
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
Basic Usage
use ;
use ;
async
Advanced Usage
Multiple Servers
use ;
async
Custom Requests and Notifications
use ;
use ;
// Define custom request
async
Error Handling and Recovery
use ;
async
Configuration
Server Configuration
use LspServerConfig;
use Duration;
let config = new
.command
.args
.working_directory
.env
.root_path
.workspace_folders
.startup_timeout
.request_timeout
.max_restart_attempts
.restart_delay
.initialization_options;
Client Capabilities
use ;
let capabilities = LspClientCapabilities ;
let config = new
.command
.client_capabilities;
Supported LSP Features
- ✅ Text Document Synchronization - Open, close, change notifications
- ✅ Completion - Code completion with filtering and sorting
- ✅ Hover - Symbol information on hover
- ✅ Signature Help - Function signature assistance
- ✅ Go to Definition - Navigate to symbol definitions
- ✅ Go to Type Definition - Navigate to type definitions
- ✅ Go to Implementation - Navigate to implementations
- ✅ Find References - Find all symbol references
- ✅ Document Highlighting - Highlight related symbols
- ✅ Document Symbols - List symbols in document
- ✅ Code Actions - Quick fixes and refactoring
- ✅ Code Lens - Inline actionable information
- ✅ Document Links - Clickable links in documents
- ✅ Document Formatting - Format entire document
- ✅ Range Formatting - Format selected range
- ✅ On Type Formatting - Format on character input
- ✅ Rename - Rename symbols across workspace
- ✅ Folding Range - Code folding information
- ✅ Selection Range - Smart selection expansion
- ✅ Workspace Symbols - Search symbols across workspace
- ✅ Execute Command - Execute custom commands
- ✅ Diagnostics - Error and warning reporting
- ✅ Progress Reporting - Operation progress notifications
Language Server Examples
Rust (rust-analyzer)
let config = new
.command
.initialization_options;
Python (pylsp)
let config = new
.command
.initialization_options;
TypeScript (typescript-language-server)
let config = new
.command
.args
.initialization_options;
Architecture
Overview
graph TB
subgraph "Client Application"
App[Your Application]
App --> API[LSPBridge API]
end
subgraph "LSPBridge Core"
API --> Bridge[LspBridge]
Bridge --> Client[LspClient]
Bridge --> Config[Configuration]
Client --> Server1[LspServer 1]
Client --> Server2[LspServer 2]
Client --> ServerN[LspServer N]
end
subgraph "LSP Servers"
Server1 --> Process1[rust-analyzer]
Server2 --> Process2[typescript-language-server]
ServerN --> ProcessN[Other LSP Servers]
end
style Bridge fill:#e1f5fe
style Client fill:#f3e5f5
style API fill:#e8f5e8
Key Components
The LSP Bridge is organized into several key modules:
bridge- Main interface coordinating client-server communicationclient- Client-side bridge implementation for LSP interactionsserver- Server lifecycle management and communicationprotocol- LSP protocol implementation and message typesconfig- Configuration types and builderserror- Comprehensive error types and handlingutils- Shared utilities and helper functions
Communication Flow
sequenceDiagram
participant App as Your App
participant Bridge as LspBridge
participant Server as LspServer
participant LSP as LSP Process
App->>Bridge: request()
Bridge->>Server: forward_request()
Server->>LSP: JSON-RPC
LSP->>Server: response
Server->>Bridge: response
Bridge->>App: result
For detailed architecture diagrams and component interactions, see Architecture Diagrams.
Error Handling
LSP Bridge provides comprehensive error handling with detailed error types:
use LspError;
match error
Performance
LSP Bridge is designed for high performance:
- Async/Await - Built on Tokio for efficient async operations
- Concurrent Processing - Multiple servers and requests handled concurrently
- Smart Caching - Intelligent caching of server capabilities and responses
- Minimal Overhead - Optimized message parsing and routing
- Resource Management - Automatic cleanup and resource management
Testing
Run the test suite:
Run with logging:
RUST_LOG=debug
Integration tests with real LSP servers:
Documentation
Architecture and Design
- Architecture Diagrams - Comprehensive visual documentation of system architecture, protocol flows, and component interactions
- Architecture Overview - Detailed technical architecture and design principles
- Production Guide - Complete guide for production deployment with LSP protocol flows
API Reference
- API Documentation - Complete API reference with examples
- Examples - Working examples for common use cases
- Contributing Guide - Development workflow and contribution guidelines
Visual Documentation
Our documentation includes comprehensive diagrams showing:
- System Architecture - High-level component organization
- Protocol Flows - LSP request/response and notification sequences
- Server Lifecycle - State transitions and error handling
- Multi-Server Coordination - How multiple LSP servers work together
- Thread Safety - Concurrency patterns and synchronization
- Development Workflow - Contributing and testing processes
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Development Setup
-
Clone the repository:
-
Install dependencies:
-
Run tests:
-
Check formatting and linting:
Roadmap
- WebSocket transport support
- Language server discovery and auto-configuration
- Built-in language server implementations
- VS Code extension integration
- Performance benchmarking and optimization
- Advanced caching strategies
- Plugin system for custom extensions
- Docker container support
- Language server health monitoring
- Automatic server selection based on file type
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
- Language Server Protocol - Microsoft's LSP specification
- lsp-types - Rust LSP types implementation
- Tokio - Asynchronous runtime for Rust
- rust-analyzer - Inspiration for LSP server architecture
Changelog
See CHANGELOG.md for details about changes in each release.