| Crates.io | lsp-proxy |
| lib.rs | lsp-proxy |
| version | 0.1.5 |
| created_at | 2025-10-27 17:30:16.302804+00 |
| updated_at | 2025-10-31 11:34:36.637999+00 |
| description | A Language Server Protocol (LSP) proxy server implemented in Rust. |
| homepage | |
| repository | https://github.com/MikhailSiarko/lsp-proxy |
| max_upload_size | |
| id | 1903382 |
| size | 29,977 |
A Rust library for proxying LSP (Language Server Protocol) messages with hooks for interception, modification, and notification generation.
tokio for async operationscargo add lsp_proxy
use async_trait::async_trait;
use lsp_proxy::{Hook, HookOutput, HookResult, Message, Proxy};
use std::sync::Arc;
use serde_json::json;
// Define a hook
struct MyHook;
#[async_trait]
impl Hook for MyHook {
async fn on_request(&self, message: Message) -> HookResult {
// Optionally modify the request and generate notifications
let notification = Message::notification(
"window/logMessage"
Some(json!({"type": 4, "message": "Processing request"}))
);
Ok(HookOutput::new(message).with_notification(notification))
}
// Default implementation for messages is to forward them unmodified
// You only need to implement on_response if you want to process responses
async fn on_response(&self, message: Message) -> HookResult {
// Process the response
Ok(HookOutput::new(message))
}
}
fn main() -> std::io::Result<()> {
smol::block_on(async {
// Create and configure proxy
let proxy = ProxyBuilder::new()
.with_hook("textDocument/completion" Arc::new(MyHook));
// Spawn LSP server and forward messages
proxy.forward(
server_reader,
server_writer,
client_reader,
client_writer,
).await?;
Ok(())
}}
}
textDocument/completion, textDocument/hover, etc.)Client → Proxy → Server
↓ ↓
└─ Hook processes request
└─ Can generate notifications → Client
Server → Proxy → Client
↓
└─ Hook processes response (matched by request ID)
└─ Can generate notifications → Client
Proxy
forward(server_reader, server_writer, client_reader, client_writer) - Forwards messagesHook Trait
on_request(request) -> HookResult - Process requeston_response(response) -> HookResult - Process responseon_notification(notification) -> HookResult - Process notificationHookOutput
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 JSONThis project is provided as-is for educational and development purposes.