Skip to main content

LspTransport

Struct LspTransport 

Source
pub struct LspTransport { /* private fields */ }
Expand description

A synchronous transport layer for communicating with a Language Server Protocol (LSP) server.

Implementations§

Source§

impl LspTransport

Source

pub fn new(child: &mut Child) -> Self

Creates a new LspTransport by taking ownership of the stdin and stdout streams from the provided child process.

§Panics

Panics if the child process does not have a captured stdin or stdout stream (e.g., if they weren’t configured with Stdio::piped()).

Source

pub fn send(&mut self, msg: &Value) -> Result<()>

Send a JSON-RPC message.

§Errors

Returns an std::io::Error if writing to or flushing the underlying stdin stream fails.

Source

pub fn recv(&mut self) -> Result<Value>

Read the next LSP message (blocks until one arrives).

§Errors

Returns an error if:

  • An I/O error occurs while reading from the stdout stream.
  • The stream ends before a valid Content-Length header is parsed.
  • The header value cannot be parsed into a valid size.
  • The message body cannot be parsed as valid JSON.
Source

pub fn recv_until<T>( &mut self, limit: usize, predicate: impl FnMut(&Value) -> Option<T>, ) -> Result<T>

Read messages until predicate returns Some(T), discarding everything else.

§Errors

Returns an error if:

  • The underlying Self::recv call fails.
  • The limit number of messages is exhausted without the predicate returning Some(T).
Source

pub fn initialize(process_id: u32, root_uri: &str) -> Value

Constructs an LSP initialize request message.

Source

pub fn initialized() -> Value

Constructs an LSP initialized notification message.

Source

pub fn did_open(uri: &str, text: &str) -> Value

Constructs an LSP textDocument/didOpen notification message.

Source

pub fn definition(id: u64, uri: &str, line: u32, character: u32) -> Value

Constructs an LSP textDocument/definition request message.

Source

pub fn completion(id: u64, uri: &str, line: u32, character: u32) -> Value

Constructs an LSP textDocument/completion request message.

Source

pub fn shutdown(id: u64) -> Value

Constructs an LSP shutdown request message.

Source

pub fn exit() -> Value

Constructs an LSP exit notification message.

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.