#[non_exhaustive]pub enum IncomingMessage {
Request(Request, CancellationToken),
Notification(Notification),
CancelHandled,
ResponseRouted,
ResponseUnknown(Response),
}Expand description
Represents a classified incoming message after routing.
When a Message is received from the transport, it is classified
into one of these variants by the Connection::route() method.
§Variants
Request: A request requiring a response. Includes aCancellationTokenthat is triggered on$/cancelRequestor shutdown.Notification: A fire-and-forget notification. No response is expected.ResponseRouted: A response that was successfully delivered to a pending outgoing request’s receiver.ResponseUnknown: A response for which no pending outgoing request was found. This typically indicates a protocol error or a timed-out request.
§Example
use lsp_server_tokio::{IncomingMessage, Message, Request, Response};
fn handle_message(incoming: IncomingMessage) {
match incoming {
IncomingMessage::Request(req, token) => {
println!("Handle request: {}", req.method);
// Use token for cooperative cancellation
// Send response back
}
IncomingMessage::Notification(notif) => {
println!("Handle notification: {}", notif.method);
}
IncomingMessage::CancelHandled => {
// `$/cancelRequest` was applied automatically
}
IncomingMessage::ResponseRouted => {
// Response was delivered to awaiting task, nothing to do
}
IncomingMessage::ResponseUnknown(resp) => {
println!("Unknown response for id: {:?}", resp.id);
// Log or handle the unexpected response
}
_ => {}
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Request(Request, CancellationToken)
A request that needs a response.
The server must send a response with the same request ID.
The included CancellationToken is triggered when:
- A
$/cancelRequestnotification is received for this request - The connection is shutting down
Use the token for cooperative cancellation of long-running operations.
Notification(Notification)
A notification (fire-and-forget).
No response is expected or allowed.
CancelHandled
A $/cancelRequest notification that was automatically processed.
The cancellation token for the referenced request (if pending) has already been triggered. No further action is needed.
ResponseRouted
A response that was successfully delivered to a pending outgoing request.
The response was sent to the oneshot channel registered when the outgoing request was created. The awaiting task will receive it.
ResponseUnknown(Response)
A response for an unknown request ID.
This occurs when:
- The response ID doesn’t match any pending outgoing request
- The request timed out and was removed before the response arrived
- The client sent an unsolicited response
- The response has a null ID (parse error response)
Implementations§
Source§impl IncomingMessage
impl IncomingMessage
Sourcepub fn is_request(&self) -> bool
pub fn is_request(&self) -> bool
Returns true if this message is a routed request.
Sourcepub fn is_notification(&self) -> bool
pub fn is_notification(&self) -> bool
Returns true if this message is a notification.
Sourcepub fn is_cancel_handled(&self) -> bool
pub fn is_cancel_handled(&self) -> bool
Returns true if this message is an automatically handled cancellation notification.
Sourcepub fn is_response_routed(&self) -> bool
pub fn is_response_routed(&self) -> bool
Returns true if this message is a response routed to a pending request.
Sourcepub fn is_response_unknown(&self) -> bool
pub fn is_response_unknown(&self) -> bool
Returns true if this message is a response for an unknown request.