Skip to main content

LockFileProvider

Trait LockFileProvider 

Source
pub trait LockFileProvider: Send + Sync {
    // Required methods
    fn locate_lockfile(&self, manifest_uri: &Uri) -> Option<PathBuf>;
    fn parse_lockfile<'a>(
        &'a self,
        lockfile_path: &'a Path,
    ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>;

    // Provided method
    fn is_lockfile_stale(
        &self,
        lockfile_path: &Path,
        last_modified: SystemTime,
    ) -> bool { ... }
}
Expand description

Lock file provider trait for ecosystem-specific implementations.

Implementations parse lock files for a specific package ecosystem (Cargo.lock, package-lock.json, etc.) and extract resolved versions.

§Examples

use deps_core::lockfile::{LockFileProvider, ResolvedPackages};
use std::path::{Path, PathBuf};
use tower_lsp_server::ls_types::Uri;

struct MyLockParser;

impl LockFileProvider for MyLockParser {
    fn locate_lockfile(&self, manifest_uri: &Uri) -> Option<PathBuf> {
        let manifest_path = manifest_uri.to_file_path()?;
        let lock_path = manifest_path.with_file_name("my.lock");
        lock_path.exists().then_some(lock_path)
    }

    fn parse_lockfile<'a>(&'a self, lockfile_path: &'a Path) -> std::pin::Pin<Box<dyn std::future::Future<Output = deps_core::error::Result<ResolvedPackages>> + Send + 'a>> {
        Box::pin(async move {
            // Parse lock file format and extract packages
            Ok(ResolvedPackages::new())
        })
    }
}

Required Methods§

Source

fn locate_lockfile(&self, manifest_uri: &Uri) -> Option<PathBuf>

Locates the lock file for a given manifest URI.

Returns None if:

  • Lock file doesn’t exist
  • Manifest path cannot be determined from URI
  • Workspace root search fails
§Arguments
  • manifest_uri - URI of the manifest file (Cargo.toml, package.json, etc.)
§Returns

Path to lock file if found

Source

fn parse_lockfile<'a>( &'a self, lockfile_path: &'a Path, ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>

Parses a lock file and extracts resolved packages.

§Arguments
  • lockfile_path - Path to the lock file
§Returns

ResolvedPackages on success, error if parse fails

§Errors

Returns an error if:

  • File cannot be read
  • File format is invalid
  • Required fields are missing

Provided Methods§

Source

fn is_lockfile_stale( &self, lockfile_path: &Path, last_modified: SystemTime, ) -> bool

Checks if lock file has been modified since last parse.

Used for cache invalidation. Default implementation compares file modification time.

§Arguments
  • lockfile_path - Path to the lock file
  • last_modified - Last known modification time
§Returns

true if file has been modified or cannot be stat’d, false otherwise

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§