10
10
use std:: { fmt, iter, ops:: Not } ;
11
11
12
12
use cfg:: { CfgAtom , CfgDiff } ;
13
- use flycheck:: FlycheckConfig ;
13
+ use flycheck:: { CargoOptions , FlycheckConfig } ;
14
14
use ide:: {
15
15
AssistConfig , CallableSnippets , CompletionConfig , DiagnosticsConfig , ExprFillDefaultMode ,
16
16
HighlightConfig , HighlightRelatedConfig , HoverConfig , HoverDocFormat , InlayFieldsToResolve ,
@@ -1364,6 +1364,22 @@ impl Config {
1364
1364
self . data . check_workspace
1365
1365
}
1366
1366
1367
+ pub fn cargo_test_options ( & self ) -> CargoOptions {
1368
+ CargoOptions {
1369
+ target_triples : self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ,
1370
+ all_targets : false ,
1371
+ no_default_features : self . data . cargo_noDefaultFeatures ,
1372
+ all_features : matches ! ( self . data. cargo_features, CargoFeaturesDef :: All ) ,
1373
+ features : match self . data . cargo_features . clone ( ) {
1374
+ CargoFeaturesDef :: All => vec ! [ ] ,
1375
+ CargoFeaturesDef :: Selected ( it) => it,
1376
+ } ,
1377
+ extra_args : self . extra_args ( ) . clone ( ) ,
1378
+ extra_env : self . extra_env ( ) . clone ( ) ,
1379
+ target_dir : self . target_dir_from_config ( ) ,
1380
+ }
1381
+ }
1382
+
1367
1383
pub fn flycheck ( & self ) -> FlycheckConfig {
1368
1384
match & self . data . check_overrideCommand {
1369
1385
Some ( args) if !args. is_empty ( ) => {
@@ -1389,37 +1405,39 @@ impl Config {
1389
1405
}
1390
1406
Some ( _) | None => FlycheckConfig :: CargoCommand {
1391
1407
command : self . data . check_command . clone ( ) ,
1392
- target_triples : self
1393
- . data
1394
- . check_targets
1395
- . clone ( )
1396
- . and_then ( |targets| match & targets. 0 [ ..] {
1397
- [ ] => None ,
1398
- targets => Some ( targets. into ( ) ) ,
1399
- } )
1400
- . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1401
- all_targets : self . data . check_allTargets . unwrap_or ( self . data . cargo_allTargets ) ,
1402
- no_default_features : self
1403
- . data
1404
- . check_noDefaultFeatures
1405
- . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1406
- all_features : matches ! (
1407
- self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1408
- CargoFeaturesDef :: All
1409
- ) ,
1410
- features : match self
1411
- . data
1412
- . check_features
1413
- . clone ( )
1414
- . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1415
- {
1416
- CargoFeaturesDef :: All => vec ! [ ] ,
1417
- CargoFeaturesDef :: Selected ( it) => it,
1408
+ options : CargoOptions {
1409
+ target_triples : self
1410
+ . data
1411
+ . check_targets
1412
+ . clone ( )
1413
+ . and_then ( |targets| match & targets. 0 [ ..] {
1414
+ [ ] => None ,
1415
+ targets => Some ( targets. into ( ) ) ,
1416
+ } )
1417
+ . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1418
+ all_targets : self . data . check_allTargets . unwrap_or ( self . data . cargo_allTargets ) ,
1419
+ no_default_features : self
1420
+ . data
1421
+ . check_noDefaultFeatures
1422
+ . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1423
+ all_features : matches ! (
1424
+ self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1425
+ CargoFeaturesDef :: All
1426
+ ) ,
1427
+ features : match self
1428
+ . data
1429
+ . check_features
1430
+ . clone ( )
1431
+ . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1432
+ {
1433
+ CargoFeaturesDef :: All => vec ! [ ] ,
1434
+ CargoFeaturesDef :: Selected ( it) => it,
1435
+ } ,
1436
+ extra_args : self . check_extra_args ( ) ,
1437
+ extra_env : self . check_extra_env ( ) ,
1438
+ target_dir : self . target_dir_from_config ( ) ,
1418
1439
} ,
1419
- extra_args : self . check_extra_args ( ) ,
1420
- extra_env : self . check_extra_env ( ) ,
1421
1440
ansi_color_output : self . color_diagnostic_output ( ) ,
1422
- target_dir : self . target_dir_from_config ( ) ,
1423
1441
} ,
1424
1442
}
1425
1443
}
@@ -2772,7 +2790,7 @@ mod tests {
2772
2790
. unwrap ( ) ;
2773
2791
assert_eq ! ( config. data. cargo_targetDir, None ) ;
2774
2792
assert ! (
2775
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir. is_none( ) )
2793
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { options , .. } if options . target_dir. is_none( ) )
2776
2794
) ;
2777
2795
}
2778
2796
@@ -2791,7 +2809,7 @@ mod tests {
2791
2809
. unwrap ( ) ;
2792
2810
assert_eq ! ( config. data. cargo_targetDir, Some ( TargetDirectory :: UseSubdirectory ( true ) ) ) ;
2793
2811
assert ! (
2794
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( Utf8PathBuf :: from( "target/rust-analyzer" ) ) )
2812
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { options , .. } if options . target_dir == Some ( Utf8PathBuf :: from( "target/rust-analyzer" ) ) )
2795
2813
) ;
2796
2814
}
2797
2815
@@ -2813,7 +2831,7 @@ mod tests {
2813
2831
Some ( TargetDirectory :: Directory ( Utf8PathBuf :: from( "other_folder" ) ) )
2814
2832
) ;
2815
2833
assert ! (
2816
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( Utf8PathBuf :: from( "other_folder" ) ) )
2834
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { options , .. } if options . target_dir == Some ( Utf8PathBuf :: from( "other_folder" ) ) )
2817
2835
) ;
2818
2836
}
2819
2837
}
0 commit comments