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§
Sourcefn locate_lockfile(&self, manifest_uri: &Uri) -> Option<PathBuf>
fn locate_lockfile(&self, manifest_uri: &Uri) -> Option<PathBuf>
Sourcefn parse_lockfile<'a>(
&'a self,
lockfile_path: &'a Path,
) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>
fn parse_lockfile<'a>( &'a self, lockfile_path: &'a Path, ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>
Provided Methods§
Sourcefn is_lockfile_stale(
&self,
lockfile_path: &Path,
last_modified: SystemTime,
) -> bool
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 filelast_modified- Last known modification time
§Returns
true if file has been modified or cannot be stat’d, false otherwise