pub struct WorkspacePathResolver { /* private fields */ }Expand description
Workspace path resolver
Normalizes and validates paths relative to a workspace root.
This is the only way to create WorkspaceFilePath instances.
§Responsibilities
- Convert any path (absolute/relative) to
WorkspaceFilePath - Normalize paths (resolve
..and.) - Validate paths are within workspace
- Share workspace_root via
Arc<Path>for efficient cloning
§Example
let resolver = WorkspacePathResolver::new("/home/user/project".into());
// Absolute path
let p1 = resolver.resolve("/home/user/project/src/lib.rs")?;
// Relative path (resolved from CWD)
let p2 = resolver.resolve("./src/../src/lib.rs")?;
// Strict mode (also checks file existence)
let p3 = resolver.resolve_strict("src/lib.rs")?;Implementations§
Source§impl WorkspacePathResolver
impl WorkspacePathResolver
Sourcepub fn new(workspace_root: PathBuf) -> Self
pub fn new(workspace_root: PathBuf) -> Self
Create a new resolver with the given workspace root
Defaults to WorkspaceType::Workspace. Use with_type for explicit control.
Sourcepub fn with_type(workspace_root: PathBuf, workspace_type: WorkspaceType) -> Self
pub fn with_type(workspace_root: PathBuf, workspace_type: WorkspaceType) -> Self
Create a new resolver with explicit workspace type
Sourcepub fn workspace_type(&self) -> WorkspaceType
pub fn workspace_type(&self) -> WorkspaceType
Get the workspace type
Sourcepub fn resolve_with_provider<P: WorkspaceMetadataProvider>(
&self,
path: impl AsRef<Path>,
provider: &P,
) -> Result<WorkspaceFilePath, ResolveError>
pub fn resolve_with_provider<P: WorkspaceMetadataProvider>( &self, path: impl AsRef<Path>, provider: &P, ) -> Result<WorkspaceFilePath, ResolveError>
Resolve any path to a WorkspaceFilePath with provider-based crate resolution
- Absolute path → convert to relative from workspace_root
- Relative path → resolve from CWD, then convert
../.→ resolved- Outside workspace → error
- crate_name → resolved from provider
Sourcepub fn resolve_strict_with_provider<P: WorkspaceMetadataProvider>(
&self,
path: impl AsRef<Path>,
provider: &P,
) -> Result<WorkspaceFilePath, ResolveError>
pub fn resolve_strict_with_provider<P: WorkspaceMetadataProvider>( &self, path: impl AsRef<Path>, provider: &P, ) -> Result<WorkspaceFilePath, ResolveError>
Resolve with file existence check (strict mode)
Sourcepub fn resolve_relative_with_crate(
&self,
relative: impl AsRef<Path>,
crate_name: CrateName,
) -> WorkspaceFilePath
pub fn resolve_relative_with_crate( &self, relative: impl AsRef<Path>, crate_name: CrateName, ) -> WorkspaceFilePath
Resolve from a path that’s already relative to workspace root (with explicit crate name)
This skips CWD resolution and directly creates a WorkspaceFilePath. Useful when you already have a known-good relative path and crate name.
Sourcepub fn resolve_relative_with_provider<P: WorkspaceMetadataProvider>(
&self,
relative: impl AsRef<Path>,
provider: &P,
) -> Option<WorkspaceFilePath>
pub fn resolve_relative_with_provider<P: WorkspaceMetadataProvider>( &self, relative: impl AsRef<Path>, provider: &P, ) -> Option<WorkspaceFilePath>
Resolve from a path that’s already relative to workspace root (with provider)
This skips CWD resolution and uses the provider to resolve the crate name.
Sourcepub fn workspace_root(&self) -> &Path
pub fn workspace_root(&self) -> &Path
Get the workspace root
Sourcepub fn workspace_root_arc(&self) -> Arc<Path>
pub fn workspace_root_arc(&self) -> Arc<Path>
Get the workspace root as Arc (for deserialization)
Sourcepub fn module_to_file(
&self,
module_path: &SymbolPath,
crate_name: &CrateName,
span_file: Option<&WorkspaceFilePath>,
) -> WorkspaceFilePath
pub fn module_to_file( &self, module_path: &SymbolPath, crate_name: &CrateName, span_file: Option<&WorkspaceFilePath>, ) -> WorkspaceFilePath
Resolve module path to file path
This method centralizes the logic for determining which file a module belongs to. It handles the distinction between:
- Crate root (depth 1): span points to the actual file (main.rs/lib.rs)
- Sub-modules (depth > 1): span points to declaration site (
mod foo;in lib.rs), so path-based inference is needed to get the actual file (foo.rs)
§Arguments
module_path: The symbol path of the modulecrate_name: The crate name for path inferencespan_file: Optional span file (use for crate root to preserve main.rs vs lib.rs)
§Example
let resolver = WorkspacePathResolver::new("/workspace".into());
// For crate root with span → uses span file (preserves main.rs)
let file = resolver.module_to_file(&module_path, &crate_name, Some(&span_file));
// For sub-module → uses path-based inference
let file = resolver.module_to_file(&module_path, &crate_name, None);Sourcepub fn resolve(
&self,
path: impl AsRef<Path>,
) -> Result<WorkspaceFilePath, ResolveError>
pub fn resolve( &self, path: impl AsRef<Path>, ) -> Result<WorkspaceFilePath, ResolveError>
Resolve any path to a WorkspaceFilePath (infers crate_name from path)
This is a simplified API that attempts to infer the crate name from the path.
It looks for crates/<crate-name>/ in the path structure.
For more control, use resolve_with_provider or resolve_relative_with_crate.
Sourcepub fn resolve_relative(
&self,
relative: impl AsRef<Path>,
) -> Option<WorkspaceFilePath>
pub fn resolve_relative( &self, relative: impl AsRef<Path>, ) -> Option<WorkspaceFilePath>
Resolve from a path that’s already relative to workspace root (infers crate_name)
This is a simplified API that skips CWD resolution and infers the crate name.
Sourcepub fn validate_crate_path(
&self,
path: &str,
workspace_members: &[String],
) -> Result<(), ResolveError>
pub fn validate_crate_path( &self, path: &str, workspace_members: &[String], ) -> Result<(), ResolveError>
Validate that a crate:: prefixed path is unambiguous in this workspace
In a multi-crate workspace (WorkspaceType::Workspace), paths starting with
crate:: are ambiguous because it’s unclear which crate is being referred to.
§Arguments
path: The path string to validate (e.g., “crate::domain::model”)workspace_members: List of workspace member paths for error message (e.g., [“crates/core”, “crates/api”])
§Returns
Ok(())if the path is unambiguous (single crate or doesn’t start withcrate::)Err(ResolveError::AmbiguousCratePath)if ambiguous in multi-crate workspace
§Example
let resolver = WorkspacePathResolver::with_type(root, WorkspaceType::Workspace);
let members = vec!["crates/core".to_string(), "crates/api".to_string()];
// This will error in multi-crate workspace
resolver.validate_crate_path("crate::domain", &members)?;
// These are OK
resolver.validate_crate_path("core::domain", &members)?; // explicit crate name
resolver.validate_crate_path("src/domain.rs", &members)?; // file pathTrait Implementations§
Source§impl Clone for WorkspacePathResolver
impl Clone for WorkspacePathResolver
Source§fn clone(&self) -> WorkspacePathResolver
fn clone(&self) -> WorkspacePathResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more