mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51: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,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
use hir::{ImplItem, Resolution};
|
use hir::Resolution;
|
||||||
|
|
||||||
use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
|
use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo};
|
||||||
|
|
||||||
|
@ -138,18 +138,7 @@ pub(crate) fn reference_definition(
|
||||||
.node_expr(expr)
|
.node_expr(expr)
|
||||||
.and_then(|it| infer_result.assoc_resolutions(it.into()))
|
.and_then(|it| infer_result.assoc_resolutions(it.into()))
|
||||||
{
|
{
|
||||||
match res {
|
return Exact(NavigationTarget::from_impl_item(db, 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));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use ra_syntax::{
|
||||||
SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast,
|
SyntaxNode, SyntaxNodePtr, AstNode, SmolStr, TextRange, ast,
|
||||||
SyntaxKind::{self, NAME},
|
SyntaxKind::{self, NAME},
|
||||||
};
|
};
|
||||||
use hir::{ModuleSource, FieldSource, Name};
|
use hir::{ModuleSource, FieldSource, Name, ImplItem};
|
||||||
|
|
||||||
use crate::{FileSymbol, db::RootDatabase};
|
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)]
|
#[cfg(test)]
|
||||||
pub(crate) fn assert_match(&self, expected: &str) {
|
pub(crate) fn assert_match(&self, expected: &str) {
|
||||||
let actual = self.debug_render();
|
let actual = self.debug_render();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue