diff options
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index f523f0647..d1eaccf23 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -13,8 +13,8 @@ use ra_syntax::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | HirDatabase, Function, ModuleDef, | 16 | HirDatabase, Function, ModuleDef, Struct, Enum, |
17 | AsName, Module, HirFileId, | 17 | AsName, Module, HirFileId, Crate, |
18 | ids::{LocationCtx, SourceFileItemId}, | 18 | ids::{LocationCtx, SourceFileItemId}, |
19 | }; | 19 | }; |
20 | 20 | ||
@@ -83,7 +83,8 @@ fn module_from_source( | |||
83 | let source_root_id = db.file_source_root(file_id.as_original_file()); | 83 | let source_root_id = db.file_source_root(file_id.as_original_file()); |
84 | db.source_root_crates(source_root_id) | 84 | db.source_root_crates(source_root_id) |
85 | .iter() | 85 | .iter() |
86 | .find_map(|&krate| { | 86 | .map(|&crate_id| Crate { crate_id }) |
87 | .find_map(|krate| { | ||
87 | let module_tree = db.module_tree(krate); | 88 | let module_tree = db.module_tree(krate); |
88 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; | 89 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; |
89 | Some(Module { krate, module_id }) | 90 | Some(Module { krate, module_id }) |
@@ -128,6 +129,28 @@ pub fn function_from_child_node( | |||
128 | function_from_source(db, file_id, fn_def) | 129 | function_from_source(db, file_id, fn_def) |
129 | } | 130 | } |
130 | 131 | ||
132 | pub fn struct_from_module( | ||
133 | db: &impl HirDatabase, | ||
134 | module: Module, | ||
135 | struct_def: &ast::StructDef, | ||
136 | ) -> Struct { | ||
137 | let (file_id, _) = module.definition_source(db); | ||
138 | let file_id = file_id.into(); | ||
139 | let ctx = LocationCtx::new(db, module, file_id); | ||
140 | Struct { | ||
141 | id: ctx.to_def(struct_def), | ||
142 | } | ||
143 | } | ||
144 | |||
145 | pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { | ||
146 | let (file_id, _) = module.definition_source(db); | ||
147 | let file_id = file_id.into(); | ||
148 | let ctx = LocationCtx::new(db, module, file_id); | ||
149 | Enum { | ||
150 | id: ctx.to_def(enum_def), | ||
151 | } | ||
152 | } | ||
153 | |||
131 | pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { | 154 | pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { |
132 | let module = match module_from_file_id(db, file_id) { | 155 | let module = match module_from_file_id(db, file_id) { |
133 | Some(it) => it, | 156 | Some(it) => it, |