File tree 3 files changed +84
-29
lines changed 3 files changed +84
-29
lines changed Original file line number Diff line number Diff line change @@ -373,19 +373,6 @@ mod baz {
373
373
) ;
374
374
}
375
375
376
- #[ test]
377
- fn not_applicable_in_import_statements ( ) {
378
- check_assist_not_applicable (
379
- auto_import,
380
- r"
381
- use PubStruct$0;
382
-
383
- pub mod PubMod {
384
- pub struct PubStruct;
385
- }" ,
386
- ) ;
387
- }
388
-
389
376
#[ test]
390
377
fn function_import ( ) {
391
378
check_assist (
@@ -1121,4 +1108,43 @@ struct Foo;
1121
1108
"# ,
1122
1109
) ;
1123
1110
}
1111
+
1112
+ #[ test]
1113
+ fn works_in_use_start ( ) {
1114
+ check_assist (
1115
+ auto_import,
1116
+ r#"
1117
+ mod bar {
1118
+ pub mod foo {
1119
+ pub struct Foo;
1120
+ }
1121
+ }
1122
+ use foo$0::Foo;
1123
+ "# ,
1124
+ r#"
1125
+ mod bar {
1126
+ pub mod foo {
1127
+ pub struct Foo;
1128
+ }
1129
+ }
1130
+ use bar::foo;
1131
+ use foo::Foo;
1132
+ "# ,
1133
+ ) ;
1134
+ }
1135
+
1136
+ #[ test]
1137
+ fn not_applicable_in_non_start_use ( ) {
1138
+ check_assist_not_applicable (
1139
+ auto_import,
1140
+ r"
1141
+ mod bar {
1142
+ pub mod foo {
1143
+ pub struct Foo;
1144
+ }
1145
+ }
1146
+ use foo::Foo$0;
1147
+ " ,
1148
+ ) ;
1149
+ }
1124
1150
}
Original file line number Diff line number Diff line change @@ -381,20 +381,6 @@ pub mod PubMod {
381
381
check_assist_not_applicable ( qualify_path, r#"PubStruct$0"# ) ;
382
382
}
383
383
384
- #[ test]
385
- fn not_applicable_in_import_statements ( ) {
386
- check_assist_not_applicable (
387
- qualify_path,
388
- r#"
389
- use PubStruct$0;
390
-
391
- pub mod PubMod {
392
- pub struct PubStruct;
393
- }
394
- "# ,
395
- ) ;
396
- }
397
-
398
384
#[ test]
399
385
fn qualify_function ( ) {
400
386
check_assist (
@@ -1270,4 +1256,42 @@ struct Foo;
1270
1256
"# ,
1271
1257
) ;
1272
1258
}
1259
+
1260
+ #[ test]
1261
+ fn works_in_use_start ( ) {
1262
+ check_assist (
1263
+ qualify_path,
1264
+ r#"
1265
+ mod bar {
1266
+ pub mod foo {
1267
+ pub struct Foo;
1268
+ }
1269
+ }
1270
+ use foo$0::Foo;
1271
+ "# ,
1272
+ r#"
1273
+ mod bar {
1274
+ pub mod foo {
1275
+ pub struct Foo;
1276
+ }
1277
+ }
1278
+ use bar::foo::Foo;
1279
+ "# ,
1280
+ ) ;
1281
+ }
1282
+
1283
+ #[ test]
1284
+ fn not_applicable_in_non_start_use ( ) {
1285
+ check_assist_not_applicable (
1286
+ qualify_path,
1287
+ r"
1288
+ mod bar {
1289
+ pub mod foo {
1290
+ pub struct Foo;
1291
+ }
1292
+ }
1293
+ use foo::Foo$0;
1294
+ " ,
1295
+ ) ;
1296
+ }
1273
1297
}
Original file line number Diff line number Diff line change @@ -114,8 +114,13 @@ impl ImportAssets {
114
114
sema : & Semantics < RootDatabase > ,
115
115
) -> Option < Self > {
116
116
let candidate_node = fully_qualified_path. syntax ( ) . clone ( ) ;
117
- if candidate_node. ancestors ( ) . find_map ( ast:: Use :: cast) . is_some ( ) {
118
- return None ;
117
+ if let Some ( use_tree) = candidate_node. ancestors ( ) . find_map ( ast:: UseTree :: cast) {
118
+ // Path is inside a use tree, then only continue if it is the first segment of a use statement.
119
+ if use_tree. syntax ( ) . parent ( ) . and_then ( ast:: Use :: cast) . is_none ( )
120
+ || fully_qualified_path. qualifier ( ) . is_some ( )
121
+ {
122
+ return None ;
123
+ }
119
124
}
120
125
Some ( Self {
121
126
import_candidate : ImportCandidate :: for_regular_path ( sema, fully_qualified_path) ?,
You can’t perform that action at this time.
0 commit comments