pub struct SymbolPathResolver { /* private fields */ }Expand description
Resolves WorkspaceFilePath to SymbolPath
§Design
This resolver centralizes the conversion from file paths to Rust symbol paths. It wraps the crate name and layout, providing methods for bidirectional conversion between file paths and symbol paths.
§Example
// For a crate in crates/ directory
let resolver = SymbolPathResolver::with_layout(
"my_crate",
CrateLayout::in_crates("my-crate"),
);
// Module path from file
let module = resolver.resolve_module(&file_path)?;
// → my_crate::foo::bar
// Reverse: symbol to file
let file = resolver.to_workspace_file_path(&symbol, &workspace_root);
// → crates/my-crate/src/foo/bar.rsImplementations§
Source§impl SymbolPathResolver
impl SymbolPathResolver
Sourcepub fn new(crate_name: impl AsRef<str>) -> Self
pub fn new(crate_name: impl AsRef<str>) -> Self
Create a resolver for a crate (assumes Root layout and Lib entry point)
For workspace crates in crates/ directory, use with_layout instead.
Sourcepub fn with_layout(crate_name: impl AsRef<str>, layout: CrateLayout) -> Self
pub fn with_layout(crate_name: impl AsRef<str>, layout: CrateLayout) -> Self
Sourcepub fn with_layout_and_entry(
crate_name: impl AsRef<str>,
layout: CrateLayout,
entry_point: EntryPoint,
) -> Self
pub fn with_layout_and_entry( crate_name: impl AsRef<str>, layout: CrateLayout, entry_point: EntryPoint, ) -> Self
Sourcepub fn from_crate_name(crate_name: CrateName) -> Self
pub fn from_crate_name(crate_name: CrateName) -> Self
Create a resolver from a CrateName (assumes Root layout and Lib entry point)
Sourcepub fn from_crate_name_with_layout(
crate_name: CrateName,
layout: CrateLayout,
) -> Self
pub fn from_crate_name_with_layout( crate_name: CrateName, layout: CrateLayout, ) -> Self
Create a resolver from a CrateName with explicit layout (assumes Lib entry point)
Sourcepub fn from_crate_name_with_layout_and_entry(
crate_name: CrateName,
layout: CrateLayout,
entry_point: EntryPoint,
) -> Self
pub fn from_crate_name_with_layout_and_entry( crate_name: CrateName, layout: CrateLayout, entry_point: EntryPoint, ) -> Self
Create a resolver from a CrateName with explicit layout and entry point
Sourcepub fn from_workspace_path(path: &WorkspaceFilePath) -> Result<Self, ParseError>
pub fn from_workspace_path(path: &WorkspaceFilePath) -> Result<Self, ParseError>
Create a resolver from a WorkspaceFilePath
Extracts the crate name and infers both layout and entry point from the file path.
Sourcepub fn crate_name(&self) -> &CrateName
pub fn crate_name(&self) -> &CrateName
Get the crate name
Sourcepub fn entry_point(&self) -> EntryPoint
pub fn entry_point(&self) -> EntryPoint
Get the entry point
Sourcepub fn layout(&self) -> &CrateLayout
pub fn layout(&self) -> &CrateLayout
Get the crate layout
Sourcepub fn resolve_module(
&self,
path: &WorkspaceFilePath,
) -> Result<SymbolPath, ParseError>
pub fn resolve_module( &self, path: &WorkspaceFilePath, ) -> Result<SymbolPath, ParseError>
Resolve file path to module path (SymbolPath)
e.g., “src/foo/bar.rs” → “my_crate::foo::bar”
Sourcepub fn resolve_item(
&self,
path: &WorkspaceFilePath,
item_name: &str,
) -> Result<SymbolPath, ParseError>
pub fn resolve_item( &self, path: &WorkspaceFilePath, item_name: &str, ) -> Result<SymbolPath, ParseError>
Resolve item in file
e.g., “src/lib.rs” + “MyStruct” → “my_crate::MyStruct”
Sourcepub fn resolve_nested(
&self,
path: &WorkspaceFilePath,
segments: &[&str],
) -> Result<SymbolPath, ParseError>
pub fn resolve_nested( &self, path: &WorkspaceFilePath, segments: &[&str], ) -> Result<SymbolPath, ParseError>
Resolve nested item in file
e.g., “src/lib.rs” + [“Foo”, “new”] → “my_crate::Foo::new”
Sourcepub fn module_path_str(&self, path: &WorkspaceFilePath) -> String
pub fn module_path_str(&self, path: &WorkspaceFilePath) -> String
Get module path string (without parsing to SymbolPath)
Useful when you need the string representation directly.
Sourcepub fn to_workspace_file_path(
&self,
symbol_path: &SymbolPath,
workspace_root: Arc<Path>,
) -> WorkspaceFilePath
pub fn to_workspace_file_path( &self, symbol_path: &SymbolPath, workspace_root: Arc<Path>, ) -> WorkspaceFilePath
Convert SymbolPath to WorkspaceFilePath (reverse of resolve_module)
Determines the file path where a symbol should be defined.
§Rules
crate→src/lib.rscrate::Item→src/lib.rs(item in crate root)crate::foo::Item→src/foo.rs(item in module foo)crate::foo::bar::Item→src/foo/bar.rs(item in nested module)
§Arguments
path: The symbol path to convertworkspace_root: The workspace root for creating WorkspaceFilePath
§Example
let resolver = SymbolPathResolver::new("my_crate");
let symbol = SymbolPath::parse("my_crate::models::User")?;
let file = resolver.to_workspace_file_path(&symbol, &workspace_root);
// → src/models.rsSourcepub fn symbol_path_to_relative(&self, symbol_path: &SymbolPath) -> String
pub fn symbol_path_to_relative(&self, symbol_path: &SymbolPath) -> String
Convert SymbolPath to relative file path string
This is the core logic for reverse conversion. Uses the crate layout and entry point to determine the correct path.
Trait Implementations§
Source§impl Clone for SymbolPathResolver
impl Clone for SymbolPathResolver
Source§fn clone(&self) -> SymbolPathResolver
fn clone(&self) -> SymbolPathResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more