mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add NavigationTarget::from_impl_item
This commit is contained in:
parent
ad2da5b1da
commit
e1b59bfe0b
2 changed files with 22 additions and 14 deletions
|
@ -5,7 +5,7 @@ use ra_syntax::{
|
|||
SyntaxNode,
|
||||
};
|
||||
use test_utils::tested_by;
|
||||
use hir::{ImplItem, Resolution};
|
||||
use hir::Resolution;
|
||||
|
||||
use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
|
||||
|
||||
|
@ -138,18 +138,7 @@ pub(crate) fn reference_definition(
|
|||
.node_expr(expr)
|
||||
.and_then(|it| infer_result.assoc_resolutions(it.into()))
|
||||
{
|
||||
match res {
|
||||
ImplItem::Method(f) => {
|
||||
return Exact(NavigationTarget::from_function(db, f));
|
||||
}
|
||||
ImplItem::Const(c) => {
|
||||
let (file, node) = c.source(db);
|
||||
let file = file.original_file(db);
|
||||
let node = &*node;
|
||||
return Exact(NavigationTarget::from_named(file, node));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return Exact(NavigationTarget::from_impl_item(db, res));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue