aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-28 16:04:35 +0000
committerGitHub <[email protected]>2020-11-28 16:04:35 +0000
commita6f26ded0037a3efb5625ac3482a2f4ec9eb01a3 (patch)
tree50e45682891a77d01dd7303c24d63ffa0ddd57f8
parente437e38d7ac6804bdfbab4908aa217286481235e (diff)
parentb006856381de97ac0fa06725c31194bc581aadbd (diff)
Merge #6660
6660: Support "go to definition" for SelfParams r=jonas-schievink a=Veykril Fixes #6657 Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r--crates/ide/src/goto_definition.rs42
1 files changed, 36 insertions, 6 deletions
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 15792f947..d41dd3d92 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -3,12 +3,7 @@ use ide_db::{
3 defs::{NameClass, NameRefClass}, 3 defs::{NameClass, NameRefClass},
4 symbol_index, RootDatabase, 4 symbol_index, RootDatabase,
5}; 5};
6use syntax::{ 6use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
7 ast::{self},
8 match_ast, AstNode,
9 SyntaxKind::*,
10 SyntaxToken, TokenAtOffset, T,
11};
12 7
13use crate::{ 8use crate::{
14 display::{ToNav, TryToNav}, 9 display::{ToNav, TryToNav},
@@ -44,6 +39,12 @@ pub(crate) fn goto_definition(
44 let nav = def.try_to_nav(sema.db)?; 39 let nav = def.try_to_nav(sema.db)?;
45 vec![nav] 40 vec![nav]
46 }, 41 },
42 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]
47 },
47 _ => return None, 48 _ => return None,
48 } 49 }
49 }; 50 };
@@ -984,4 +985,33 @@ fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {}
984"#, 985"#,
985 ); 986 );
986 } 987 }
988
989 #[test]
990 fn todo_def_type_for_self() {
991 check(
992 r#"
993struct Foo {}
994 //^^^
995
996impl Foo {
997 fn bar(&self<|>) {}
998}
999"#,
1000 );
1001 }
1002
1003 #[test]
1004 fn todo_def_type_for_arbitrary_self() {
1005 check(
1006 r#"
1007struct Arc<T>(T);
1008 //^^^
1009struct Foo {}
1010
1011impl Foo {
1012 fn bar(self<|>: Arc<Self>) {}
1013}
1014"#,
1015 );
1016 }
987} 1017}