1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! # lsp-server-tokio
//!
//! An async-first Rust crate for building LSP (Language Server Protocol) servers using Tokio.
//!
//! This crate provides transport-agnostic async LSP server infrastructure that handles
//! protocol concerns so developers can focus on language-specific logic.
//!
//! ## Quick Start
//!
//! ```no_run
//! use futures::StreamExt;
//! use lsp_server_tokio::{Connection, IncomingMessage, Response};
//!
//! # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
//! let mut conn = Connection::stdio();
//! let capabilities = serde_json::json!({
//! "documentFormattingProvider": true
//! });
//!
//! let _client_params = conn.initialize(capabilities).await?;
//! let sender = conn.client_sender();
//!
//! while let Some(result) = conn.receiver_mut().next().await {
//! let msg = result?;
//!
//! match conn.route(msg) {
//! IncomingMessage::Request(req, _) if req.method == "shutdown" => {
//! conn.handle_shutdown(req.id)?;
//! }
//! IncomingMessage::Request(req, _) => {
//! sender.respond(Response::ok(req.id, serde_json::Value::Null))?;
//! }
//! IncomingMessage::Notification(notif) if notif.method == "exit" => {
//! break;
//! }
//! IncomingMessage::CancelHandled => {}
//! IncomingMessage::Notification(_) => {}
//! IncomingMessage::ResponseRouted | IncomingMessage::ResponseUnknown(_) => {}
//! _ => {}
//! }
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(()) });
//! ```
//!
//! ## Testing
//!
//! Use [`duplex_transport()`] when you want connected in-memory transports for unit
//! and integration tests without stdio:
//!
//! ```
//! use futures::{SinkExt, StreamExt};
//! use lsp_server_tokio::{duplex_transport, Message, Request, Response};
//!
//! # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(async {
//! let (mut client, mut server) = duplex_transport(4096);
//!
//! client
//! .send(Message::Request(Request::new(1, "textDocument/hover", None)))
//! .await
//! .unwrap();
//!
//! if let Some(Ok(Message::Request(req))) = server.next().await {
//! server
//! .send(Message::Response(Response::ok(
//! req.id,
//! serde_json::json!({"contents": "Hello"}),
//! )))
//! .await
//! .unwrap();
//! }
//! # });
//! ```
//!
//! ## Core Types
//!
//! - [`RequestId`] - Identifies requests/responses (supports both integer and string IDs)
//! - [`ErrorCode`] - LSP specification error codes
//! - [`ResponseError`] - Error responses with code, message, and optional data
//! - [`Message`] - Discriminated union of Request, Response, and Notification
//! - [`Request`] - JSON-RPC request with id and method
//! - [`Response`] - JSON-RPC response with result or error
//! - [`Notification`] - JSON-RPC notification (no id, no response)
//!
//! ## Transport Layer
//!
//! - [`Transport`] - Type alias for `Framed<T, LspCodec>` providing Stream + Sink
//! - [`transport()`] - Factory function wrapping any `AsyncRead` + `AsyncWrite`
//! - [`duplex_transport()`] - Creates connected in-memory transports for testing
//! - [`LspCodec`] - Encoder/Decoder for Content-Length message framing
//!
//! ## Request Routing
//!
//! The [`IncomingMessage`] enum classifies messages received from [`Connection::route()`]:
//! - [`IncomingMessage::Request`] - A request with automatic [`CancellationToken`] for cooperative cancellation
//! - [`IncomingMessage::Notification`] - A notification (no response expected)
//! - [`IncomingMessage::CancelHandled`] - A `$/cancelRequest` that was applied automatically
//! - [`IncomingMessage::ResponseRouted`] - A response delivered to an awaiting receiver
//! - [`IncomingMessage::ResponseUnknown`] - A response for an unknown request ID
pub use ;
pub use LspCodec;
pub use ;
pub use ;
pub use ;
pub use ;
pub use RequestId;
pub use ;
pub use ;
pub use ;
// Re-export CancellationToken for ergonomic use with IncomingMessage::Request
pub use CancellationToken;