LSP Proxy
A Rust library for proxying LSP (Language Server Protocol) messages with hooks for interception, modification, and notification generation.
Features
- Message Forwarding: Proxy messages between LSP client and server
- Request/Response Hooks: Intercept and modify requests and responses by method name
- Notification Generation: Generate notifications while processing messages
- Process Management: Spawn and manage LSP server processes
- Async: Built with
smolfor async operations
Installation
Quick Start
use async_trait;
use ;
use Arc;
use json;
// Define a hook
;
Key Concepts
Hooks
- Register hooks by LSP method name (
textDocument/completion,textDocument/hover, etc.) - Hooks process requests and responses only
- Notifications are forwarded without processing (by design)
- Responses are matched to hooks by tracking request IDs
Message Flow
Client → Proxy → Server
↓ ↓
└─ Hook processes request
└─ Can generate notifications → Client
Server → Proxy → Client
↓
└─ Hook processes response (matched by request ID)
└─ Can generate notifications → Client
API
Proxy
spawn(cmd, args, reader, writer)- Spawn server and forward messages
Hook Trait
on_request(message) -> HookResult- Process requeston_response(message) -> HookResult- Process response
HookOutput
new(message)- Create with modified messagewith_notification(notif)- Add notification (chainable)
Message
notification(method, params)- Create notificationto_value()- Convert to JSONfrom_value(json)- Parse from JSON
License
This project is provided as-is for educational and development purposes.