@@ -218,20 +218,34 @@ pub(crate) fn handle_run_test(
218
218
. unwrap_or_default ( ) ,
219
219
None => "" . to_owned ( ) ,
220
220
} ;
221
- let test_path = if lca. is_empty ( ) {
222
- None
223
- } else if let Some ( ( _ , path) ) = lca. split_once ( "::" ) {
224
- Some ( path)
221
+ let ( package_name , test_path) = if lca. is_empty ( ) {
222
+ ( None , None )
223
+ } else if let Some ( ( package_name , path) ) = lca. split_once ( "::" ) {
224
+ ( Some ( package_name ) , Some ( path) )
225
225
} else {
226
- None
226
+ ( None , None )
227
227
} ;
228
228
let mut handles = vec ! [ ] ;
229
229
for ws in & * state. workspaces {
230
230
if let ProjectWorkspaceKind :: Cargo { cargo, .. } = & ws. kind {
231
+ // If possible, scope the test to a specific package otherwise run at the workspace level
232
+ let ( is_workspace, test_root) = if let Some ( package_name) = package_name {
233
+ if let Some ( package) =
234
+ cargo. packages ( ) . find ( |p| cargo[ * p] . name . replace ( '-' , "_" ) == package_name)
235
+ {
236
+ ( false , cargo[ package] . manifest . parent ( ) )
237
+ } else {
238
+ ( true , cargo. workspace_root ( ) )
239
+ }
240
+ } else {
241
+ ( true , cargo. workspace_root ( ) )
242
+ } ;
243
+
231
244
let handle = flycheck:: CargoTestHandle :: new (
232
245
test_path,
233
246
state. config . cargo_test_options ( ) ,
234
- cargo. workspace_root ( ) ,
247
+ test_root,
248
+ is_workspace,
235
249
state. test_run_sender . clone ( ) ,
236
250
) ?;
237
251
handles. push ( handle) ;
0 commit comments