pub struct LspManager { /* private fields */ }Implementations§
Source§impl LspManager
impl LspManager
Sourcepub const PULL_FILE_TIMEOUT: Duration
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.
pub fn new() -> Self
Sourcepub fn set_extra_env(&mut self, key: &str, value: &str)
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.
Sourcepub fn server_count(&self) -> usize
pub fn server_count(&self) -> usize
Count active LSP server instances.
Sourcepub fn override_binary(&mut self, kind: ServerKind, binary_path: PathBuf)
pub fn override_binary(&mut self, kind: ServerKind, binary_path: PathBuf)
For testing: override the binary for a server kind.
Sourcepub fn ensure_server_for_file(
&mut self,
file_path: &Path,
config: &Config,
) -> Vec<ServerKey>
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.
Sourcepub fn ensure_server_for_file_detailed(
&mut self,
file_path: &Path,
config: &Config,
) -> EnsureServerOutcomes
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).
Sourcepub fn ensure_server_for_file_default(
&mut self,
file_path: &Path,
) -> Vec<ServerKey>
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.
Sourcepub fn ensure_file_open(
&mut self,
file_path: &Path,
config: &Config,
) -> Result<Vec<ServerKey>, LspError>
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.
pub fn ensure_file_open_default( &mut self, file_path: &Path, ) -> Result<Vec<ServerKey>, LspError>
Sourcepub fn notify_file_changed(
&mut self,
file_path: &Path,
content: &str,
config: &Config,
) -> Result<(), LspError>
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.
Sourcepub fn notify_file_changed_versioned(
&mut self,
file_path: &Path,
content: &str,
config: &Config,
) -> Result<Vec<(ServerKey, i32)>, LspError>
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.
pub fn notify_file_changed_default( &mut self, file_path: &Path, content: &str, ) -> Result<(), LspError>
Sourcepub fn notify_files_watched_changed(
&mut self,
paths: &[(PathBuf, FileChangeType)],
_config: &Config,
) -> Result<(), LspError>
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.
Sourcepub fn notify_file_closed(&mut self, file_path: &Path) -> Result<(), LspError>
pub fn notify_file_closed(&mut self, file_path: &Path) -> Result<(), LspError>
Close a document in all servers that have it open.
Sourcepub fn client_for_file(
&self,
file_path: &Path,
config: &Config,
) -> Option<&LspClient>
pub fn client_for_file( &self, file_path: &Path, config: &Config, ) -> Option<&LspClient>
Get an active client for a file path, if one exists.
pub fn client_for_file_default(&self, file_path: &Path) -> Option<&LspClient>
Sourcepub fn client_for_file_mut(
&mut self,
file_path: &Path,
config: &Config,
) -> Option<&mut LspClient>
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.
pub fn client_for_file_mut_default( &mut self, file_path: &Path, ) -> Option<&mut LspClient>
Sourcepub fn active_client_count(&self) -> usize
pub fn active_client_count(&self) -> usize
Number of tracked server clients.
Sourcepub fn drain_events(&mut self) -> Vec<LspEvent>
pub fn drain_events(&mut self) -> Vec<LspEvent>
Drain all pending LSP events. Call from the main loop.
Sourcepub fn wait_for_diagnostics(
&mut self,
file_path: &Path,
config: &Config,
timeout: Duration,
) -> Vec<StoredDiagnostic>
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.
pub fn wait_for_diagnostics_default( &mut self, file_path: &Path, timeout: Duration, ) -> Vec<StoredDiagnostic>
Sourcepub fn snapshot_diagnostic_epochs(
&self,
file_path: &Path,
) -> HashMap<ServerKey, u64>
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).
Sourcepub 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
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).
Sourcepub fn wait_for_file_diagnostics(
&mut self,
file_path: &Path,
config: &Config,
deadline: Instant,
) -> Vec<StoredDiagnostic>
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.
Sourcepub fn pull_file_timeout() -> Duration
pub fn pull_file_timeout() -> Duration
Public accessor so command handlers can reuse the documented default.
Sourcepub fn pull_file_diagnostics(
&mut self,
file_path: &Path,
config: &Config,
) -> Result<Vec<PullFileResult>, LspError>
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.
Sourcepub fn pull_workspace_diagnostics(
&mut self,
server_key: &ServerKey,
timeout: Option<Duration>,
) -> Result<PullWorkspaceResult, LspError>
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.
Sourcepub fn shutdown_all(&mut self)
pub fn shutdown_all(&mut self)
Shutdown all servers gracefully.
Sourcepub fn has_active_servers(&self) -> bool
pub fn has_active_servers(&self) -> bool
Check if any server is active.
Sourcepub fn active_server_keys(&self) -> Vec<ServerKey>
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.
pub fn get_diagnostics_for_file(&self, file: &Path) -> Vec<&StoredDiagnostic>
pub fn get_diagnostics_for_directory( &self, dir: &Path, ) -> Vec<&StoredDiagnostic>
pub fn get_all_diagnostics(&self) -> Vec<&StoredDiagnostic>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LspManager
impl RefUnwindSafe for LspManager
impl Send for LspManager
impl Sync for LspManager
impl Unpin for LspManager
impl UnsafeUnpin for LspManager
impl UnwindSafe for LspManager
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