Add NavigationTarget::from_impl_item

This commit is contained in:
Jeremy Kolb 2019-03-02 14:57:40 -05:00
parent ad2da5b1da
commit e1b59bfe0b
2 changed files with 22 additions and 14 deletions

View file

@ -3,7 +3,7 @@ use ra_syntax::{
SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast,
SyntaxKind::{self, NAME},
};
use hir::{ModuleSource, FieldSource, Name};
use hir::{ModuleSource, FieldSource, Name, ImplItem};
use crate::{FileSymbol, db::RootDatabase};
@ -174,6 +174,25 @@ impl NavigationTarget {
)
}
pub(crate) fn from_impl_item(
db: &RootDatabase,
impl_item: hir::ImplItem,
) -> NavigationTarget {
match impl_item {
ImplItem::Method(f) => {
NavigationTarget::from_function(db, f)
}
ImplItem::Const(c) => {
let (file_id, node) = c.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
ImplItem::TypeAlias(a) => {
let (file_id, node) = a.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
}
}
#[cfg(test)]
pub(crate) fn assert_match(&self, expected: &str) {
let actual = self.debug_render();