Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/defs.rs')
-rw-r--r--crates/ide-db/src/defs.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs
index 540cc70dd5..e5390eeb32 100644
--- a/crates/ide-db/src/defs.rs
+++ b/crates/ide-db/src/defs.rs
@@ -162,6 +162,22 @@ impl IdentClass {
.or_else(|| NameClass::classify_lifetime(sema, lifetime).map(IdentClass::NameClass))
}
+ pub fn classify_token_to_impl(
+ sema: &Semantics<RootDatabase>,
+ token: &SyntaxToken,
+ ) -> Option<Definition> {
+ let p = token.parent()?;
+ match_ast! {
+ match p {
+ ast::NameRef(name_ref) => match NameRefClass::classify_to_impl(sema, name_ref)? {
+ NameRefClass::Definition(d) => Some(d),
+ _ => None,
+ },
+ _ => None,
+ }
+ }
+ }
+
pub fn definitions(self) -> ArrayVec<Definition, 2> {
let mut res = ArrayVec::new();
match self {
@@ -417,6 +433,35 @@ impl NameRefClass {
}
}
+ fn classify_to_impl(
+ sema: &Semantics<RootDatabase>,
+ name_ref: ast::NameRef,
+ ) -> Option<NameRefClass> {
+ let parent = name_ref.syntax().parent()?;
+ match_ast! {
+ match parent {
+ ast::MethodCallExpr(method_call) => {
+ sema.resolve_impl_method(&ast::Expr::MethodCallExpr(method_call))
+ .map(Definition::Function)
+ .map(NameRefClass::Definition)
+ },
+ ast::PathSegment(ps) => {
+ ps.syntax().parent().and_then(ast::Path::cast)
+ .map(|p|
+ p.syntax()
+ .parent()
+ .and_then(ast::PathExpr::cast)
+ .map(|pe|
+ sema.resolve_impl_method(&ast::Expr::PathExpr(pe))
+ .map(Definition::Function)
+ .map(NameRefClass::Definition)
+ ).flatten()
+ ).flatten()
+ },
+ _=> None
+ }
+ }
+ }
pub fn classify_lifetime(
sema: &Semantics<RootDatabase>,
lifetime: &ast::Lifetime,