pub struct LspTransport { /* private fields */ }Expand description
A synchronous transport layer for communicating with a Language Server Protocol (LSP) server.
Implementations§
Source§impl LspTransport
impl LspTransport
Sourcepub fn new(child: &mut Child) -> Self
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()).
Sourcepub fn send(&mut self, msg: &Value) -> Result<()>
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.
Sourcepub fn recv(&mut self) -> Result<Value>
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-Lengthheader is parsed. - The header value cannot be parsed into a valid size.
- The message body cannot be parsed as valid JSON.
Sourcepub fn recv_until<T>(
&mut self,
limit: usize,
predicate: impl FnMut(&Value) -> Option<T>,
) -> Result<T>
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::recvcall fails. - The
limitnumber of messages is exhausted without thepredicatereturningSome(T).
Sourcepub fn initialize(process_id: u32, root_uri: &str) -> Value
pub fn initialize(process_id: u32, root_uri: &str) -> Value
Constructs an LSP initialize request message.
Sourcepub fn initialized() -> Value
pub fn initialized() -> Value
Constructs an LSP initialized notification message.
Sourcepub fn did_open(uri: &str, text: &str) -> Value
pub fn did_open(uri: &str, text: &str) -> Value
Constructs an LSP textDocument/didOpen notification message.
Sourcepub fn definition(id: u64, uri: &str, line: u32, character: u32) -> Value
pub fn definition(id: u64, uri: &str, line: u32, character: u32) -> Value
Constructs an LSP textDocument/definition request message.