Skip to main content

VersionData

Struct VersionData 

Source
pub struct VersionData<'a> {
    pub cached: &'a HashMap<PackageName, PackageVersions>,
    pub resolved: &'a HashMap<PackageName, ConcreteVersion>,
    pub vulnerabilities: Option<&'a VulnerabilityMap>,
    pub outcomes: Option<&'a DependencyOutcomes>,
    pub ecosystem: Option<EcosystemId>,
    pub offline: bool,
    pub trust: Option<&'a Arc<DepsDevClient>>,
}
Expand description

Bundles the two per-package version maps (cached, resolved) that LSP handlers pass together everywhere.

Grouping them prevents accidentally swapping the two map arguments at a call site, since the compiler can no longer typecheck them positionally.

§Examples

use deps_core::{ConcreteVersion, PackageName, PackageVersions, VersionData};
use std::collections::HashMap;

let mut cached = HashMap::new();
cached.insert(PackageName::new("serde"), PackageVersions::latest_only("1.0.214"));

let mut resolved = HashMap::new();
resolved.insert(PackageName::new("serde"), ConcreteVersion::new("1.0.200"));

let versions = VersionData::new(&cached, &resolved);

assert_eq!(versions.cached.get("serde").map(|v| v.latest.as_str()), Some("1.0.214"));
assert_eq!(versions.resolved.get("serde").map(ConcreteVersion::as_str), Some("1.0.200"));

Fields§

§cached: &'a HashMap<PackageName, PackageVersions>

Latest known versions and full version lists from the registry, keyed by package name.

§resolved: &'a HashMap<PackageName, ConcreteVersion>

Versions actually resolved in the lock file, keyed by package name.

§vulnerabilities: Option<&'a VulnerabilityMap>

OSV scan results, keyed by normalized package name. None when no scan has run yet (e.g. the feature is disabled) — distinct from an empty map, which would mean “scanned, nothing found”.

§outcomes: Option<&'a DependencyOutcomes>

