From b006856381de97ac0fa06725c31194bc581aadbd Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 28 Nov 2020 16:07:07 +0100 Subject: Support goto definition for ADT-SelfParams --- crates/ide/src/goto_definition.rs | 42 +++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'crates/ide') 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::{ 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 = 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); + //^^^ +struct Foo {} + +impl Foo { + fn bar(self<|>: Arc) {} +} "#, ); } -- cgit v1.2.3