pub struct LspClient { /* private fields */ }Expand description
High-level LSP client that manages a language server lifecycle.
Implementations§
Source§impl LspClient
impl LspClient
Sourcepub fn start(language: Language, project_root: &Path) -> Result<Self, LspError>
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.
Sourcepub fn start_with_binary(
binary_path: &Path,
args: &[&str],
language: Language,
project_root: &Path,
) -> Result<Self, LspError>
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.
Sourcepub async fn initialize(
&mut self,
project_root: &Path,
) -> Result<&ServerCapabilities>
pub async fn initialize( &mut self, project_root: &Path, ) -> Result<&ServerCapabilities>
Sourcepub async fn shutdown(&mut self) -> Result<()>
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.
Sourcepub async fn wait_for_response_public(
&mut self,
request_id: i64,
) -> Result<Value>
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.
Sourcepub async fn wait_for_response_with_timeout(
&mut self,
request_id: i64,
timeout: Duration,
) -> Result<Value>
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.
Sourcepub async fn wait_for_progress_end(&mut self, timeout: Duration)
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.
Sourcepub fn capabilities(&self) -> Option<&ServerCapabilities>
pub fn capabilities(&self) -> Option<&ServerCapabilities>
Get the server capabilities (available after initialize).
Sourcepub fn supports_workspace_folders(&self) -> bool
pub fn supports_workspace_folders(&self) -> bool
Whether the server supports workspace/didChangeWorkspaceFolders.
Sourcepub fn server_name(&self) -> &str
pub fn server_name(&self) -> &str
The server binary name (e.g., “vtsls”, “rust-analyzer”).
Sourcepub fn is_folder_attached(&self, path: &Path) -> bool
pub fn is_folder_attached(&self, path: &Path) -> bool
Check if a workspace folder is currently attached to this server.
Sourcepub fn attached_folders(&self) -> &HashSet<PathBuf>
pub fn attached_folders(&self) -> &HashSet<PathBuf>
Get all attached workspace folders.
Sourcepub async fn attach_folder(&mut self, path: &Path) -> Result<()>
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.
Sourcepub async fn detach_folder(&mut self, path: &Path) -> Result<()>
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.
Sourcepub fn set_diagnostic_store(&mut self, store: Arc<DiagnosticStore>)
pub fn set_diagnostic_store(&mut self, store: Arc<DiagnosticStore>)
Attach a diagnostic store so textDocument/publishDiagnostics notifications
are captured while waiting for responses.
Sourcepub fn transport_mut(&mut self) -> &mut LspTransport
pub fn transport_mut(&mut self) -> &mut LspTransport
Get mutable access to the transport for sending additional requests.
Auto Trait Implementations§
impl !Freeze for LspClient
impl !RefUnwindSafe for LspClient
impl Send for LspClient
impl Sync for LspClient
impl Unpin for LspClient
impl UnsafeUnpin for LspClient
impl !UnwindSafe for LspClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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