fix(rust): attach crate-root lib.rs annotations in multi-crate workspace scans - #4
Open
nightscape wants to merge 1 commit into
Open
nightscape wants to merge 1 commit into
nightscape wants to merge 1 commit into
Conversation
In a Cargo workspace scan, every crate's <crate>/src/lib.rs was mapped to the constant module path "_lib", so the docs map deduped them to one and ir_builder mapped "_lib" to the scan root. Result: no crate-level @C4 levels or descriptions, and `ir validate` had nothing annotated to compare. - path_resolver: give crate-root lib.rs a unique crate-dir module path (stripping a trailing `src`); a lib.rs at the scan root still maps to _lib. - ir_builder: collapse <crate>/src/lib.rs to <crate> so annotations land on the crate node. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves how crate-root lib.rs files are mapped to IR/module paths, especially in multi-crate workspace scans, to avoid collisions and to attach annotations to the crate node rather than the physical src/ directory.
Changes:
- Collapse
<crate>/src/lib.rsdirectory mapping to<crate>in the IR builder so annotations land on the crate node. - Update Rust path resolver to derive unique module names for workspace crates’
lib.rs(instead of always_lib). - Add tests covering workspace crate
lib.rsbehavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/archidoc-engine/src/ir_builder.rs | Collapses src/lib.rs to the crate directory for annotation placement. |
| adapters/archidoc-rust/src/path_resolver.rs | Derives unique module names for workspace lib.rs and adds a regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+70
to
81
| let mut dir = relative.parent().unwrap_or(Path::new(".")); | ||
| // A crate-root `lib.rs` represents its crate, not the `src/` directory | ||
| // it physically lives in. Collapse `<crate>/src/lib.rs` to `<crate>` so | ||
| // the annotation lands on the crate node. | ||
| if filename == "lib.rs" | ||
| && dir.file_name().and_then(|n| n.to_str()) == Some("src") | ||
| { | ||
| dir = dir.parent().unwrap_or(Path::new(".")); | ||
| } | ||
| let dir_str = dir.to_string_lossy().replace('\\', "/"); | ||
| if !dir_str.is_empty() { | ||
| return dir_str; |
Comment on lines
+21
to
+33
| let crate_dir = match parent.file_name().and_then(|n| n.to_str()) { | ||
| Some("src") => parent.parent().unwrap_or(Path::new("")), | ||
| _ => parent, | ||
| }; | ||
| let parts: Vec<&str> = crate_dir | ||
| .components() | ||
| .filter_map(|c| c.as_os_str().to_str()) | ||
| .collect(); | ||
| return if parts.is_empty() { | ||
| "_lib".to_string() | ||
| } else { | ||
| parts.join(".") | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Scanning a Cargo workspace (many crates under one root) loses all crate-level annotations. Every crate's
<crate>/src/lib.rsresolves to the constant module path_lib, so:walker'sdocs_map(keyed by module path) dedups all crate libs down to one.ir_builder::module_path_to_dir_pathmaps_lib→.(scan root).Net effect: no crate gets its
@c4level or description, andir validatehas nothing annotated to compare (it silently passes even when crates are added/removed).Fix
path_resolver::path_to_module_name: a crate-rootlib.rsnow derives a unique module path from its crate directory (stripping a trailingsrc). Alib.rsat the scan root still maps to_lib(single-crate behavior unchanged).ir_builder::module_path_to_dir_path: collapse<crate>/src/lib.rs→<crate>so the annotation lands on the crate node.Verified
Against a 20-crate workspace: crate
//!descriptions and@c4levels now attach to crate nodes (0 → 13 with descriptions from existing docs;@c4 containerattaches). Single-crate scans and all existing unit tests unchanged; added a multi-cratepath_resolvertest.🤖 Generated with Claude Code