diff options
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index c3c3b05ed..f506bba70 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -104,10 +104,21 @@ impl FromSource for Const { | |||
104 | impl FromSource for Static { | 104 | impl FromSource for Static { |
105 | type Ast = ast::StaticDef; | 105 | type Ast = ast::StaticDef; |
106 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { | 106 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { |
107 | let id = from_source(db, src)?; | 107 | let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? { |
108 | Some(Static { id }) | 108 | Container::Module(it) => it, |
109 | Container::Trait(_) | Container::ImplBlock(_) => return None, | ||
110 | }; | ||
111 | module | ||
112 | .declarations(db) | ||
113 | .into_iter() | ||
114 | .filter_map(|it| match it { | ||
115 | ModuleDef::Static(it) => Some(it), | ||
116 | _ => None, | ||
117 | }) | ||
118 | .find(|it| same_source(&it.source(db), &src)) | ||
109 | } | 119 | } |
110 | } | 120 | } |
121 | |||
111 | impl FromSource for TypeAlias { | 122 | impl FromSource for TypeAlias { |
112 | type Ast = ast::TypeAliasDef; | 123 | type Ast = ast::TypeAliasDef; |
113 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { | 124 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { |
@@ -271,7 +282,9 @@ where | |||
271 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | 282 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); |
272 | let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; | 283 | let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; |
273 | let ctx = LocationCtx::new(db, module.id, src.file_id); | 284 | let ctx = LocationCtx::new(db, module.id, src.file_id); |
274 | Some(DEF::from_ast(ctx, &src.value)) | 285 | let items = db.ast_id_map(src.file_id); |
286 | let item_id = items.ast_id(&src.value); | ||
287 | Some(DEF::from_ast_id(ctx, item_id)) | ||
275 | } | 288 | } |
276 | 289 | ||
277 | enum Container { | 290 | enum Container { |