@@ -29,16 +29,15 @@ pub(crate) fn replace_qualified_name_with_use(
29
29
acc : & mut Assists ,
30
30
ctx : & AssistContext < ' _ > ,
31
31
) -> Option < ( ) > {
32
- let original_path: ast:: Path = ctx. find_node_at_offset ( ) ?;
32
+ let mut original_path: ast:: Path = ctx. find_node_at_offset ( ) ?;
33
33
// We don't want to mess with use statements
34
34
if original_path. syntax ( ) . ancestors ( ) . find_map ( ast:: UseTree :: cast) . is_some ( ) {
35
35
cov_mark:: hit!( not_applicable_in_use) ;
36
36
return None ;
37
37
}
38
38
39
39
if original_path. qualifier ( ) . is_none ( ) {
40
- cov_mark:: hit!( dont_import_trivial_paths) ;
41
- return None ;
40
+ original_path = original_path. parent_path ( ) ?;
42
41
}
43
42
44
43
// only offer replacement for non assoc items
@@ -236,12 +235,6 @@ fs::Path
236
235
) ;
237
236
}
238
237
239
- #[ test]
240
- fn dont_import_trivial_paths ( ) {
241
- cov_mark:: check!( dont_import_trivial_paths) ;
242
- check_assist_not_applicable ( replace_qualified_name_with_use, r"impl foo$0 for () {}" ) ;
243
- }
244
-
245
238
#[ test]
246
239
fn test_replace_not_applicable_in_use ( ) {
247
240
cov_mark:: check!( not_applicable_in_use) ;
@@ -271,6 +264,29 @@ fn main() {
271
264
) ;
272
265
}
273
266
267
+ #[ test]
268
+ fn assist_runs_on_first_segment ( ) {
269
+ check_assist (
270
+ replace_qualified_name_with_use,
271
+ r"
272
+ mod std { pub mod fmt { pub trait Debug {} } }
273
+ fn main() {
274
+ $0std::fmt::Debug;
275
+ let x: std::fmt::Debug = std::fmt::Debug;
276
+ }
277
+ " ,
278
+ r"
279
+ use std::fmt;
280
+
281
+ mod std { pub mod fmt { pub trait Debug {} } }
282
+ fn main() {
283
+ fmt::Debug;
284
+ let x: fmt::Debug = fmt::Debug;
285
+ }
286
+ " ,
287
+ ) ;
288
+ }
289
+
274
290
#[ test]
275
291
fn does_not_replace_in_submodules ( ) {
276
292
check_assist (
0 commit comments