Skip to main content

LspManager

Struct LspManager 

Source
pub struct LspManager { /* private fields */ }

Implementations§

Source§

impl LspManager

Source

pub const PULL_FILE_TIMEOUT: Duration

Default timeout for textDocument/diagnostic (per-file pull). Servers usually respond in under 1s for files they’ve already analyzed; we allow up to 10s before falling back to push semantics. Currently surfaced via Self::pull_file_timeout for callers that want to override the wait via the wait_ms knob.

Source

pub fn new() -> Self

Source

pub fn set_extra_env(&mut self, key: &str, value: &str)

For testing: set an extra environment variable that gets passed to every spawned LSP child process. Useful for driving fake-server behavioral variants in integration tests.

Source

pub fn server_count(&self) -> usize

Count active LSP server instances.

Source

pub fn override_binary(&mut self, kind: ServerKind, binary_path: PathBuf)

For testing: override the binary for a server kind.

Source

pub fn ensure_server_for_file( &mut self, file_path: &Path, config: &Config, ) -> Vec<ServerKey>

Ensure a server is running for the given file. Spawns if needed. Returns the active server keys for the file, or an empty vec if none match.

This is the lightweight wrapper around [ensure_server_for_file_detailed] that drops failure context. Prefer the detailed variant in command handlers that need to surface honest error messages to the agent.

Source

pub fn ensure_server_for_file_detailed( &mut self, file_path: &Path, config: &Config, ) -> EnsureServerOutcomes

Detailed version of [ensure_server_for_file] that records every matching server’s outcome (Ok / NoRootMarker / BinaryNotInstalled / SpawnFailed).

Use this when the caller wants to honestly report why a file has no active server (e.g., to surface “bash-language-server not on PATH” to the agent instead of silently returning total: 0).

Source

pub fn ensure_server_for_file_default( &mut self, file_path: &Path, ) -> Vec<ServerKey>

Ensure a server is running using the default LSP registry. Kept for integration tests that exercise built-in server helpers directly.

Source

pub fn ensure_file_open( &mut self, file_path: &Path, config: &Config, ) -> Result<Vec<ServerKey>, LspError>

Ensure that servers are running for the file and that the document is open in each server’s DocumentStore. Reads file content from disk if not already open. Returns the server keys for the file.

Source

pub fn ensure_file_open_default( &mut self, file_path: &Path, ) -> Result<Vec<ServerKey>, LspError>

Source

pub fn notify_file_changed( &mut self, file_path: &Path, content: &str, config: &Config, ) -> Result<(), LspError>

Notify relevant LSP servers that a file has been written/changed. This is the main hook called after every file write in AFT.

If the file’s server isn’t running yet, starts it (lazy spawn). If the file isn’t open in LSP yet, sends didOpen. Otherwise sends didChange.

Source

pub fn notify_file_changed_versioned( &mut self, file_path: &Path, content: &str, config: &Config, ) -> Result<Vec<(ServerKey, i32)>, LspError>

Like notify_file_changed, but returns the target document version per server so the post-edit waiter can match publishDiagnostics against the exact version that this notification carried.

Returns: Vec<(ServerKey, target_version)>. target_version is the version field on the VersionedTextDocumentIdentifier we just sent (post-bump). For freshly-opened documents (didOpen) the version is 0. Servers that don’t honor versioned text document sync will not echo this back on publishDiagnostics; the caller is expected to fall back to the epoch-delta path for those.

Source

pub fn notify_file_changed_default( &mut self, file_path: &Path, content: &str, ) -> Result<(), LspError>

Source

pub fn notify_files_watched_changed( &mut self, paths: &[(PathBuf, FileChangeType)], _config: &Config, ) -> Result<(), LspError>

Notify every active server whose workspace contains at least one changed path that watched files changed. This is intentionally workspace-scoped rather than extension-scoped: configuration edits such as package.json or tsconfig.json affect a server’s project graph even though those files may not be documents handled by the server itself.

Source

pub fn notify_file_closed(&mut self, file_path: &Path) -> Result<(), LspError>

Close a document in all servers that have it open.

Source

pub fn client_for_file( &self, file_path: &Path, config: &Config, ) -> Option<&LspClient>

Get an active client for a file path, if one exists.

Source

pub fn client_for_file_default(&self, file_path: &Path) -> Option<&LspClient>

Source

pub fn client_for_file_mut( &mut self, file_path: &Path, config: &Config, ) -> Option<&mut LspClient>

