Crate deps_core

Crate deps_core 

Source
Expand description

Core abstractions for deps-lsp.

This crate provides the foundational traits and utilities used across all ecosystem-specific implementations (Cargo, npm, PyPI, etc.).

§Architecture

deps-core defines:

  • Traits: PackageRegistry, ManifestParser, VersionInfo, PackageMetadata
  • HTTP Cache: Shared caching layer with ETag/Last-Modified validation
  • Error Types: Unified error handling across all ecosystems

§Examples

Implementing a registry for a new ecosystem:

use deps_core::{PackageRegistry, VersionInfo, PackageMetadata};
use async_trait::async_trait;

#[derive(Clone)]
struct MyVersion {
    version: String,
    deprecated: bool,
}

impl VersionInfo for MyVersion {
    fn version_string(&self) -> &str {
        &self.version
    }

    fn is_yanked(&self) -> bool {
        self.deprecated
    }
}

#[derive(Clone)]
struct MyMetadata {
    name: String,
    latest: String,
}

impl PackageMetadata for MyMetadata {
    fn name(&self) -> &str {
        &self.name
    }

    fn description(&self) -> Option<&str> {
        None
    }

    fn repository(&self) -> Option<&str> {
        None
    }

    fn documentation(&self) -> Option<&str> {
        None
    }

    fn latest_version(&self) -> &str {
        &self.latest
    }
}

struct MyRegistry;

#[async_trait]
impl PackageRegistry for MyRegistry {
    type Version = MyVersion;
    type Metadata = MyMetadata;
    type VersionReq = String;

    async fn get_versions(&self, _name: &str) -> deps_core::error::Result<Vec<Self::Version>> {
        Ok(vec![])
    }

    async fn get_latest_matching(
        &self,
        _name: &str,
        _req: &Self::VersionReq,
    ) -> deps_core::error::Result<Option<Self::Version>> {
        Ok(None)
    }

    async fn search(&self, _query: &str, _limit: usize) -> deps_core::error::Result<Vec<Self::Metadata>> {
        Ok(vec![])
    }
}

Re-exports§

pub use cache::CachedResponse;
pub use cache::HttpCache;
pub use ecosystem::Dependency;
pub use ecosystem::Ecosystem;
pub use ecosystem::EcosystemConfig;
pub use ecosystem::ParseResult;
pub use ecosystem_registry::EcosystemRegistry;
pub use error::DepsError;
pub use error::Result;
pub use handler::DiagnosticsConfig;
pub use handler::EcosystemHandler;
pub use handler::InlayHintsConfig;
pub use handler::VersionStringGetter;
pub use handler::YankedChecker;
pub use handler::generate_code_actions;
pub use handler::generate_diagnostics;
pub use handler::generate_hover;
pub use handler::generate_inlay_hints;
pub use lockfile::LockFileProvider;
pub use lockfile::ResolvedPackage;
pub use lockfile::ResolvedPackages;
pub use lockfile::ResolvedSource;
pub use lsp_helpers::EcosystemFormatter;
pub use lsp_helpers::generate_code_actions as lsp_generate_code_actions;
pub use lsp_helpers::generate_diagnostics as lsp_generate_diagnostics;
pub use lsp_helpers::generate_hover as lsp_generate_hover;
pub use lsp_helpers::generate_inlay_hints as lsp_generate_inlay_hints;
pub use lsp_helpers::is_same_major_minor;
pub use lsp_helpers::ranges_overlap;
pub use parser::DependencyInfo;
pub use parser::DependencySource;
pub use parser::LoadingState;
pub use parser::ManifestParser;
pub use parser::ParseResultInfo;
pub use registry::Metadata;
pub use registry::PackageMetadata;
pub use registry::PackageRegistry;
pub use registry::Registry;
pub use registry::Version;
pub use registry::VersionInfo;
pub use registry::find_latest_stable;
pub use version_matcher::Pep440Matcher;
pub use version_matcher::SemverMatcher;
pub use version_matcher::VersionRequirementMatcher;
pub use version_matcher::extract_pypi_min_version;
pub use version_matcher::normalize_and_parse_version;

Modules§

cache
completion
Core completion infrastructure for deps-lsp.
ecosystem
ecosystem_registry
error
handler
Generic LSP handler infrastructure.
lockfile
Lock file parsing abstractions.
lsp_helpers
Shared LSP response builders.
macros
Macro utilities for reducing boilerplate in ecosystem implementations.
parser
registry
version_matcher
Version requirement matching abstractions.

Macros§

delegate_to_variants
Delegate a method call to all enum variants.
impl_dependency
Implement Dependency and DependencyInfo traits for a struct.
impl_metadata
Implement Metadata and PackageMetadata traits for a struct.
impl_parse_result
Implement ParseResult trait for a struct.
impl_version
Implement Version and VersionInfo traits for a struct.