11use crate :: core:: parse:: extract_all;
22use crate :: core:: types:: { RefUse , SpecBlock } ;
33use crate :: core:: walk:: find_markdown_files;
4+ use std:: collections:: HashMap ;
45use std:: fs;
5- use std:: path:: Path ;
6+ use std:: path:: { Path , PathBuf } ;
67
78/// Collect all SpecBlocks and standalone RefUses from the workspace
89pub fn collect_workspace_all (
910 root : & Path ,
1011 ignore_patterns : & [ String ] ,
12+ overrides : Option < & HashMap < PathBuf , String > > ,
1113) -> ( Vec < SpecBlock > , Vec < RefUse > ) {
1214 let files = find_markdown_files ( root, ignore_patterns) ;
1315 let mut all_blocks = Vec :: new ( ) ;
1416 let mut all_refs = Vec :: new ( ) ;
1517
1618 for file_path in files {
17- match fs:: read_to_string ( & file_path) {
19+ // Canonicalize the path for lookup to match the keys in overrides
20+ let lookup_path = fs:: canonicalize ( & file_path) . unwrap_or_else ( |_| file_path. clone ( ) ) ;
21+
22+ let content_result = if let Some ( map) = overrides
23+ && let Some ( content) = map. get ( lookup_path. as_path ( ) )
24+ {
25+ Ok ( content. clone ( ) )
26+ } else {
27+ fs:: read_to_string ( & file_path)
28+ } ;
29+
30+ match content_result {
1831 Ok ( content) => {
1932 let ( blocks, refs) = extract_all ( & content, & file_path) ;
2033 all_blocks. extend ( blocks) ;
@@ -40,7 +53,7 @@ mod tests {
4053 let mut file = File :: create ( & file_path) . unwrap ( ) ;
4154 writeln ! ( file, "<a id=\" ID-1\" ></a>\n # Heading\n [Ref](#ID-2)" ) . unwrap ( ) ;
4255
43- let ( blocks, refs) = collect_workspace_all ( dir. path ( ) , & [ ] ) ;
56+ let ( blocks, refs) = collect_workspace_all ( dir. path ( ) , & [ ] , None ) ;
4457
4558 assert_eq ! ( blocks. len( ) , 1 ) ;
4659 assert_eq ! ( blocks[ 0 ] . id, "ID-1" ) ;
0 commit comments