pub struct LspMultiplexer {
pub project_root: PathBuf,
pub workspace_roots: Vec<(Language, PathBuf)>,
/* private fields */
}Expand description
Manages LSP server instances — one per language (multi-root) or per-root (LRU fallback).
Concurrency model: each language has its own Arc<Mutex<LanguageState>>.
Callers acquire a per-language OwnedMutexGuard for the duration of LSP I/O.
Different languages can be queried concurrently — no global lock is held during I/O.
Lazy startup: servers are started on first query, not at daemon boot. Crash recovery: exponential backoff for multi-root, silent removal for LRU.
Fields§
§project_root: PathBufRead-only after daemon start. Never mutated after new() is called.
workspace_roots: Vec<(Language, PathBuf)>Implementations§
Source§impl LspMultiplexer
impl LspMultiplexer
Sourcepub fn new(
project_root: PathBuf,
workspace_roots: Vec<(Language, PathBuf)>,
) -> Self
pub fn new( project_root: PathBuf, workspace_roots: Vec<(Language, PathBuf)>, ) -> Self
Create a new multiplexer for a project.
Pre-populates per-language slots for all known languages so the
languages map never needs to grow after construction.
Sourcepub fn set_diagnostic_store(&self, store: Arc<DiagnosticStore>)
pub fn set_diagnostic_store(&self, store: Arc<DiagnosticStore>)
Attach a diagnostic store so all new LSP clients collect diagnostics.
Must be called before the first query. Subsequent calls are no-ops.
Sourcepub fn set_max_lru_sessions(&self, max: usize)
pub fn set_max_lru_sessions(&self, max: usize)
Set the maximum number of concurrent LRU sessions (from config).
Sourcepub fn set_max_language_servers(&self, max: usize)
pub fn set_max_language_servers(&self, max: usize)
Set the maximum number of concurrent language server processes (from config).
Sourcepub fn set_priority_roots(&self, roots: HashSet<PathBuf>)
pub fn set_priority_roots(&self, roots: HashSet<PathBuf>)
Set priority workspace roots that are exempt from LRU eviction.
Sourcepub fn priority_roots(&self) -> HashSet<PathBuf>
pub fn priority_roots(&self) -> HashSet<PathBuf>
Get the priority workspace roots.
Sourcepub async fn get_or_start(
&self,
lang: Language,
) -> Result<OwnedMutexGuard<LanguageState>>
pub async fn get_or_start( &self, lang: Language, ) -> Result<OwnedMutexGuard<LanguageState>>
Acquire a per-language guard for the given language, booting the server if needed.
The returned guard holds the per-language mutex for the duration of LSP I/O. Other languages remain accessible concurrently.
§Errors
Returns an error if the server cannot be started or has permanently failed.
Sourcepub async fn route_for_file(
&self,
file_path: &Path,
) -> Result<OwnedMutexGuard<LanguageState>>
pub async fn route_for_file( &self, file_path: &Path, ) -> Result<OwnedMutexGuard<LanguageState>>
Route a file to its language server, attaching the workspace folder if needed.
Returns a per-language guard that the caller holds during LSP I/O.
§Errors
Returns an error if language cannot be detected or server fails to start.
Sourcepub async fn attach_all_workspaces(&self, lang: Language) -> Result<()>
pub async fn attach_all_workspaces(&self, lang: Language) -> Result<()>
Attach all discovered workspace folders for a language.
Acquires the per-language lock internally.
§Errors
Returns an error if the server is not running or attachment fails.
Sourcepub async fn attach_all_workspaces_with_guard(
&self,
lang: Language,
guard: &mut OwnedMutexGuard<LanguageState>,
) -> Result<()>
pub async fn attach_all_workspaces_with_guard( &self, lang: Language, guard: &mut OwnedMutexGuard<LanguageState>, ) -> Result<()>
Attach all workspaces using an already-held language guard.
Use this variant when you already hold the per-language lock.
§Errors
Returns an error if attachment fails.
Sourcepub fn find_nearest_workspace(
&self,
file_path: &Path,
lang: Language,
) -> Option<PathBuf>
pub fn find_nearest_workspace( &self, file_path: &Path, lang: Language, ) -> Option<PathBuf>
Find the nearest discovered workspace root for a file.
Sourcepub fn unique_languages(&self) -> Vec<Language>
pub fn unique_languages(&self) -> Vec<Language>
Get all unique languages detected in the project.
Sourcepub async fn warm_priority_roots(&self) -> Result<()>
pub async fn warm_priority_roots(&self) -> Result<()>
Pre-warm LRU sessions for priority workspace roots.
§Errors
Returns an error if a session fails to boot (non-fatal, logged by caller).
Sourcepub fn active_languages(&self) -> Vec<Language>
pub fn active_languages(&self) -> Vec<Language>
Get all active (running) languages.
Sourcepub fn status(&self) -> Vec<ServerStatus>
pub fn status(&self) -> Vec<ServerStatus>
Get status info for all known languages. Uses try_lock — busy languages show as “ready”.
Sourcepub fn readiness(&self) -> Readiness
pub fn readiness(&self) -> Readiness
Readiness summary: how many languages have running servers.
Sourcepub fn is_ready(&self, lang: Language) -> bool
pub fn is_ready(&self, lang: Language) -> bool
Check if a language has a running session (best-effort, non-blocking).
Sourcepub fn workspace_roots(&self) -> &[(Language, PathBuf)]
pub fn workspace_roots(&self) -> &[(Language, PathBuf)]
Get all known workspace roots.
Sourcepub fn project_root(&self) -> &Path
pub fn project_root(&self) -> &Path
Get the project root.
Sourcepub async fn shutdown_all(&self)
pub async fn shutdown_all(&self)
Shut down all active LSP sessions.
Sourcepub async fn restart_language(&self, lang: Language) -> Result<()>
pub async fn restart_language(&self, lang: Language) -> Result<()>
Shut down and clear the server for a language so it will be re-booted on next query.
§Errors
Returns Err if the language is not registered in this multiplexer.
Sourcepub fn language_lock(&self, lang: Language) -> Result<Arc<Mutex<LanguageState>>>
pub fn language_lock(&self, lang: Language) -> Result<Arc<Mutex<LanguageState>>>
Get the Arc<Mutex<LanguageState>> for a language.
§Errors
Returns Err if the language has no registered slot in this multiplexer.
Auto Trait Implementations§
impl !Freeze for LspMultiplexer
impl !RefUnwindSafe for LspMultiplexer
impl Send for LspMultiplexer
impl Sync for LspMultiplexer
impl Unpin for LspMultiplexer
impl UnsafeUnpin for LspMultiplexer
impl !UnwindSafe for LspMultiplexer
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