1010use std:: { fmt, iter, ops:: Not } ;
1111
1212use cfg:: { CfgAtom , CfgDiff } ;
13- use flycheck:: FlycheckConfig ;
13+ use flycheck:: { CargoOptions , FlycheckConfig } ;
1414use ide:: {
1515 AssistConfig , CallableSnippets , CompletionConfig , DiagnosticsConfig , ExprFillDefaultMode ,
1616 HighlightConfig , HighlightRelatedConfig , HoverConfig , HoverDocFormat , InlayFieldsToResolve ,
@@ -1364,6 +1364,22 @@ impl Config {
13641364 self . data . check_workspace
13651365 }
13661366
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+
13671383 pub fn flycheck ( & self ) -> FlycheckConfig {
13681384 match & self . data . check_overrideCommand {
13691385 Some ( args) if !args. is_empty ( ) => {
@@ -1389,37 +1405,39 @@ impl Config {
13891405 }
13901406 Some ( _) | None => FlycheckConfig :: CargoCommand {
13911407 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 ( ) ,
14181439 } ,
1419- extra_args : self . check_extra_args ( ) ,
1420- extra_env : self . check_extra_env ( ) ,
14211440 ansi_color_output : self . color_diagnostic_output ( ) ,
1422- target_dir : self . target_dir_from_config ( ) ,
14231441 } ,
14241442 }
14251443 }
@@ -2772,7 +2790,7 @@ mod tests {
27722790 . unwrap ( ) ;
27732791 assert_eq ! ( config. data. cargo_targetDir, None ) ;
27742792 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( ) )
27762794 ) ;
27772795 }
27782796
@@ -2791,7 +2809,7 @@ mod tests {
27912809 . unwrap ( ) ;
27922810 assert_eq ! ( config. data. cargo_targetDir, Some ( TargetDirectory :: UseSubdirectory ( true ) ) ) ;
27932811 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" ) ) )
27952813 ) ;
27962814 }
27972815
@@ -2813,7 +2831,7 @@ mod tests {
28132831 Some ( TargetDirectory :: Directory ( Utf8PathBuf :: from( "other_folder" ) ) )
28142832 ) ;
28152833 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" ) ) )
28172835 ) ;
28182836 }
28192837}
0 commit comments