Skip to main content

LspMultiplexer

Struct LspMultiplexer 

Source
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: PathBuf

Read-only after daemon start. Never mutated after new() is called.

§workspace_roots: Vec<(Language, PathBuf)>

Implementations§

Source§

impl LspMultiplexer

Source

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.

Source

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.

Source

pub fn set_max_lru_sessions(&self, max: usize)

Set the maximum number of concurrent LRU sessions (from config).

Source

pub fn set_max_language_servers(&self, max: usize)

Set the maximum number of concurrent language server processes (from config).

Source

pub fn set_priority_roots(&self, roots: HashSet<PathBuf>)

Set priority workspace roots that are exempt from LRU eviction.

Source

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

Get the priority workspace roots.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn find_nearest_workspace( &self, file_path: &Path, lang: Language, ) -> Option<PathBuf>

Find the nearest discovered workspace root for a file.

Source

pub fn unique_languages(&self) -> Vec<Language>

Get all unique languages detected in the project.

Source

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).

Source

pub fn active_languages(&self) -> Vec<Language>

Get all active (running) languages.

Source

pub fn status(&self) -> Vec<ServerStatus>

Get status info for all known languages. Uses try_lock — busy languages show as “ready”.

Source

pub fn readiness(&self) -> Readiness

Readiness summary: how many languages have running servers.

Source

pub fn is_ready(&self, lang: Language) -> bool

Check if a language has a running session (best-effort, non-blocking).

Source

pub fn workspace_roots(&self) -> &[(Language, PathBuf)]

Get all known workspace roots.

Source

pub fn project_root(&self) -> &Path

Get the project root.

Source

pub async fn shutdown_all(&self)

Shut down all active LSP sessions.

Source

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.

Source

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§

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