mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #6660
6660: Support "go to definition" for SelfParams r=jonas-schievink a=Veykril Fixes #6657 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
a6f26ded00
1 changed files with 36 additions and 6 deletions
|
@ -3,12 +3,7 @@ use ide_db::{
|
|||
defs::{NameClass, NameRefClass},
|
||||
symbol_index, RootDatabase,
|
||||
};
|
||||
use syntax::{
|
||||
ast::{self},
|
||||
match_ast, AstNode,
|
||||
SyntaxKind::*,
|
||||
SyntaxToken, TokenAtOffset, T,
|
||||
};
|
||||
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
|
||||
|
||||
use crate::{
|
||||
display::{ToNav, TryToNav},
|
||||
|
@ -44,6 +39,12 @@ pub(crate) fn goto_definition(
|
|||
let nav = def.try_to_nav(sema.db)?;
|
||||
vec![nav]
|
||||
},
|
||||
ast::SelfParam(self_param) => {
|
||||
let ty = sema.type_of_self(&self_param)?;
|
||||
let adt_def = ty.autoderef(db).filter_map(|ty| ty.as_adt()).last()?;
|
||||
let nav = adt_def.to_nav(db);
|
||||
vec![nav]
|
||||
},
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
|
@ -981,6 +982,35 @@ trait Iterator {
|
|||
}
|
||||
|
||||
fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn todo_def_type_for_self() {
|
||||
check(
|
||||
r#"
|
||||
struct Foo {}
|
||||
//^^^
|
||||
|
||||
impl Foo {
|
||||
fn bar(&self<|>) {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn todo_def_type_for_arbitrary_self() {
|
||||
check(
|
||||
r#"
|
||||
struct Arc<T>(T);
|
||||
//^^^
|
||||
struct Foo {}
|
||||
|
||||
impl Foo {
|
||||
fn bar(self<|>: Arc<Self>) {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue