Skip to main content

DocumentState

Struct DocumentState 

Source
pub struct DocumentState {
    pub ecosystem: EcosystemId,
    pub content: String,
    pub cached_versions: HashMap<PackageName, PackageVersions>,
    pub resolved_versions: HashMap<PackageName, ConcreteVersion>,
    pub vulnerabilities: VulnerabilityMap,
    pub outcomes: DependencyOutcomes,
    pub parsed_at: Instant,
    pub loading_state: LoadingState,
    pub loading_started_at: Option<Instant>,
    pub version: Option<i32>,
    /* private fields */
}
Expand description

State for a single open document.

Stores the document content, parsed dependency information, and cached version data for a single file. The state is updated when the document changes or when version information is fetched from the registry.

Supports multiple package ecosystems via the trait-based ParseResult.

§Examples

use deps_core::EcosystemId;
use deps_lsp::document::DocumentState;

let state = DocumentState::new_without_parse_result(
    EcosystemId::Cargo,
    "[dependencies]\nserde = \"1.0\"".into(),
);

assert!(state.cached_versions.is_empty());

Fields§

§ecosystem: EcosystemId

Package ecosystem identifier, exhaustively typed.

§content: String

Original document content

§cached_versions: HashMap<PackageName, PackageVersions>

Latest known version and full version list per package, fetched together in a single registry round trip (see PackageVersions).

§resolved_versions: HashMap<PackageName, ConcreteVersion>

Resolved versions from lock file

§vulnerabilities: VulnerabilityMap

OSV.dev scan results, keyed by normalized package name. Empty until the first background scan completes; carried across document edits by preserve_cache so it is not wiped on every keystroke.

§outcomes: DependencyOutcomes

Yanked, deprecation, and fetch-failure findings from the lifecycle’s registry fetch, keyed by normalized package name. This is deliberately a different type from FetchResult’s raw-keyed triple: the split makes a forgotten normalization at a store/merge site a compile error rather than a silent bug for ecosystems where normalization changes the name (e.g. PyPI). See DependencyOutcome for what each of the three channels means. Empty until the first fetch completes; carried across document edits by preserve_cache so it doesn’t flicker off on every keystroke.

§parsed_at: Instant

Last successful parse time

§loading_state: LoadingState

Current loading state for registry data

§loading_started_at: Option<Instant>

When the current loading operation started (for timeout/metrics)

§version: Option<i32>

LSP document version from the client’s didOpen/didChange, None if this state was populated from disk (cold start) rather than an LSP notification.

Threaded into WorkspaceEdit.document_changes so the client can reject a batch edit whose ranges were computed against a buffer state it has since moved past (see handlers::code_lens).

Implementations§

Source§

impl DocumentState

Source

pub fn new_from_parse_result( ecosystem: EcosystemId, content: String, parse_result: Box<dyn ParseResult>, ) -> Self

Creates a new document state using trait objects (new architecture).

This is the preferred constructor for Phase 3+ implementations.

Source

pub fn new_without_parse_result(ecosystem: EcosystemId, content: String) -> Self

Creates a new document state without a parse result.

Used when parsing fails but the document should still be stored to enable fallback completion and other LSP features.

Source

pub fn ecosystem_id(&self) -> &'static str

Returns the ecosystem identifier as a &'static str, derived from DocumentState::ecosystem. Registry lookups (EcosystemRegistry::get) are keyed by string, so this mirrors ecosystem.id().

Source

pub fn parse_result(&self) -> Option<&dyn ParseResult>

Gets a reference to the parse result if available.

Source

pub fn parse_result_arc(&self) -> Option<Arc<dyn ParseResult>>

Returns a cheap Arc clone of the parse result, if available.

Lets a caller (e.g. a handlers::{hover,completion,code_actions} handler) own the parse result and release the DashMap shard Ref before awaiting a registry-bound Ecosystem::generate_* call, without deep-cloning ecosystem-specific parse data on every request (#319).

Source

pub fn update_cached_versions( &mut self, versions: HashMap<PackageName, PackageVersions>, )

Updates the cached registry version data (new architecture).

Source

pub fn update_resolved_versions( &mut self, versions: HashMap<PackageName, ConcreteVersion>, )

Updates the resolved versions from lock file.

Source

pub fn update_vulnerabilities(&mut self, vulnerabilities: VulnerabilityMap)

Updates the OSV.dev scan results.

Source

pub fn replace_outcomes(&mut self, outcomes: DependencyOutcomes)

Replaces the yanked/deprecation/fetch-failure outcome map wholesale (normalized-keyed, see Self::outcomes).

Source

pub fn set_version(&mut self, version: Option<i32>)

Sets the LSP document version from the client’s didOpen/didChange, or clears it (None) for a document populated from disk rather than an LSP notification.

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::DocumentState;

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
assert!(doc.version.is_none());
doc.set_version(Some(3));
assert_eq!(doc.version, Some(3));
Source

pub fn is_ready_for_batch_update(&self) -> bool

Whether this document has everything deps-lsp.updateAllOutdated (and the code lens that surfaces it) need to safely act: version data isn’t currently Loading, and the document has a known LSP version.

version: None means this state was populated from disk after a missed didOpen (server restart/crash) — the client’s buffer may hold unsaved edits the disk copy does not reflect, so batch-editing it is unsafe even though the document is otherwise loaded.

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::DocumentState;

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
assert!(!doc.is_ready_for_batch_update(), "no version yet");

doc.set_version(Some(1));
assert!(doc.is_ready_for_batch_update());

doc.set_loading();
assert!(!doc.is_ready_for_batch_update(), "still loading");
Source

pub fn set_loading(&mut self)

Mark document as loading registry data.

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::DocumentState;

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
doc.set_loading();
assert!(doc.loading_started_at.is_some());
§Thread Safety

This method requires exclusive access (&mut self). When used with DashMap::get_mut(), thread safety is guaranteed by the lock. Calling while already Loading resets the timer.

Source

pub fn set_loaded(&mut self)

Mark document as loaded with fresh data.

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::{DocumentState, LoadingState};

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
doc.set_loading();
doc.set_loaded();
assert_eq!(doc.loading_state, LoadingState::Loaded);
assert!(doc.loading_started_at.is_none());
Source

pub fn set_failed(&mut self)

Mark document as failed to load (keeps old cached data).

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::{DocumentState, LoadingState};

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
doc.set_loading();
doc.set_failed();
assert_eq!(doc.loading_state, LoadingState::Failed);
assert!(doc.loading_started_at.is_none());
Source

pub fn loading_duration(&self) -> Option<Duration>

Get current loading duration if loading.

Returns None if not currently loading, or Some(Duration) representing how long the current loading operation has been running.

§Examples
use deps_core::EcosystemId;
use deps_lsp::document::DocumentState;

let mut doc = DocumentState::new_without_parse_result(EcosystemId::Cargo, "".into());
assert!(doc.loading_duration().is_none());

doc.set_loading();
assert!(doc.loading_duration().is_some());

Trait Implementations§

Source§

impl Clone for DocumentState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DocumentState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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