mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Refactor a bit to prepare for resolving trait assoc items
This commit is contained in:
parent
913ab1ec0a
commit
828d60574f
10 changed files with 85 additions and 54 deletions
|
@ -1,4 +1,4 @@
|
|||
use hir::{FieldSource, HasSource, ImplItem, ModuleSource};
|
||||
use hir::{AssocItem, FieldSource, HasSource, ModuleSource};
|
||||
use ra_db::{FileId, SourceDatabase};
|
||||
use ra_syntax::{
|
||||
algo::visit::{visitor, Visitor},
|
||||
|
@ -221,11 +221,14 @@ impl NavigationTarget {
|
|||
)
|
||||
}
|
||||
|
||||
pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget {
|
||||
match impl_item {
|
||||
ImplItem::Method(it) => NavigationTarget::from_def_source(db, it),
|
||||
ImplItem::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||
ImplItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
|
||||
pub(crate) fn from_assoc_item(
|
||||
db: &RootDatabase,
|
||||
assoc_item: hir::AssocItem,
|
||||
) -> NavigationTarget {
|
||||
match assoc_item {
|
||||
AssocItem::Function(it) => NavigationTarget::from_def_source(db, it),
|
||||
AssocItem::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||
AssocItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ pub(crate) fn reference_definition(
|
|||
match classify_name_ref(db, &analyzer, name_ref) {
|
||||
Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)),
|
||||
Some(FieldAccess(field)) => return Exact(NavigationTarget::from_field(db, field)),
|
||||
Some(AssocItem(assoc)) => return Exact(NavigationTarget::from_impl_item(db, assoc)),
|
||||
Some(AssocItem(assoc)) => return Exact(NavigationTarget::from_assoc_item(db, assoc)),
|
||||
Some(Method(func)) => return Exact(NavigationTarget::from_def_source(db, func)),
|
||||
Some(Def(def)) => match NavigationTarget::from_def(db, def) {
|
||||
Some(nav) => return Exact(nav),
|
||||
|
|
|
@ -117,9 +117,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
}
|
||||
}
|
||||
Some(AssocItem(it)) => res.extend(match it {
|
||||
hir::ImplItem::Method(it) => from_def_source(db, it),
|
||||
hir::ImplItem::Const(it) => from_def_source(db, it),
|
||||
hir::ImplItem::TypeAlias(it) => from_def_source(db, it),
|
||||
hir::AssocItem::Function(it) => from_def_source(db, it),
|
||||
hir::AssocItem::Const(it) => from_def_source(db, it),
|
||||
hir::AssocItem::TypeAlias(it) => from_def_source(db, it),
|
||||
}),
|
||||
Some(Def(it)) => {
|
||||
match it {
|
||||
|
|
|
@ -8,7 +8,7 @@ pub enum NameRefKind {
|
|||
Method(hir::Function),
|
||||
Macro(hir::MacroDef),
|
||||
FieldAccess(hir::StructField),
|
||||
AssocItem(hir::ImplItem),
|
||||
AssocItem(hir::AssocItem),
|
||||
Def(hir::ModuleDef),
|
||||
SelfType(hir::Ty),
|
||||
Pat(AstPtr<ast::BindPat>),
|
||||
|
|
|
@ -102,9 +102,9 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
|
|||
Some(Method(_)) => "function",
|
||||
Some(Macro(_)) => "macro",
|
||||
Some(FieldAccess(_)) => "field",
|
||||
Some(AssocItem(hir::ImplItem::Method(_))) => "function",
|
||||
Some(AssocItem(hir::ImplItem::Const(_))) => "constant",
|
||||
Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type",
|
||||
Some(AssocItem(hir::AssocItem::Function(_))) => "function",
|
||||
Some(AssocItem(hir::AssocItem::Const(_))) => "constant",
|
||||
Some(AssocItem(hir::AssocItem::TypeAlias(_))) => "type",
|
||||
Some(Def(hir::ModuleDef::Module(_))) => "module",
|
||||
Some(Def(hir::ModuleDef::Function(_))) => "function",
|
||||
Some(Def(hir::ModuleDef::Adt(_))) => "type",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue