pub struct DocumentState {
pub ecosystem: Ecosystem,
pub ecosystem_id: &'static str,
pub content: String,
pub dependencies: Vec<UnifiedDependency>,
pub versions: HashMap<String, UnifiedVersion>,
pub cached_versions: HashMap<String, String>,
pub resolved_versions: HashMap<String, String>,
pub parsed_at: Instant,
pub loading_state: LoadingState,
pub loading_started_at: Option<Instant>,
/* 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 (Cargo, npm) with unified dependency and version storage.
§Examples
use deps_lsp::document::{DocumentState, Ecosystem, UnifiedDependency};
use deps_lsp::ParsedDependency;
use deps_cargo::{DependencySection, DependencySource};
use tower_lsp_server::ls_types::{Position, Range};
let dep = ParsedDependency {
name: "serde".into(),
name_range: Range::new(Position::new(0, 0), Position::new(0, 5)),
version_req: Some("1.0".into()),
version_range: Some(Range::new(Position::new(0, 8), Position::new(0, 12))),
features: vec![],
features_range: None,
source: DependencySource::Registry,
workspace_inherited: false,
section: DependencySection::Dependencies,
};
let state = DocumentState::new(
Ecosystem::Cargo,
"[dependencies]\nserde = \"1.0\"".into(),
vec![UnifiedDependency::Cargo(dep)],
);
assert!(state.versions.is_empty());
assert_eq!(state.dependencies.len(), 1);Fields§
§ecosystem: EcosystemPackage ecosystem type (deprecated, use ecosystem_id)
ecosystem_id: &'static strEcosystem identifier (“cargo”, “npm”, “pypi”)
content: StringOriginal document content
dependencies: Vec<UnifiedDependency>Parsed dependencies with positions (legacy)
versions: HashMap<String, UnifiedVersion>Cached latest version information from registry
cached_versions: HashMap<String, String>Simplified cached versions (just strings) for new architecture
resolved_versions: HashMap<String, String>Resolved versions from lock file
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)
Implementations§
Source§impl DocumentState
impl DocumentState
Sourcepub fn new(
ecosystem: Ecosystem,
content: String,
dependencies: Vec<UnifiedDependency>,
) -> Self
pub fn new( ecosystem: Ecosystem, content: String, dependencies: Vec<UnifiedDependency>, ) -> Self
Creates a new document state (legacy constructor).
Initializes with the given ecosystem, content, and parsed dependencies. Version information starts empty and is populated asynchronously.
Sourcepub fn new_from_parse_result(
ecosystem_id: &'static str,
content: String,
parse_result: Box<dyn ParseResult>,
) -> Self
pub fn new_from_parse_result( ecosystem_id: &'static str, 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_id: &'static str,
content: String,
) -> Self
pub fn new_without_parse_result( ecosystem_id: &'static str, 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 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 update_versions(&mut self, versions: HashMap<String, UnifiedVersion>)
pub fn update_versions(&mut self, versions: HashMap<String, UnifiedVersion>)
Updates the cached latest version information for dependencies.
Sourcepub fn update_cached_versions(&mut self, versions: HashMap<String, String>)
pub fn update_cached_versions(&mut self, versions: HashMap<String, String>)
Updates the simplified cached versions (new architecture).
Sourcepub fn update_resolved_versions(&mut self, versions: HashMap<String, String>)
pub fn update_resolved_versions(&mut self, versions: HashMap<String, String>)
Updates the resolved versions from lock file.
Sourcepub fn set_loading(&mut self)
pub fn set_loading(&mut self)
Mark document as loading registry data.
§Examples
use deps_lsp::document::DocumentState;
let mut doc = DocumentState::new_without_parse_result("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_lsp::document::{DocumentState, LoadingState};
let mut doc = DocumentState::new_without_parse_result("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_lsp::document::{DocumentState, LoadingState};
let mut doc = DocumentState::new_without_parse_result("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_lsp::document::DocumentState;
let mut doc = DocumentState::new_without_parse_result("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 Freeze for DocumentState
impl !RefUnwindSafe for DocumentState
impl Send for DocumentState
impl Sync for DocumentState
impl Unpin for DocumentState
impl !UnwindSafe 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