diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_hir/src/source_binder.rs | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 59f782277..625a2ce45 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -65,11 +65,7 @@ pub fn module_from_child_node( | |||
65 | file_id: FileId, | 65 | file_id: FileId, |
66 | child: &SyntaxNode, | 66 | child: &SyntaxNode, |
67 | ) -> Option<Module> { | 67 | ) -> Option<Module> { |
68 | if let Some(m) = child | 68 | if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { |
69 | .ancestors() | ||
70 | .filter_map(ast::Module::cast) | ||
71 | .find(|it| !it.has_semi()) | ||
72 | { | ||
73 | module_from_inline(db, file_id.into(), m) | 69 | module_from_inline(db, file_id.into(), m) |
74 | } else { | 70 | } else { |
75 | module_from_file_id(db, file_id.into()) | 71 | module_from_file_id(db, file_id.into()) |
@@ -82,14 +78,13 @@ fn module_from_source( | |||
82 | decl_id: Option<SourceFileItemId>, | 78 | decl_id: Option<SourceFileItemId>, |
83 | ) -> Option<Module> { | 79 | ) -> Option<Module> { |
84 | let source_root_id = db.file_source_root(file_id.as_original_file()); | 80 | let source_root_id = db.file_source_root(file_id.as_original_file()); |
85 | db.source_root_crates(source_root_id) | 81 | db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map( |
86 | .iter() | 82 | |krate| { |
87 | .map(|&crate_id| Crate { crate_id }) | ||
88 | .find_map(|krate| { | ||
89 | let module_tree = db.module_tree(krate); | 83 | let module_tree = db.module_tree(krate); |
90 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; | 84 | let module_id = module_tree.find_module_by_source(file_id, decl_id)?; |
91 | Some(Module { krate, module_id }) | 85 | Some(Module { krate, module_id }) |
92 | }) | 86 | }, |
87 | ) | ||
93 | } | 88 | } |
94 | 89 | ||
95 | pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> { | 90 | pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> { |
@@ -116,9 +111,7 @@ pub fn function_from_module( | |||
116 | let (file_id, _) = module.definition_source(db); | 111 | let (file_id, _) = module.definition_source(db); |
117 | let file_id = file_id.into(); | 112 | let file_id = file_id.into(); |
118 | let ctx = LocationCtx::new(db, module, file_id); | 113 | let ctx = LocationCtx::new(db, module, file_id); |
119 | Function { | 114 | Function { id: ctx.to_def(fn_def) } |
120 | id: ctx.to_def(fn_def), | ||
121 | } | ||
122 | } | 115 | } |
123 | 116 | ||
124 | pub fn function_from_child_node( | 117 | pub fn function_from_child_node( |
@@ -138,18 +131,14 @@ pub fn struct_from_module( | |||
138 | let (file_id, _) = module.definition_source(db); | 131 | let (file_id, _) = module.definition_source(db); |
139 | let file_id = file_id.into(); | 132 | let file_id = file_id.into(); |
140 | let ctx = LocationCtx::new(db, module, file_id); | 133 | let ctx = LocationCtx::new(db, module, file_id); |
141 | Struct { | 134 | Struct { id: ctx.to_def(struct_def) } |
142 | id: ctx.to_def(struct_def), | ||
143 | } | ||
144 | } | 135 | } |
145 | 136 | ||
146 | pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { | 137 | pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { |
147 | let (file_id, _) = module.definition_source(db); | 138 | let (file_id, _) = module.definition_source(db); |
148 | let file_id = file_id.into(); | 139 | let file_id = file_id.into(); |
149 | let ctx = LocationCtx::new(db, module, file_id); | 140 | let ctx = LocationCtx::new(db, module, file_id); |
150 | Enum { | 141 | Enum { id: ctx.to_def(enum_def) } |
151 | id: ctx.to_def(enum_def), | ||
152 | } | ||
153 | } | 142 | } |
154 | 143 | ||
155 | pub fn trait_from_module( | 144 | pub fn trait_from_module( |
@@ -160,9 +149,7 @@ pub fn trait_from_module( | |||
160 | let (file_id, _) = module.definition_source(db); | 149 | let (file_id, _) = module.definition_source(db); |
161 | let file_id = file_id.into(); | 150 | let file_id = file_id.into(); |
162 | let ctx = LocationCtx::new(db, module, file_id); | 151 | let ctx = LocationCtx::new(db, module, file_id); |
163 | Trait { | 152 | Trait { id: ctx.to_def(trait_def) } |
164 | id: ctx.to_def(trait_def), | ||
165 | } | ||
166 | } | 153 | } |
167 | 154 | ||
168 | pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { | 155 | pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, TextRange)> { |