11use std:: {
2+ collections:: BTreeMap ,
23 io:: stdout,
34 mem,
45 sync:: {
@@ -79,11 +80,13 @@ pub struct Args {
7980}
8081
8182pub fn run ( args : Args ) -> Result < ( ) > {
82- let ( target_path, base_path, project_config, unit_options) =
83+ let ( target_path, base_path, project_config, unit_options, symbol_mappings ) =
8384 match ( & args. target , & args. base , & args. project , & args. unit ) {
8485 ( Some ( _) , Some ( _) , None , None )
8586 | ( Some ( _) , None , None , None )
86- | ( None , Some ( _) , None , None ) => ( args. target . clone ( ) , args. base . clone ( ) , None , None ) ,
87+ | ( None , Some ( _) , None , None ) => {
88+ ( args. target . clone ( ) , args. base . clone ( ) , None , None , BTreeMap :: new ( ) )
89+ }
8790 ( None , None , p, u) => {
8891 let project = match p {
8992 Some ( project) => project. clone ( ) ,
@@ -163,15 +166,24 @@ pub fn run(args: Args) -> Result<()> {
163166 let unit_options = units. get ( unit_idx) . and_then ( |u| u. options ( ) . cloned ( ) ) ;
164167 let target_path = object. target_path . clone ( ) ;
165168 let base_path = object. base_path . clone ( ) ;
166- ( target_path, base_path, Some ( project_config) , unit_options)
169+ let symbol_mappings = object. symbol_mappings . clone ( ) ;
170+ ( target_path, base_path, Some ( project_config) , unit_options, symbol_mappings)
167171 }
168172 _ => bail ! ( "Either target and base or project and unit must be specified" ) ,
169173 } ;
170174
171175 if let Some ( output) = & args. output {
172- run_oneshot ( & args, output, target_path. as_deref ( ) , base_path. as_deref ( ) , unit_options)
176+ run_oneshot (
177+ & args,
178+ output,
179+ target_path. as_deref ( ) ,
180+ base_path. as_deref ( ) ,
181+ project_config. as_ref ( ) ,
182+ unit_options,
183+ & symbol_mappings,
184+ )
173185 } else {
174- run_interactive ( args, target_path, base_path, project_config, unit_options)
186+ run_interactive ( args, target_path, base_path, project_config, unit_options, symbol_mappings )
175187 }
176188}
177189
@@ -180,10 +192,13 @@ fn run_oneshot(
180192 output : & Utf8PlatformPath ,
181193 target_path : Option < & Utf8PlatformPath > ,
182194 base_path : Option < & Utf8PlatformPath > ,
195+ project_config : Option < & ProjectConfig > ,
183196 unit_options : Option < ProjectOptions > ,
197+ symbol_mappings : & BTreeMap < String , String > ,
184198) -> Result < ( ) > {
185199 let output_format = OutputFormat :: from_option ( args. format . as_deref ( ) ) ?;
186- let ( diff_config, mapping_config) = build_config_from_args ( args, None , unit_options. as_ref ( ) ) ?;
200+ let ( diff_config, mapping_config) =
201+ build_config_from_args ( args, project_config, unit_options. as_ref ( ) , symbol_mappings) ?;
187202 let target = target_path
188203 . map ( |p| {
189204 obj:: read:: read ( p. as_ref ( ) , & diff_config, DiffSide :: Target )
@@ -209,6 +224,7 @@ fn build_config_from_args(
209224 args : & Args ,
210225 project_config : Option < & ProjectConfig > ,
211226 unit_options : Option < & ProjectOptions > ,
227+ symbol_mappings : & BTreeMap < String , String > ,
212228) -> Result < ( DiffObjConfig , MappingConfig ) > {
213229 let mut diff_config = DiffObjConfig :: default ( ) ;
214230 if let Some ( options) = project_config. and_then ( |config| config. options . as_ref ( ) ) {
@@ -218,7 +234,11 @@ fn build_config_from_args(
218234 apply_project_options ( & mut diff_config, options) ?;
219235 }
220236 apply_config_args ( & mut diff_config, & args. config ) ?;
221- Ok ( ( diff_config, MappingConfig :: default ( ) ) )
237+ Ok ( ( diff_config, MappingConfig {
238+ mappings : symbol_mappings. clone ( ) ,
239+ selecting_left : None ,
240+ selecting_right : None ,
241+ } ) )
222242}
223243
224244pub struct AppState {
@@ -279,6 +299,7 @@ pub struct ObjectConfig {
279299 pub base_path : Option < Utf8PlatformPathBuf > ,
280300 pub metadata : ProjectObjectMetadata ,
281301 pub complete : Option < bool > ,
302+ pub symbol_mappings : BTreeMap < String , String > ,
282303}
283304
284305impl ObjectConfig {
@@ -308,6 +329,7 @@ impl ObjectConfig {
308329 base_path,
309330 metadata : object. metadata . clone ( ) . unwrap_or_default ( ) ,
310331 complete : object. complete ( ) ,
332+ symbol_mappings : object. symbol_mappings . clone ( ) . unwrap_or_default ( ) ,
311333 }
312334 }
313335}
@@ -358,12 +380,17 @@ fn run_interactive(
358380 base_path : Option < Utf8PlatformPathBuf > ,
359381 project_config : Option < ProjectConfig > ,
360382 unit_options : Option < ProjectOptions > ,
383+ symbol_mappings : BTreeMap < String , String > ,
361384) -> Result < ( ) > {
362385 let Some ( symbol_name) = & args. symbol else { bail ! ( "Interactive mode requires a symbol name" ) } ;
363386 let time_format = time:: format_description:: parse_borrowed :: < 2 > ( "[hour]:[minute]:[second]" )
364387 . context ( "Failed to parse time format" ) ?;
365- let ( diff_obj_config, mapping_config) =
366- build_config_from_args ( & args, project_config. as_ref ( ) , unit_options. as_ref ( ) ) ?;
388+ let ( diff_obj_config, mapping_config) = build_config_from_args (
389+ & args,
390+ project_config. as_ref ( ) ,
391+ unit_options. as_ref ( ) ,
392+ & symbol_mappings,
393+ ) ?;
367394 let mut state = AppState {
368395 jobs : Default :: default ( ) ,
369396 waker : Default :: default ( ) ,
0 commit comments