aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/from_source.rs64
1 files changed, 39 insertions, 25 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 7abb4bd75..3b6454a1d 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -1,8 +1,8 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use hir_def::{ 2use hir_def::{
3 child_by_source::ChildBySource, dyn_map::DynMap, keys, keys::Key, nameres::ModuleSource, 3 child_by_source::ChildBySource, dyn_map::DynMap, keys, keys::Key, nameres::ModuleSource,
4 ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, StaticId, StructId, 4 ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId,
5 TraitId, TypeAliasId, UnionId, VariantId, 5 StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId,
6}; 6};
7use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; 7use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
8use ra_syntax::{ 8use ra_syntax::{
@@ -212,29 +212,43 @@ impl Module {
212} 212}
213 213
214fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { 214fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap {
215 _analyze_container(db, src).unwrap_or_default() 215 return child_by_source(db, src).unwrap_or_default();
216}
217 216
218fn _analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> { 217 fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> {
219 // FIXME: this doesn't try to handle nested declarations 218 for container in src.value.ancestors().skip(1) {
220 for container in src.value.ancestors().skip(1) { 219 let res = match_ast! {
221 let res = match_ast! { 220 match container {
222 match container { 221 ast::TraitDef(it) => {
223 ast::TraitDef(it) => { 222 let def = Trait::from_source(db, src.with_value(it))?;
224 let c = Trait::from_source(db, src.with_value(it))?; 223 def.id.child_by_source(db)
225 c.id.child_by_source(db) 224 },
226 }, 225 ast::ImplBlock(it) => {
227 ast::ImplBlock(it) => { 226 let def = ImplBlock::from_source(db, src.with_value(it))?;
228 let c = ImplBlock::from_source(db, src.with_value(it))?; 227 def.id.child_by_source(db)
229 c.id.child_by_source(db) 228 },
230 }, 229 ast::FnDef(it) => {
231 _ => { continue }, 230 let def = Function::from_source(db, src.with_value(it))?;
232 } 231 DefWithBodyId::from(def.id)
233 }; 232 .child_by_source(db)
234 return Some(res); 233 },
235 } 234 ast::StaticDef(it) => {
235 let def = Static::from_source(db, src.with_value(it))?;
236 DefWithBodyId::from(def.id)
237 .child_by_source(db)
238 },
239 ast::ConstDef(it) => {
240 let def = Const::from_source(db, src.with_value(it))?;
241 DefWithBodyId::from(def.id)
242 .child_by_source(db)
243 },
244 _ => { continue },
245 }
246 };
247 return Some(res);
248 }
236 249
237 let module_source = ModuleSource::from_child_node(db, src); 250 let module_source = ModuleSource::from_child_node(db, src);
238 let c = Module::from_definition(db, src.with_value(module_source))?; 251 let c = Module::from_definition(db, src.with_value(module_source))?;
239 Some(c.id.child_by_source(db)) 252 Some(c.id.child_by_source(db))
253 }
240} 254}