Introduce DependencyMap for future import routing#269
Conversation
src/resolution.rs
Outdated
| pub fn test_insert_without_canonicalize( | ||
| &mut self, | ||
| context: &Path, | ||
| dependency_root_path: String, | ||
| path: &Path, | ||
| ) { | ||
| self.inner.push(Remapping { | ||
| context_prefix: context.to_path_buf(), | ||
| dependency_root_path, | ||
| target: path.to_path_buf(), | ||
| }); | ||
| self.sort_mappings(); | ||
| } |
| // No matches found | ||
| Err(Error::UnknownLibrary(first_segment.to_string())).with_span(*use_decl.span()) | ||
| } | ||
| } |
There was a problem hiding this comment.
Let's have at least a few unit tests
72a8241 to
e21af35
Compare
e21af35 to
3355d31
Compare
src/resolution.rs
Outdated
| // If your macro generates a different constructor, just swap `From::from` | ||
| // with `Identifier::new(s)` or `Identifier(Arc::from(s))`! |
There was a problem hiding this comment.
Looks like AI generated comment, let's not include those
src/resolution.rs
Outdated
| // --- TEST HELPERS --- | ||
|
|
There was a problem hiding this comment.
| // --- TEST HELPERS --- |
src/resolution.rs
Outdated
| /// The base directory that owns this dependency mapping. | ||
| pub context_prefix: PathBuf, | ||
| /// The name used in the `use` statement (e.g., "math"). | ||
| pub dependency_root_path: String, |
There was a problem hiding this comment.
| pub dependency_root_path: String, | |
| pub drp_name: String, |
src/resolution.rs
Outdated
| // --- TESTS --- | ||
|
|
There was a problem hiding this comment.
| // --- TESTS --- |
b455b6f to
4199eed
Compare
src/resolution.rs
Outdated
| #[derive(Debug, Clone)] | ||
| pub struct Remapping { | ||
| /// The base directory that owns this dependency mapping. | ||
| pub context_prefix: PathBuf, |
There was a problem hiding this comment.
| pub context_prefix: PathBuf, | |
| pub context_prefix: CanonPath, |
src/resolution.rs
Outdated
| pub fn insert( | ||
| &mut self, | ||
| context: CanonPath, | ||
| dependency_root_path: String, |
There was a problem hiding this comment.
| dependency_root_path: String, | |
| drp_name: String, |
src/resolution.rs
Outdated
| Ok(()) | ||
| } | ||
|
|
||
| /// Resolve `use dependency_root_path::...` into a physical file path by finding the |
There was a problem hiding this comment.
| /// Resolve `use dependency_root_path::...` into a physical file path by finding the | |
| /// Resolve `use dependency_root_path_name::...` into a physical file path by finding the |
4199eed to
683082b
Compare
37f7b01 to
3695b8a
Compare
src/parse.rs
Outdated
|
|
||
| impl UseDecl { | ||
| /// Creates a dummy `UseDecl` specifically for testing `DependencyMap` resolution. | ||
| /// It automatically builds the internal Identifier path. |
There was a problem hiding this comment.
| /// It automatically builds the internal Identifier path. |
| /// Returns a `String` containing the OS error if the path does not exist or | ||
| /// cannot be accessed. The caller is expected to map this into a more specific | ||
| /// compiler diagnostic (e.g., `RichError`). |
There was a problem hiding this comment.
Not to block this PR, but the String as an error is too generic, so we will need a follow up PR (after modules are merged into master that would take care of it)
@LesterEvSe could you create a GitHub issue, and link this comment?
| // We use `map_err` here to intercept the generic OS error and enrich | ||
| // it with the specific path that failed |
There was a problem hiding this comment.
| // We use `map_err` here to intercept the generic OS error and enrich | |
| // it with the specific path that failed |
Outdated?
There was a problem hiding this comment.
No, I think it's still necessary
src/resolution.rs
Outdated
| // Check if the current file is executing inside the context's directory tree. | ||
| // This prevents a file in `/project_a/` from using a dependency meant for `/project_b/` | ||
| if !current_file | ||
| .as_path() | ||
| .starts_with(remapping.context_prefix.as_path()) | ||
| { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Could we create a method inside the CanonPath and add rust doc there?
src/resolution.rs
Outdated
| // Safely extract the first segment (the dependency root path) | ||
| let parts: Vec<&str> = use_decl.path().iter().map(|s| s.as_inner()).collect(); | ||
| let first_segment = parts.first().copied().ok_or_else(|| { | ||
| Error::CannotParse("Empty use path".to_string()).with_span(*use_decl.span()) | ||
| })?; |
There was a problem hiding this comment.
Move this to the method of UseDecl
src/resolution.rs
Outdated
| } | ||
| } | ||
|
|
||
| // No matches found |
There was a problem hiding this comment.
| // No matches found |
3695b8a to
fb99a23
Compare
fb99a23 to
f609987
Compare
DependencyMapandRemappingdata structures.