1
1
use hir:: Semantics ;
2
2
use ide_db:: {
3
+ base_db:: FileId ,
3
4
defs:: { NameClass , NameRefClass } ,
4
5
symbol_index, RootDatabase ,
5
6
} ;
@@ -40,10 +41,17 @@ pub(crate) fn goto_definition(
40
41
vec![ nav]
41
42
} ,
42
43
ast:: SelfParam ( self_param) => {
43
- let ty = sema. type_of_self( & self_param) ?;
44
- let adt_def = ty. autoderef( db) . filter_map( |ty| ty. as_adt( ) ) . last( ) ?;
45
- let nav = adt_def. to_nav( db) ;
46
- vec![ nav]
44
+ vec![ self_to_nav_target( self_param, position. file_id) ?]
45
+ } ,
46
+ ast:: PathSegment ( segment) => {
47
+ segment. self_token( ) ?;
48
+ let path = segment. parent_path( ) ;
49
+ if path. qualifier( ) . is_some( ) && !ast:: PathExpr :: can_cast( path. syntax( ) . parent( ) ?. kind( ) ) {
50
+ return None ;
51
+ }
52
+ let func = segment. syntax( ) . ancestors( ) . find_map( ast:: Fn :: cast) ?;
53
+ let self_param = func. param_list( ) ?. self_param( ) ?;
54
+ vec![ self_to_nav_target( self_param, position. file_id) ?]
47
55
} ,
48
56
_ => return None ,
49
57
}
@@ -63,6 +71,20 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
63
71
}
64
72
}
65
73
74
+ fn self_to_nav_target ( self_param : ast:: SelfParam , file_id : FileId ) -> Option < NavigationTarget > {
75
+ let self_token = self_param. self_token ( ) ?;
76
+ Some ( NavigationTarget {
77
+ file_id,
78
+ full_range : self_param. syntax ( ) . text_range ( ) ,
79
+ focus_range : Some ( self_token. text_range ( ) ) ,
80
+ name : self_token. text ( ) . clone ( ) ,
81
+ kind : self_token. kind ( ) ,
82
+ container_name : None ,
83
+ description : None ,
84
+ docs : None ,
85
+ } )
86
+ }
87
+
66
88
#[ derive( Debug ) ]
67
89
pub ( crate ) enum ReferenceResult {
68
90
Exact ( NavigationTarget ) ,
@@ -987,31 +1009,31 @@ fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {}
987
1009
}
988
1010
989
1011
#[ test]
990
- fn todo_def_type_for_self ( ) {
1012
+ fn goto_self_param_ty_specified ( ) {
991
1013
check (
992
1014
r#"
993
1015
struct Foo {}
994
- //^^^
995
1016
996
1017
impl Foo {
997
- fn bar(&self<|>) {}
998
- }
999
- "# ,
1000
- ) ;
1018
+ fn bar(self: &Foo) {
1019
+ //^^^^
1020
+ let foo = sel<|>f;
1021
+ }
1022
+ }"# ,
1023
+ )
1001
1024
}
1002
1025
1003
1026
#[ test]
1004
- fn todo_def_type_for_arbitrary_self ( ) {
1027
+ fn goto_self_param_on_decl ( ) {
1005
1028
check (
1006
1029
r#"
1007
- struct Arc<T>(T);
1008
- //^^^
1009
1030
struct Foo {}
1010
1031
1011
1032
impl Foo {
1012
- fn bar(self<|>: Arc<Self>) {}
1013
- }
1014
- "# ,
1015
- ) ;
1033
+ fn bar(&self<|>) {
1034
+ //^^^^
1035
+ }
1036
+ }"# ,
1037
+ )
1016
1038
}
1017
1039
}
0 commit comments