ServerState

Struct ServerState 

Source
pub struct ServerState {
    pub documents: DashMap<Uri, DocumentState>,
    pub cache: Arc<HttpCache>,
    pub lockfile_cache: Arc<LockFileCache>,
    pub ecosystem_registry: Arc<EcosystemRegistry>,
    pub cold_start_limiter: ColdStartLimiter,
    /* private fields */
}
Expand description

Global LSP server state.

Manages all open documents, HTTP cache, lock file cache, and background tasks for the server. This state is shared across all LSP handlers via Arc and uses concurrent data structures (DashMap, RwLock) for thread-safe access.

§Examples

use deps_lsp::document::ServerState;
use tower_lsp_server::ls_types::Uri;

let state = ServerState::new();
assert_eq!(state.document_count(), 0);

Fields§

§documents: DashMap<Uri, DocumentState>

Open documents by URI

§cache: Arc<HttpCache>

HTTP cache for registry requests

§lockfile_cache: Arc<LockFileCache>

Lock file cache for parsed lock files

§ecosystem_registry: Arc<EcosystemRegistry>

Ecosystem registry for trait-based architecture

§cold_start_limiter: ColdStartLimiter

Cold start rate limiter

Implementations§

Source§

impl ServerState

Source

pub fn new() -> Self

Creates a new server state with default configuration.

Source

pub fn get_document(&self, uri: &Uri) -> Option<Ref<'_, Uri, DocumentState>>

Retrieves document state by URI.

Returns a read-only reference to the document state if it exists. The reference holds a lock on the internal map, so it should be dropped as soon as possible.

Source

pub fn get_document_clone(&self, uri: &Uri) -> Option<DocumentState>

Retrieves a cloned copy of document state by URI.

This method clones the document state immediately and releases the DashMap lock, allowing concurrent access to the map while the document is being processed. Use this in hot paths where async operations are performed with the document data.

§Performance

Cloning DocumentState is relatively cheap as it only clones String and HashMap metadata, not the underlying parse result trait object.

§Examples
// Lock released immediately after clone
let doc = state.get_document_clone(uri);

if let Some(doc) = doc {
    // Perform async operations without holding lock
    let result = process_async(&doc).await;
}
Source

pub fn update_document(&self, uri: Uri, state: DocumentState)

Updates or inserts document state.

If a document already exists at the given URI, it is replaced. Otherwise, a new entry is created.

Source

pub fn remove_document(&self, uri: &Uri) -> Option<(Uri, DocumentState)>

Removes document state and returns the removed entry.

Returns None if no document exists at the given URI.

Source

pub async fn spawn_background_task(&self, uri: Uri, task: JoinHandle<()>)

Spawns a background task for a document.

If a task already exists for the given URI, it is aborted before the new task is registered. This ensures only one background task runs per document.

Typical use case: fetching version data asynchronously after document open or change.

Source

pub async fn cancel_background_task(&self, uri: &Uri)

Cancels the background task for a document.

If no task exists, this is a no-op.

Source

pub fn document_count(&self) -> usize

Returns the number of open documents.

Trait Implementations§

Source§

impl Default for ServerState

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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, 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more