@@ -12,7 +12,7 @@ use crate::{
12
12
13
13
// Assist: qualify_method_call
14
14
//
15
- // If the name is resolvable, provides fully qualified path for it .
15
+ // Replaces the method call with a qualified function call .
16
16
//
17
17
// ```
18
18
// struct Foo;
@@ -36,8 +36,10 @@ use crate::{
36
36
// }
37
37
// ```
38
38
pub ( crate ) fn qualify_method_call ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
39
- let call: ast:: MethodCallExpr = ctx. find_node_at_offset ( ) ?;
40
- let fn_name = & call. name_ref ( ) ?;
39
+ let name: ast:: NameRef = ctx. find_node_at_offset ( ) ?;
40
+ let call = name. syntax ( ) . parent ( ) . and_then ( ast:: MethodCallExpr :: cast) ?;
41
+
42
+ let ident = name. ident_token ( ) ?;
41
43
42
44
let range = call. syntax ( ) . text_range ( ) ;
43
45
let resolved_call = ctx. sema . resolve_method_call ( & call) ?;
@@ -52,7 +54,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Opt
52
54
53
55
acc. add (
54
56
AssistId ( "qualify_method_call" , AssistKind :: RefactorInline ) ,
55
- format ! ( "Qualify call `{}`" , fn_name ) ,
57
+ format ! ( "Qualify `{}` method call " , ident . text ( ) ) ,
56
58
range,
57
59
|builder| {
58
60
qualify_candidate. qualify (
@@ -68,7 +70,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Opt
68
70
#[ cfg( test) ]
69
71
mod tests {
70
72
use super :: * ;
71
- use crate :: tests:: check_assist;
73
+ use crate :: tests:: { check_assist, check_assist_not_applicable } ;
72
74
73
75
#[ test]
74
76
fn struct_method ( ) {
@@ -480,6 +482,49 @@ fn main() {
480
482
let test_struct = TestStruct {};
481
483
TestTrait::test_method::<()>(&test_struct)
482
484
}
485
+ "# ,
486
+ ) ;
487
+ }
488
+
489
+ #[ test]
490
+ fn struct_method_over_stuct_instance ( ) {
491
+ check_assist_not_applicable (
492
+ qualify_method_call,
493
+ r#"
494
+ struct Foo;
495
+ impl Foo {
496
+ fn foo(&self) {}
497
+ }
498
+
499
+ fn main() {
500
+ let foo = Foo {};
501
+ f$0oo.foo()
502
+ }
503
+ "# ,
504
+ ) ;
505
+ }
506
+
507
+ #[ test]
508
+ fn trait_method_over_stuct_instance ( ) {
509
+ check_assist_not_applicable (
510
+ qualify_method_call,
511
+ r#"
512
+ mod test_mod {
513
+ pub trait TestTrait {
514
+ fn test_method(&self);
515
+ }
516
+ pub struct TestStruct {}
517
+ impl TestTrait for TestStruct {
518
+ fn test_method(&self) {}
519
+ }
520
+ }
521
+
522
+ use test_mod::*;
523
+
524
+ fn main() {
525
+ let test_struct = test_mod::TestStruct {};
526
+ tes$0t_struct.test_method()
527
+ }
483
528
"# ,
484
529
) ;
485
530
}
0 commit comments