Skip to main content

LspClient

Struct LspClient 

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

High-level LSP client that manages a language server lifecycle.

Implementations§

Source§

impl LspClient

Source

pub fn start(language: Language, project_root: &Path) -> Result<Self, LspError>

Start an LSP server for the given language and project root.

Looks for the server binary in PATH first, then in ~/.krait/servers/. Use start_with_auto_install() to also download if missing.

§Errors

Returns LspError::ServerNotFound if the binary is missing. Returns an error if the process cannot be spawned.

Source

pub fn start_with_binary( binary_path: &Path, args: &[&str], language: Language, project_root: &Path, ) -> Result<Self, LspError>

Start an LSP server using a specific binary path.

§Errors

Returns an error if the process cannot be spawned.

Source

pub async fn initialize( &mut self, project_root: &Path, ) -> Result<&ServerCapabilities>

Perform the LSP initialize handshake.

Sends initialize request, waits for response, then sends initialized notification.

§Errors

Returns an error if the handshake fails or times out.

§Panics

Panics if capabilities are not stored after a successful response (should never happen).

Source

pub async fn shutdown(&mut self) -> Result<()>

Shut down the LSP server cleanly.

Sends shutdown request, waits for response, sends exit notification, then waits for the process to exit.

§Errors

Returns an error if shutdown fails or the process doesn’t exit.

Source

pub async fn wait_for_response_public( &mut self, request_id: i64, ) -> Result<Value>

Wait for a response to a previously sent request.

Uses the default initialize timeout. For commands that need LSP responses after the handshake is complete.

§Errors

Returns an error if the response times out or contains an LSP error.

Source

pub async fn wait_for_response_with_timeout( &mut self, request_id: i64, timeout: Duration, ) -> Result<Value>

Wait for a response with a caller-specified timeout.

Unlike wrapping wait_for_response_public in tokio::time::timeout, this ensures the response is always consumed (no orphaned responses in the pipe).

§Errors

Returns an error if the timeout expires before a response is received.

Source

pub async fn wait_for_progress_end(&mut self, timeout: Duration)

Wait until the server sends a $/progress notification with "kind": "end".

This replaces the fixed-delay polling heuristic: instead of sleeping 200ms × N, we listen for the server’s own signal that background indexing is complete. If no progress end is received within timeout, we proceed anyway (graceful degradation).

Any responses received while waiting are buffered for future retrieval.

Source

pub fn capabilities(&self) -> Option<&ServerCapabilities>

Get the server capabilities (available after initialize).

Source

pub fn language(&self) -> Language

Get the language this client serves.

Source

pub fn supports_workspace_folders(&self) -> bool

Whether the server supports workspace/didChangeWorkspaceFolders.

Source

pub fn server_name(&self) -> &str

The server binary name (e.g., “vtsls”, “rust-analyzer”).

Source

pub fn is_folder_attached(&self, path: &Path) -> bool

Check if a workspace folder is currently attached to this server.

Source

pub fn attached_folders(&self) -> &HashSet<PathBuf>

Get all attached workspace folders.

Source

pub async fn attach_folder(&mut self, path: &Path) -> Result<()>

Dynamically attach a workspace folder to the running server.

Sends workspace/didChangeWorkspaceFolders notification. No-op if already attached or server doesn’t support it.

§Errors

Returns an error if the notification cannot be sent.

Source

pub async fn detach_folder(&mut self, path: &Path) -> Result<()>

Dynamically detach a workspace folder from the running server.

Sends workspace/didChangeWorkspaceFolders notification. No-op if not attached.

§Errors

Returns an error if the notification cannot be sent.

Source

pub fn set_diagnostic_store(&mut self, store: Arc<DiagnosticStore>)

Attach a diagnostic store so textDocument/publishDiagnostics notifications are captured while waiting for responses.

Source

pub fn transport_mut(&mut self) -> &mut LspTransport

Get mutable access to the transport for sending additional requests.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more