diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index ab6d111c2..975afc145 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -16,6 +16,7 @@ use rustc_hash::FxHashSet; | |||
16 | use salsa::{Database, ParallelDatabase}; | 16 | use salsa::{Database, ParallelDatabase}; |
17 | use hir::{ | 17 | use hir::{ |
18 | self, | 18 | self, |
19 | source_binder, | ||
19 | FnSignatureInfo, | 20 | FnSignatureInfo, |
20 | Problem, | 21 | Problem, |
21 | }; | 22 | }; |
@@ -166,7 +167,7 @@ impl AnalysisImpl { | |||
166 | /// This return `Vec`: a module may be included from several places. We | 167 | /// This return `Vec`: a module may be included from several places. We |
167 | /// don't handle this case yet though, so the Vec has length at most one. | 168 | /// don't handle this case yet though, so the Vec has length at most one. |
168 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 169 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
169 | let descr = match hir::Module::guess_from_position(&*self.db, position)? { | 170 | let descr = match source_binder::module_from_position(&*self.db, position)? { |
170 | None => return Ok(Vec::new()), | 171 | None => return Ok(Vec::new()), |
171 | Some(it) => it, | 172 | Some(it) => it, |
172 | }; | 173 | }; |
@@ -185,7 +186,7 @@ impl AnalysisImpl { | |||
185 | } | 186 | } |
186 | /// Returns `Vec` for the same reason as `parent_module` | 187 | /// Returns `Vec` for the same reason as `parent_module` |
187 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 188 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
188 | let descr = match hir::Module::guess_from_file_id(&*self.db, file_id)? { | 189 | let descr = match source_binder::module_from_file_id(&*self.db, file_id)? { |
189 | None => return Ok(Vec::new()), | 190 | None => return Ok(Vec::new()), |
190 | Some(it) => it, | 191 | Some(it) => it, |
191 | }; | 192 | }; |
@@ -209,9 +210,11 @@ impl AnalysisImpl { | |||
209 | let file = self.db.source_file(position.file_id); | 210 | let file = self.db.source_file(position.file_id); |
210 | let syntax = file.syntax(); | 211 | let syntax = file.syntax(); |
211 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 212 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
212 | if let Some(fn_descr) = | 213 | if let Some(fn_descr) = source_binder::function_from_child_node( |
213 | hir::Function::guess_for_name_ref(&*self.db, position.file_id, name_ref)? | 214 | &*self.db, |
214 | { | 215 | position.file_id, |
216 | name_ref.syntax(), | ||
217 | )? { | ||
215 | let scope = fn_descr.scope(&*self.db); | 218 | let scope = fn_descr.scope(&*self.db); |
216 | // First try to resolve the symbol locally | 219 | // First try to resolve the symbol locally |
217 | if let Some(entry) = scope.resolve_local_name(name_ref) { | 220 | if let Some(entry) = scope.resolve_local_name(name_ref) { |
@@ -234,7 +237,7 @@ impl AnalysisImpl { | |||
234 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 237 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
235 | if module.has_semi() { | 238 | if module.has_semi() { |
236 | let parent_module = | 239 | let parent_module = |
237 | hir::Module::guess_from_file_id(&*self.db, position.file_id)?; | 240 | source_binder::module_from_file_id(&*self.db, position.file_id)?; |
238 | let child_name = module.name(); | 241 | let child_name = module.name(); |
239 | match (parent_module, child_name) { | 242 | match (parent_module, child_name) { |
240 | (Some(parent_module), Some(child_name)) => { | 243 | (Some(parent_module), Some(child_name)) => { |
@@ -282,18 +285,18 @@ impl AnalysisImpl { | |||
282 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { | 285 | ) -> Cancelable<Option<(ast::BindPat<'a>, hir::Function)>> { |
283 | let syntax = source_file.syntax(); | 286 | let syntax = source_file.syntax(); |
284 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 287 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
285 | let descr = ctry!(hir::Function::guess_for_bind_pat( | 288 | let descr = ctry!(source_binder::function_from_child_node( |
286 | db, | 289 | db, |
287 | position.file_id, | 290 | position.file_id, |
288 | binding | 291 | binding.syntax(), |
289 | )?); | 292 | )?); |
290 | return Ok(Some((binding, descr))); | 293 | return Ok(Some((binding, descr))); |
291 | }; | 294 | }; |
292 | let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); | 295 | let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); |
293 | let descr = ctry!(hir::Function::guess_for_name_ref( | 296 | let descr = ctry!(source_binder::function_from_child_node( |
294 | db, | 297 | db, |
295 | position.file_id, | 298 | position.file_id, |
296 | name_ref | 299 | name_ref.syntax(), |
297 | )?); | 300 | )?); |
298 | let scope = descr.scope(db); | 301 | let scope = descr.scope(db); |
299 | let resolved = ctry!(scope.resolve_local_name(name_ref)); | 302 | let resolved = ctry!(scope.resolve_local_name(name_ref)); |
@@ -327,7 +330,7 @@ impl AnalysisImpl { | |||
327 | fix: None, | 330 | fix: None, |
328 | }) | 331 | }) |
329 | .collect::<Vec<_>>(); | 332 | .collect::<Vec<_>>(); |
330 | if let Some(m) = hir::Module::guess_from_file_id(&*self.db, file_id)? { | 333 | if let Some(m) = source_binder::module_from_file_id(&*self.db, file_id)? { |
331 | for (name_node, problem) in m.problems(&*self.db) { | 334 | for (name_node, problem) in m.problems(&*self.db) { |
332 | let diag = match problem { | 335 | let diag = match problem { |
333 | Problem::UnresolvedModule { candidate } => { | 336 | Problem::UnresolvedModule { candidate } => { |
@@ -418,7 +421,7 @@ impl AnalysisImpl { | |||
418 | if fs.kind == FN_DEF { | 421 | if fs.kind == FN_DEF { |
419 | let fn_file = self.db.source_file(fn_file_id); | 422 | let fn_file = self.db.source_file(fn_file_id); |
420 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { | 423 | if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { |
421 | let descr = ctry!(hir::Function::guess_from_source( | 424 | let descr = ctry!(source_binder::function_from_source( |
422 | &*self.db, fn_file_id, fn_def | 425 | &*self.db, fn_file_id, fn_def |
423 | )?); | 426 | )?); |
424 | if let Some(descriptor) = descr.signature_info(&*self.db) { | 427 | if let Some(descriptor) = descr.signature_info(&*self.db) { |