LockFileProvider

Trait LockFileProvider 

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

    // 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 async_trait::async_trait;
use std::path::{Path, PathBuf};
use tower_lsp_server::ls_types::Uri;

struct MyLockParser;

#[async_trait]
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)
    }

    async fn parse_lockfile(&self, lockfile_path: &Path) -> deps_core::error::Result<ResolvedPackages> {
        // 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<'life0, 'life1, 'async_trait>( &'life0 self, lockfile_path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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

Implementors§