pub struct EcosystemRegistry { /* private fields */ }Expand description
Registry for all available ecosystems.
This registry manages ecosystem implementations and provides fast lookup by ecosystem ID or manifest filename. It’s designed for thread-safe concurrent access using DashMap.
§Examples
use deps_core::EcosystemRegistry;
use std::sync::Arc;
let registry = EcosystemRegistry::new();
// Register ecosystems (would be actual implementations)
// registry.register(Arc::new(CargoEcosystem::new(cache.clone())));
// registry.register(Arc::new(NpmEcosystem::new(cache.clone())));
// Look up by filename
if let Some(ecosystem) = registry.get_for_filename("Cargo.toml") {
println!("Found ecosystem: {}", ecosystem.display_name());
}
// List all registered ecosystems
for id in registry.ecosystem_ids() {
println!("Registered: {}", id);
}Implementations§
Source§impl EcosystemRegistry
impl EcosystemRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty registry
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
assert_eq!(registry.ecosystem_ids().len(), 0);Sourcepub fn register(&self, ecosystem: Arc<dyn Ecosystem>)
pub fn register(&self, ecosystem: Arc<dyn Ecosystem>)
Register an ecosystem implementation
This method registers the ecosystem and creates filename mappings for all manifest filenames declared by the ecosystem.
§Arguments
ecosystem- Arc-wrapped ecosystem implementation
§Examples
use deps_core::EcosystemRegistry;
use std::sync::Arc;
let registry = EcosystemRegistry::new();
// registry.register(Arc::new(CargoEcosystem::new(cache)));Sourcepub fn get(&self, id: &str) -> Option<Arc<dyn Ecosystem>>
pub fn get(&self, id: &str) -> Option<Arc<dyn Ecosystem>>
Get ecosystem by ID
§Arguments
id- Ecosystem identifier (e.g., “cargo”, “npm”, “pypi”)
§Returns
Some(Arc<dyn Ecosystem>)- Registered ecosystemNone- No ecosystem registered with this ID
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
if let Some(ecosystem) = registry.get("cargo") {
println!("Found: {}", ecosystem.display_name());
}Sourcepub fn get_for_filename(&self, filename: &str) -> Option<Arc<dyn Ecosystem>>
pub fn get_for_filename(&self, filename: &str) -> Option<Arc<dyn Ecosystem>>
Get ecosystem for a filename
Lookup is two-stage: an exact, case-sensitive match against
registered manifest filenames (e.g. "Cargo.toml") is tried first;
if that misses, the filename’s extension is matched case-insensitively
against registered Ecosystem::manifest_extensions. This asymmetry
is deliberate — exact filenames are canonical and case-sensitive on
Unix filesystems, while extensions on unbounded basenames (e.g.
*.csproj) come from MSBuild/Windows projects that commonly vary
case (MyApp.CSPROJ). So MyApp.CSPROJ routes via the extension
fallback, but packages.Config does not match the exact-name
entry for packages.config.
§Arguments
filename- Manifest filename (e.g., “Cargo.toml”, “package.json”)
§Returns
Some(Arc<dyn Ecosystem>)- Ecosystem handling this filenameNone- No ecosystem handles this filename
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
if let Some(ecosystem) = registry.get_for_filename("Cargo.toml") {
println!("Cargo.toml handled by: {}", ecosystem.display_name());
}Sourcepub fn get_for_uri(&self, uri: &Uri) -> Option<Arc<dyn Ecosystem>>
pub fn get_for_uri(&self, uri: &Uri) -> Option<Arc<dyn Ecosystem>>
Get ecosystem from URI
Extracts the filename from the URI path and looks up the ecosystem.
§Arguments
uri- Document URI (file:///path/to/Cargo.toml)
§Returns
Some(Arc<dyn Ecosystem>)- Ecosystem handling this fileNone- No ecosystem handles this file type or URI parsing failed
§Examples
use deps_core::EcosystemRegistry;
use tower_lsp_server::ls_types::Uri;
let registry = EcosystemRegistry::new();
let uri = Uri::from_file_path("/home/user/project/Cargo.toml").unwrap();
if let Some(ecosystem) = registry.get_for_uri(&uri) {
println!("File handled by: {}", ecosystem.display_name());
}Sourcepub fn ecosystem_ids(&self) -> Vec<&'static str>
pub fn ecosystem_ids(&self) -> Vec<&'static str>
Get all registered ecosystem IDs
Returns a vector of all ecosystem IDs currently registered. This is useful for debugging and listing available ecosystems.
§Returns
Vector of ecosystem ID strings
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
// registry.register(cargo_ecosystem);
// registry.register(npm_ecosystem);
for id in registry.ecosystem_ids() {
println!("Registered ecosystem: {}", id);
}Sourcepub fn get_for_lockfile(&self, filename: &str) -> Option<Arc<dyn Ecosystem>>
pub fn get_for_lockfile(&self, filename: &str) -> Option<Arc<dyn Ecosystem>>
Get ecosystem for a lock file name
An entry in Ecosystem::lockfile_filenames is either an exact name
("Cargo.lock") or a single-*-wildcard pattern
("packages.*.lock.json", NuGet’s per-project lock files) — the same
prefix/suffix scheme Ecosystem::manifest_patterns uses, applied
here via a linear scan (mirroring get_for_directory_pattern’s own linear scan)
rather than a dedicated map, since the pattern count per ecosystem is tiny.
§Arguments
filename- Lock file name (e.g., “Cargo.lock”, “package-lock.json”)
§Returns
Some(Arc<dyn Ecosystem>)- Ecosystem using this lock fileNone- No ecosystem uses this lock file
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
// registry.register(cargo_ecosystem);
if let Some(ecosystem) = registry.get_for_lockfile("Cargo.lock") {
println!("Cargo.lock handled by: {}", ecosystem.display_name());
}Sourcepub fn all_lockfile_patterns(&self) -> Vec<String>
pub fn all_lockfile_patterns(&self) -> Vec<String>
Get all lock file patterns for file watching
Returns glob patterns (e.g., “**/Cargo.lock”) for all registered ecosystems.
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
// registry.register(cargo_ecosystem);
// registry.register(npm_ecosystem);
let patterns = registry.all_lockfile_patterns();
for pattern in patterns {
println!("Watching pattern: {}", pattern);
}Sourcepub fn get_for_watched_config(
&self,
filename: &str,
) -> Option<Arc<dyn Ecosystem>>
pub fn get_for_watched_config( &self, filename: &str, ) -> Option<Arc<dyn Ecosystem>>
Get ecosystem for a Ecosystem::watched_config_filenames entry — mirrors
Self::get_for_lockfile exactly, reusing the same exact/single-*-wildcard
matching, but scanning the config list instead of the lockfile one.
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
// registry.register(npm_ecosystem);
if let Some(ecosystem) = registry.get_for_watched_config("pnpm-workspace.yaml") {
println!("pnpm-workspace.yaml handled by: {}", ecosystem.display_name());
}Sourcepub fn all_watched_config_patterns(&self) -> Vec<String>
pub fn all_watched_config_patterns(&self) -> Vec<String>
Get all Ecosystem::watched_config_filenames glob patterns for file watching —
mirrors Self::all_lockfile_patterns, scanning the config list instead.
§Examples
use deps_core::EcosystemRegistry;
let registry = EcosystemRegistry::new();
// registry.register(npm_ecosystem);
let patterns = registry.all_watched_config_patterns();
for pattern in patterns {
println!("Watching pattern: {}", pattern);
}