aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db/src')
-rw-r--r--crates/ra_ide_db/src/defs.rs32
1 files changed, 4 insertions, 28 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 788906723..0599f5e38 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -6,7 +6,7 @@
6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). 6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
7 7
8use hir::{ 8use hir::{
9 Adt, AssocItem, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder, 9 Adt, HasSource, ImplBlock, InFile, Local, MacroDef, Module, ModuleDef, SourceBinder,
10 StructField, TypeParam, VariantDef, 10 StructField, TypeParam, VariantDef,
11}; 11};
12use ra_prof::profile; 12use ra_prof::profile;
@@ -21,7 +21,6 @@ use crate::RootDatabase;
21pub enum NameKind { 21pub enum NameKind {
22 Macro(MacroDef), 22 Macro(MacroDef),
23 Field(StructField), 23 Field(StructField),
24 AssocItem(AssocItem),
25 Def(ModuleDef), 24 Def(ModuleDef),
26 SelfType(ImplBlock), 25 SelfType(ImplBlock),
27 Local(Local), 26 Local(Local),
@@ -92,29 +91,17 @@ pub fn classify_name(
92 ast::FnDef(it) => { 91 ast::FnDef(it) => {
93 let src = name.with_value(it); 92 let src = name.with_value(it);
94 let def: hir::Function = sb.to_def(src)?; 93 let def: hir::Function = sb.to_def(src)?;
95 if parent.parent().and_then(ast::ItemList::cast).map_or(false, |it| it.syntax().parent().and_then(ast::Module::cast).is_none()) { 94 Some(from_module_def(sb.db, def.into(), None))
96 Some(from_assoc_item(sb.db, def.into()))
97 } else {
98 Some(from_module_def(sb.db, def.into(), None))
99 }
100 }, 95 },
101 ast::ConstDef(it) => { 96 ast::ConstDef(it) => {
102 let src = name.with_value(it); 97 let src = name.with_value(it);
103 let def: hir::Const = sb.to_def(src)?; 98 let def: hir::Const = sb.to_def(src)?;
104 if parent.parent().and_then(ast::ItemList::cast).is_some() { 99 Some(from_module_def(sb.db, def.into(), None))
105 Some(from_assoc_item(sb.db, def.into()))
106 } else {
107 Some(from_module_def(sb.db, def.into(), None))
108 }
109 }, 100 },
110 ast::TypeAliasDef(it) => { 101 ast::TypeAliasDef(it) => {
111 let src = name.with_value(it); 102 let src = name.with_value(it);
112 let def: hir::TypeAlias = sb.to_def(src)?; 103 let def: hir::TypeAlias = sb.to_def(src)?;
113 if parent.parent().and_then(ast::ItemList::cast).is_some() { 104 Some(from_module_def(sb.db, def.into(), None))
114 Some(from_assoc_item(sb.db, def.into()))
115 } else {
116 Some(from_module_def(sb.db, def.into(), None))
117 }
118 }, 105 },
119 ast::MacroCall(it) => { 106 ast::MacroCall(it) => {
120 let src = name.with_value(it); 107 let src = name.with_value(it);
@@ -142,17 +129,6 @@ pub fn classify_name(
142 } 129 }
143} 130}
144 131
145pub fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition {
146 let container = item.module(db);
147 let visibility = match item {
148 AssocItem::Function(f) => f.source(db).value.visibility(),
149 AssocItem::Const(c) => c.source(db).value.visibility(),
150 AssocItem::TypeAlias(a) => a.source(db).value.visibility(),
151 };
152 let kind = NameKind::AssocItem(item);
153 NameDefinition { kind, container, visibility }
154}
155
156pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { 132pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition {
157 let kind = NameKind::Field(field); 133 let kind = NameKind::Field(field);
158 let parent = field.parent_def(db); 134 let parent = field.parent_def(db);