Get a mutable active client for a file path, if one exists.

Source

pub fn client_for_file_mut_default( &mut self, file_path: &Path, ) -> Option<&mut LspClient>

Source

pub fn active_client_count(&self) -> usize

Number of tracked server clients.

Source

pub fn drain_events(&mut self) -> Vec<LspEvent>

Drain all pending LSP events. Call from the main loop.

Source

pub fn wait_for_diagnostics( &mut self, file_path: &Path, config: &Config, timeout: Duration, ) -> Vec<StoredDiagnostic>

Wait for diagnostics to arrive for a specific file until a timeout expires.

Source

pub fn wait_for_diagnostics_default( &mut self, file_path: &Path, timeout: Duration, ) -> Vec<StoredDiagnostic>

Source

pub fn snapshot_diagnostic_epochs( &self, file_path: &Path, ) -> HashMap<ServerKey, u64>

Snapshot the current per-server epoch for every entry that exists for file_path. Servers without an entry yet (never published) are absent from the map; for those, pre = 0 (any first publish will be considered fresh under the epoch-fallback rule).

Source

pub fn wait_for_post_edit_diagnostics( &mut self, file_path: &Path, _config: &Config, expected_versions: &[(ServerKey, i32)], pre_snapshot: &HashMap<ServerKey, u64>, timeout: Duration, ) -> PostEditWaitOutcome

Wait for FRESH per-server diagnostics that match the just-sent document version. This is the v0.17.3 post-edit path that fixes the stale-diagnostics bug: instead of returning whatever is in the cache when the deadline hits, we only return entries whose version matches the post-edit target version (or, for servers that don’t participate in versioned sync, whose epoch was bumped after the pre-edit snapshot).

expected_versions should come from notify_file_changed_versioned — one (ServerKey, target_version) per server we sent didChange/ didOpen to.

pre_snapshot is the per-server epoch BEFORE the notification was sent; it gates the epoch-fallback path so an old-version publish arriving after drain_events and before didChange cannot be mistaken for a fresh response.

Returns a per-server tri-state: Fresh (publish matched target version OR epoch advanced past snapshot for an unversioned server), Pending (deadline hit before this server published anything we could verify), or Exited (server died between notification and deadline).

Source

pub fn wait_for_file_diagnostics( &mut self, file_path: &Path, config: &Config, deadline: Instant, ) -> Vec<StoredDiagnostic>

Wait for diagnostics to arrive for a specific file until a deadline.

Drains already-queued events first, then blocks on the shared event channel only until either publishDiagnostics arrives for this file or the deadline is reached.

Source

pub fn pull_file_timeout() -> Duration

Public accessor so command handlers can reuse the documented default.

Source

pub fn pull_file_diagnostics( &mut self, file_path: &Path, config: &Config, ) -> Result<Vec<PullFileResult>, LspError>

Issue a textDocument/diagnostic (LSP 3.17 per-file pull) request to every server that supports pull diagnostics for the given file.

Returns the per-server outcome. If a server reports kind: "unchanged", the cached entry’s diagnostics are surfaced (deterministic re-use of the previous response). If a server doesn’t advertise pull capability, it’s skipped here — the caller should fall back to push for those.

Side effects: results are stored in DiagnosticsStore so directory-mode queries can aggregate them later.

Source

pub fn pull_workspace_diagnostics( &mut self, server_key: &ServerKey, timeout: Option<Duration>, ) -> Result<PullWorkspaceResult, LspError>

Issue a workspace/diagnostic request to a specific server. Cancels internally if timeout elapses before the server responds. Cached entries from the response are stored so directory-mode queries pick them up.

Source

pub fn shutdown_all(&mut self)

Shutdown all servers gracefully.

Source

pub fn has_active_servers(&self) -> bool

Check if any server is active.

Source

pub fn active_server_keys(&self) -> Vec<ServerKey>

Active server keys (running clients). Used by lsp_diagnostics directory mode to know which servers to ask for workspace pull.

Source

pub fn get_diagnostics_for_file(&self, file: &Path) -> Vec<&StoredDiagnostic>

Source

pub fn get_diagnostics_for_directory( &self, dir: &Path, ) -> Vec<&StoredDiagnostic>

Source

pub fn get_all_diagnostics(&self) -> Vec<&StoredDiagnostic>

Trait Implementations§

Source§

impl Default for LspManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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