Skip to content

Commit a6f26de

Browse files
bors[bot]Veykril
andauthored
Merge #6660
6660: Support "go to definition" for SelfParams r=jonas-schievink a=Veykril Fixes #6657 Co-authored-by: Lukas Wirth <[email protected]>
2 parents e437e38 + b006856 commit a6f26de

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

crates/ide/src/goto_definition.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ use ide_db::{
33
defs::{NameClass, NameRefClass},
44
symbol_index, RootDatabase,
55
};
6-
use syntax::{
7-
ast::{self},
8-
match_ast, AstNode,
9-
SyntaxKind::*,
10-
SyntaxToken, TokenAtOffset, T,
11-
};
6+
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
127

138
use crate::{
149
display::{ToNav, TryToNav},
@@ -44,6 +39,12 @@ pub(crate) fn goto_definition(
4439
let nav = def.try_to_nav(sema.db)?;
4540
vec![nav]
4641
},
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+
},
4748
_ => return None,
4849
}
4950
};
@@ -981,6 +982,35 @@ trait Iterator {
981982
}
982983
983984
fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {}
985+
"#,
986+
);
987+
}
988+
989+
#[test]
990+
fn todo_def_type_for_self() {
991+
check(
992+
r#"
993+
struct Foo {}
994+
//^^^
995+
996+
impl Foo {
997+
fn bar(&self<|>) {}
998+
}
999+
"#,
1000+
);
1001+
}
1002+
1003+
#[test]
1004+
fn todo_def_type_for_arbitrary_self() {
1005+
check(
1006+
r#"
1007+
struct Arc<T>(T);
1008+
//^^^
1009+
struct Foo {}
1010+
1011+
impl Foo {
1012+
fn bar(self<|>: Arc<Self>) {}
1013+
}
9841014
"#,
9851015
);
9861016
}

0 commit comments

Comments
 (0)