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: EcosystemIdPackage ecosystem identifier, exhaustively typed.
content: StringOriginal 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: VulnerabilityMapOSV.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: DependencyOutcomesYanked, 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: InstantLast successful parse time
loading_state: LoadingStateCurrent 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
impl DocumentState
Sourcepub fn new_from_parse_result(
ecosystem: EcosystemId,
content: String,
parse_result: Box<dyn ParseResult>,
) -> Self
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.
Sourcepub fn new_without_parse_result(ecosystem: EcosystemId, content: String) -> Self
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.
Sourcepub fn ecosystem_id(&self) -> &'static str
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().
Sourcepub fn parse_result(&self) -> Option<&dyn ParseResult>
pub fn parse_result(&self) -> Option<&dyn ParseResult>
Gets a reference to the parse result if available.
Sourcepub fn parse_result_arc(&self) -> Option<Arc<dyn ParseResult>>
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).
Sourcepub fn update_cached_versions(
&mut self,
versions: HashMap<PackageName, PackageVersions>,
)
pub fn update_cached_versions( &mut self, versions: HashMap<PackageName, PackageVersions>, )
Updates the cached registry version data (new architecture).
Sourcepub fn update_resolved_versions(
&mut self,
versions: HashMap<PackageName, ConcreteVersion>,
)
pub fn update_resolved_versions( &mut self, versions: HashMap<PackageName, ConcreteVersion>, )
Updates the resolved versions from lock file.
Sourcepub fn update_vulnerabilities(&mut self, vulnerabilities: VulnerabilityMap)
pub fn update_vulnerabilities(&mut self, vulnerabilities: VulnerabilityMap)
Updates the OSV.dev scan results.
Sourcepub fn replace_outcomes(&mut self, outcomes: DependencyOutcomes)
pub fn replace_outcomes(&mut self, outcomes: DependencyOutcomes)
Replaces the yanked/deprecation/fetch-failure outcome map wholesale (normalized-keyed,
see Self::outcomes).
Sourcepub fn set_version(&mut self, version: Option<i32>)
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));Sourcepub fn is_ready_for_batch_update(&self) -> bool
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");Sourcepub fn set_loading(&mut self)
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.
Sourcepub fn set_loaded(&mut self)
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());Sourcepub fn set_failed(&mut self)
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());Sourcepub fn loading_duration(&self) -> Option<Duration>
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
impl Clone for DocumentState
Auto Trait Implementations§
impl !RefUnwindSafe for DocumentState
impl !UnwindSafe for DocumentState
impl Freeze for DocumentState
impl Send for DocumentState
impl Sync for DocumentState
impl Unpin for DocumentState
impl UnsafeUnpin for DocumentState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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