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: boolWhether 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>
impl<'a> VersionData<'a>
Sourcepub fn new(
cached: &'a HashMap<PackageName, PackageVersions>,
resolved: &'a HashMap<PackageName, ConcreteVersion>,
) -> Self
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());Sourcepub fn with_vulnerabilities(self, vulnerabilities: &'a VulnerabilityMap) -> Self
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());Sourcepub fn with_outcomes(self, outcomes: &'a DependencyOutcomes) -> Self
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());Sourcepub const fn with_ecosystem(self, ecosystem: EcosystemId) -> Self
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));Sourcepub const fn with_offline(self, offline: bool) -> Self
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);Sourcepub const fn with_trust(self, client: &'a Arc<DepsDevClient>) -> Self
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>
impl<'a> Clone for VersionData<'a>
Source§fn clone(&self) -> VersionData<'a>
fn clone(&self) -> VersionData<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more