perl_lsp_transport/lib.rs
1//! LSP transport layer for perl-lsp.
2//!
3//! This crate provides the transport layer implementation for the Perl Language Server,
4//! handling message framing according to the LSP Base Protocol specification.
5//!
6//! # Overview
7//!
8//! The LSP Base Protocol uses Content-Length based message framing over stdio (or other
9//! transports). This crate provides:
10//!
11//! - [`ContentLengthMessageReader`] - Stateful framed reader for streaming request loops
12//! - [`read_message`] - Read and parse an LSP message with Content-Length framing
13//! - [`write_message`] - Write an LSP response with proper framing
14//! - [`write_notification`] - Write an LSP notification with proper framing
15//! - [`log_response`] - Debug logging for outgoing responses
16//!
17//! # Example
18//!
19//! ```no_run
20//! use std::io::{BufReader, stdin, stdout};
21//! use perl_lsp_transport::{read_message, write_message};
22//! use perl_lsp_protocol::JsonRpcResponse;
23//!
24//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
25//! let mut reader = BufReader::new(stdin());
26//! let mut writer = stdout();
27//!
28//! // Read an incoming message
29//! if let Ok(Some(request)) = read_message(&mut reader) {
30//! // Process request and create response
31//! let response = JsonRpcResponse::null(request.id);
32//!
33//! // Write the response
34//! write_message(&mut writer, &response)?;
35//! }
36//! # Ok(())
37//! # }
38//! ```
39
40#![deny(unsafe_code)]
41#![deny(clippy::print_stderr, clippy::print_stdout)]
42#![cfg_attr(test, allow(clippy::print_stderr, clippy::print_stdout))]
43#![warn(missing_docs)]
44
45mod framing;
46
47pub use framing::{
48 ContentLengthMessageReader, frame, log_response, read_message, write_message,
49 write_notification,
50};