diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide_db/src/imports_locator.rs | 2 |
2 files changed, 9 insertions, 33 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 788906723..030f44f86 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 | ||
8 | use hir::{ | 8 | use 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 | }; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
@@ -20,9 +20,8 @@ use crate::RootDatabase; | |||
20 | #[derive(Debug, PartialEq, Eq)] | 20 | #[derive(Debug, PartialEq, Eq)] |
21 | pub enum NameKind { | 21 | pub enum NameKind { |
22 | Macro(MacroDef), | 22 | Macro(MacroDef), |
23 | Field(StructField), | 23 | StructField(StructField), |
24 | AssocItem(AssocItem), | 24 | ModuleDef(ModuleDef), |
25 | Def(ModuleDef), | ||
26 | SelfType(ImplBlock), | 25 | SelfType(ImplBlock), |
27 | Local(Local), | 26 | Local(Local), |
28 | TypeParam(TypeParam), | 27 | TypeParam(TypeParam), |
@@ -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,19 +129,8 @@ pub fn classify_name( | |||
142 | } | 129 | } |
143 | } | 130 | } |
144 | 131 | ||
145 | pub 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 | |||
156 | pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { | 132 | pub fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDefinition { |
157 | let kind = NameKind::Field(field); | 133 | let kind = NameKind::StructField(field); |
158 | let parent = field.parent_def(db); | 134 | let parent = field.parent_def(db); |
159 | let container = parent.module(db); | 135 | let container = parent.module(db); |
160 | let visibility = match parent { | 136 | let visibility = match parent { |
@@ -170,7 +146,7 @@ pub fn from_module_def( | |||
170 | def: ModuleDef, | 146 | def: ModuleDef, |
171 | module: Option<Module>, | 147 | module: Option<Module>, |
172 | ) -> NameDefinition { | 148 | ) -> NameDefinition { |
173 | let kind = NameKind::Def(def); | 149 | let kind = NameKind::ModuleDef(def); |
174 | let (container, visibility) = match def { | 150 | let (container, visibility) = match def { |
175 | ModuleDef::Module(it) => { | 151 | ModuleDef::Module(it) => { |
176 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); | 152 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); |
diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 401b8ac0b..86383bcd0 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs | |||
@@ -44,7 +44,7 @@ impl<'a> ImportsLocator<'a> { | |||
44 | .chain(lib_results.into_iter()) | 44 | .chain(lib_results.into_iter()) |
45 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) | 45 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) |
46 | .filter_map(|name_definition_to_import| match name_definition_to_import { | 46 | .filter_map(|name_definition_to_import| match name_definition_to_import { |
47 | NameKind::Def(module_def) => Some(module_def), | 47 | NameKind::ModuleDef(module_def) => Some(module_def), |
48 | _ => None, | 48 | _ => None, |
49 | }) | 49 | }) |
50 | .collect() | 50 | .collect() |