Skip to main content

IncomingMessage

Enum IncomingMessage 

Source
#[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 a CancellationToken that is triggered on $/cancelRequest or 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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 $/cancelRequest notification 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

Source

pub fn is_request(&self) -> bool

Returns true if this message is a routed request.

Source

pub fn is_notification(&self) -> bool

Returns true if this message is a notification.

Source

pub fn is_cancel_handled(&self) -> bool

Returns true if this message is an automatically handled cancellation notification.

Source

pub fn is_response_routed(&self) -> bool

Returns true if this message is a response routed to a pending request.

Source

pub fn is_response_unknown(&self) -> bool

Returns true if this message is a response for an unknown request.

Trait Implementations§

Source§

impl Debug for IncomingMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.