Yanked, deprecation, and fetch-failure findings from the most recent lifecycle fetch, keyed by normalized package name — see DependencyOutcome for what each channel means and why they must stay readable together off one lookup (D5 in generate_diagnostics_from_cache, #233/#263/#205/#267). None when no fetch has run yet — distinct from an empty map, which would mean “checked, nothing found”.

§ecosystem: Option<EcosystemId>

This document’s ecosystem, when the caller has one to give. None in most test fixtures and a handful of ecosystem-crate self-tests that predate this field.

Enables two occurrence-aware refinements added for #394 (duplicate dependency names no longer collapsing into one shared finding): generate_diagnostics_from_cache only emits a yanked-version diagnostic on the occurrence whose own in-use version actually matches the recorded finding (S1), and the vulnerability lookups in generate_diagnostics_from_cache, generate_hover, and generate_code_actions prefer a version-qualified crate::osv::VulnerabilityMap key over the plain name when more than one occurrence of a name has a distinct in-use version (S2). When None, both fall back to their pre-#394 name-only behavior.

§offline: bool

Whether network.offline is set (issue #483). When true, generate_hover appends a footer stating that version and vulnerability data were not checked — deliberately more specific than a bare “showing cached data” notice, since hover.rs’s Some(ScanOutcome::Skipped(_)) | None arm renders nothing for an offline OSV skip, which would otherwise look identical to a scanned-and-clean dependency.

§trust: Option<&'a Arc<DepsDevClient>>

The deps.dev client to fetch a supply-chain trust signal through (spec 037), when the caller wants hover to attempt one. None by default and left None by every surface but handlers/hover.rs (deps-lsp) — diagnostics, code actions, inlay hints, and code lenses never set this, which is what makes FR-010’s hover-only scope structural rather than convention: those surfaces cannot reach deps.dev because they are never handed a client. &'a Arc<..>, not &'a DepsDevClient, so generate_hover can clone the Arc into a detached background task.

Implementations§

Source§

impl<'a> VersionData<'a>

Source

pub fn new( cached: &'a HashMap<PackageName, PackageVersions>, resolved: &'a HashMap<PackageName, ConcreteVersion>, ) -> Self

Creates a new VersionData from the cached and resolved version maps.

vulnerabilities starts None; chain Self::with_vulnerabilities to attach a scan result.

§Examples
use deps_core::VersionData;
use std::collections::HashMap;

let cached = HashMap::new();
let resolved = HashMap::new();
let versions = VersionData::new(&cached, &resolved);
assert!(versions.cached.is_empty());
assert!(versions.vulnerabilities.is_none());
Source

pub fn with_vulnerabilities(self, vulnerabilities: &'a VulnerabilityMap) -> Self

Attaches an OSV scan result to this VersionData.

§Examples
use deps_core::VersionData;
use deps_core::osv::VulnerabilityMap;
use std::collections::HashMap;

let cached = HashMap::new();
let resolved = HashMap::new();
let vulns = VulnerabilityMap::new();
let versions = VersionData::new(&cached, &resolved).with_vulnerabilities(&vulns);
assert!(versions.vulnerabilities.is_some());
Source

pub fn with_outcomes(self, outcomes: &'a DependencyOutcomes) -> Self

Attaches yanked, deprecation, and fetch-failure findings to this VersionData. See Self::outcomes.

§Examples
use deps_core::VersionData;
use deps_core::lsp_helpers::DependencyOutcomes;
use std::collections::HashMap;

let cached = HashMap::new();
let resolved = HashMap::new();
let outcomes = DependencyOutcomes::new();
let versions = VersionData::new(&cached, &resolved).with_outcomes(&outcomes);
assert!(versions.outcomes.is_some());
Source

pub const fn with_ecosystem(self, ecosystem: EcosystemId) -> Self

Attaches this document’s ecosystem, enabling the occurrence-aware refinements described on Self::ecosystem.

§Examples
use deps_core::{EcosystemId, VersionData};
use std::collections::HashMap;

let cached = HashMap::new();
let resolved = HashMap::new();
let versions = VersionData::new(&cached, &resolved).with_ecosystem(EcosystemId::Cargo);
assert_eq!(versions.ecosystem, Some(EcosystemId::Cargo));
Source

pub const fn with_offline(self, offline: bool) -> Self

Marks this VersionData as built while network.offline was set, so generate_hover appends its offline footer.

§Examples
use deps_core::VersionData;
use std::collections::HashMap;

let cached = HashMap::new();
let resolved = HashMap::new();
let versions = VersionData::new(&cached, &resolved).with_offline(true);
assert!(versions.offline);
Source

pub const fn with_trust(self, client: &'a Arc<DepsDevClient>) -> Self

Attaches a deps.dev client, enabling generate_hover to attempt a supply-chain trust signal for the hovered dependency. See Self::trust.

§Examples
use deps_core::{DepsDevClient, HttpCache, VersionData};
use std::collections::HashMap;
use std::sync::Arc;

let cached = HashMap::new();
let resolved = HashMap::new();
let client = Arc::new(DepsDevClient::new(Arc::new(HttpCache::new())));
let versions = VersionData::new(&cached, &resolved).with_trust(&client);
assert!(versions.trust.is_some());

Trait Implementations§

Source§

impl<'a> Clone for VersionData<'a>

Source§

fn clone(&self) -> VersionData<'a>

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<'a> Copy for VersionData<'a>

Source§

impl<'a> Debug for VersionData<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for VersionData<'a>

§

impl<'a> !UnwindSafe for VersionData<'a>

§

impl<'a> Freeze for VersionData<'a>

§

impl<'a> Send for VersionData<'a>

§

impl<'a> Sync for VersionData<'a>

§

impl<'a> Unpin for VersionData<'a>

§

impl<'a> UnsafeUnpin for VersionData<'a>

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.

§

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