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
tokiofor 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
forward(server_reader, server_writer, client_reader, client_writer)- Forwards messages
Hook Trait
on_request(request) -> HookResult- Process requeston_response(response) -> HookResult- Process responseon_notification(notification) -> HookResult- Process notification
HookOutput
new(message)- Create with modified messagewith_message(direction, message)- Add message (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.