Struct NpmDependency
pub struct NpmDependency {
pub name: PackageName,
pub name_range: Range,
pub version_req: Option<VersionReq>,
pub version_range: Option<Range>,
pub section: NpmDependencySection,
pub source: DependencySource,
pub catalog: Option<CatalogOrigin>,
}Expand description
Parsed dependency from package.json with position tracking.
Stores all information about a dependency declaration, including its name, version requirement, and source positions for LSP operations. Positions are critical for features like hover, completion, and inlay hints.
§Examples
use deps_npm::types::{NpmDependency, NpmDependencySection};
use tower_lsp_server::ls_types::{Position, Range};
let dep = NpmDependency {
name: "express".into(),
name_range: Range::new(Position::new(5, 4), Position::new(5, 13)),
version_req: Some("^4.18.2".into()),
version_range: Some(Range::new(Position::new(5, 16), Position::new(5, 25))),
section: NpmDependencySection::Dependencies,
source: deps_core::parser::DependencySource::Registry,
catalog: None,
};
assert_eq!(dep.name, "express");
assert!(matches!(dep.section, NpmDependencySection::Dependencies));Fields§
§name: PackageName§name_range: Range§version_req: Option<VersionReq>§version_range: Option<Range>§section: NpmDependencySection§source: DependencySourceResolved by .npmrc lookup (spec 032-npm-npmrc-registry-support) — Registry
(the public default) unless a registry=/@scope:registry= entry applies.
catalog: Option<CatalogOrigin>Some when version_req (before/after resolution) came from a pnpm
catalog:/catalog:<name> specifier (spec 046-pnpm-catalogs); None for every
ordinary literal-range dependency.
Trait Implementations§
§impl Clone for NpmDependency
impl Clone for NpmDependency
§fn clone(&self) -> NpmDependency
fn clone(&self) -> NpmDependency
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Debug for NpmDependency
impl Debug for NpmDependency
§impl Dependency for NpmDependency
impl Dependency for NpmDependency
§fn name(&self) -> &PackageName
fn name(&self) -> &PackageName
Package name
§fn name_range(&self) -> Range
fn name_range(&self) -> Range
LSP range of the dependency name
§fn version_requirement(&self) -> Option<&VersionReq>
fn version_requirement(&self) -> Option<&VersionReq>
Version requirement string (e.g., “^1.0”, “>=2.0”)
§fn version_range(&self) -> Option<Range>
fn version_range(&self) -> Option<Range>
LSP range of the version string
§fn source(&self) -> DependencySource
fn source(&self) -> DependencySource
Dependency source (registry, git, path)
Source§fn features_range(&self) -> Option<Range>
fn features_range(&self) -> Option<Range>
LSP range of the features array (ecosystem-specific, None if not supported)
Source§fn markers(&self) -> Option<&str>
fn markers(&self) -> Option<&str>
Environment marker expression gating this dependency (e.g. PEP 508’s
python_version >= '3.8'). Ecosystem-specific, None if not supported
or not present on this dependency.Source§fn markers_range(&self) -> Option<Range>
fn markers_range(&self) -> Option<Range>
LSP range of the environment marker expression (ecosystem-specific,
None if not supported or not present).Source§fn version_literal(&self) -> Option<&str>
fn version_literal(&self) -> Option<&str>
impl Eq for NpmDependency
§impl PartialEq for NpmDependency
impl PartialEq for NpmDependency
impl StructuralPartialEq for NpmDependency
Auto Trait Implementations§
impl Freeze for NpmDependency
impl RefUnwindSafe for NpmDependency
impl Send for NpmDependency
impl Sync for NpmDependency
impl Unpin for NpmDependency
impl UnsafeUnpin for NpmDependency
impl UnwindSafe for NpmDependency
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§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>
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 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>
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