DocumentState

Struct DocumentState 

Source
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: Ecosystem

Package ecosystem type (deprecated, use ecosystem_id)

§ecosystem_id: &'static str

Ecosystem identifier (“cargo”, “npm”, “pypi”)

§content: String

Original 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: 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)

Implementations§

Source§

impl DocumentState

Source

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.

Source

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.

Source

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.

Source

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

Gets a reference to the parse result if available.

Source

pub fn update_versions(&mut self, versions: HashMap<String, UnifiedVersion>)

Updates the cached latest version information for dependencies.

Source

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

Updates the simplified cached versions (new architecture).

Source

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

Updates the resolved versions from lock file.

Source

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.

Source

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());
Source

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());
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_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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · 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: 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> 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