diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-06 16:50:01 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-06 16:50:01 +0000 |
commit | 895cdb588314f4e04529d1adf8cd232856497dad (patch) | |
tree | 6466cb45c30478eb0c413c25cc6d07cf23d39d3a /crates/ra_ide_db/src | |
parent | 8b957caf83b18b3fea153f770bfd0ed979227eff (diff) | |
parent | d1e8b8d134da802eecef5cbcd5486bd542ad75b5 (diff) |
Merge #3034
3034: Remove ImportLocator hack r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db/src')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_db/src/imports_locator.rs | 45 |
2 files changed, 22 insertions, 25 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index cee6dde8e..788906723 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -92,7 +92,7 @@ pub fn classify_name( | |||
92 | ast::FnDef(it) => { | 92 | ast::FnDef(it) => { |
93 | let src = name.with_value(it); | 93 | let src = name.with_value(it); |
94 | let def: hir::Function = sb.to_def(src)?; | 94 | let def: hir::Function = sb.to_def(src)?; |
95 | if parent.parent().and_then(ast::ItemList::cast).is_some() { | 95 | if parent.parent().and_then(ast::ItemList::cast).map_or(false, |it| it.syntax().parent().and_then(ast::Module::cast).is_none()) { |
96 | Some(from_assoc_item(sb.db, def.into())) | 96 | Some(from_assoc_item(sb.db, def.into())) |
97 | } else { | 97 | } else { |
98 | Some(from_module_def(sb.db, def.into(), None)) | 98 | Some(from_module_def(sb.db, def.into(), None)) |
diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 21e637608..d77fc53f3 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | //! Later, this should be moved away to a separate crate that is accessible from the ra_assists module. | 2 | //! Later, this should be moved away to a separate crate that is accessible from the ra_assists module. |
3 | 3 | ||
4 | use hir::{db::HirDatabase, ModuleDef, SourceBinder}; | 4 | use hir::{db::HirDatabase, ModuleDef, SourceBinder}; |
5 | use ra_assists::ImportsLocator; | ||
6 | use ra_prof::profile; | 5 | use ra_prof::profile; |
7 | use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; | 6 | use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; |
8 | 7 | ||
@@ -22,29 +21,7 @@ impl<'a> ImportsLocatorIde<'a> { | |||
22 | Self { source_binder: SourceBinder::new(db) } | 21 | Self { source_binder: SourceBinder::new(db) } |
23 | } | 22 | } |
24 | 23 | ||
25 | fn get_name_definition( | 24 | pub fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> { |
26 | &mut self, | ||
27 | db: &impl HirDatabase, | ||
28 | import_candidate: &FileSymbol, | ||
29 | ) -> Option<NameKind> { | ||
30 | let _p = profile("get_name_definition"); | ||
31 | let file_id = import_candidate.file_id.into(); | ||
32 | let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); | ||
33 | let candidate_name_node = if candidate_node.kind() != NAME { | ||
34 | candidate_node.children().find(|it| it.kind() == NAME)? | ||
35 | } else { | ||
36 | candidate_node | ||
37 | }; | ||
38 | classify_name( | ||
39 | &mut self.source_binder, | ||
40 | hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, | ||
41 | ) | ||
42 | .map(|it| it.kind) | ||
43 | } | ||
44 | } | ||
45 | |||
46 | impl ImportsLocator for ImportsLocatorIde<'_> { | ||
47 | fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> { | ||
48 | let _p = profile("search_for_imports"); | 25 | let _p = profile("search_for_imports"); |
49 | let db = self.source_binder.db; | 26 | let db = self.source_binder.db; |
50 | 27 | ||
@@ -72,4 +49,24 @@ impl ImportsLocator for ImportsLocatorIde<'_> { | |||
72 | }) | 49 | }) |
73 | .collect() | 50 | .collect() |
74 | } | 51 | } |
52 | |||
53 | fn get_name_definition( | ||
54 | &mut self, | ||
55 | db: &impl HirDatabase, | ||
56 | import_candidate: &FileSymbol, | ||
57 | ) -> Option<NameKind> { | ||
58 | let _p = profile("get_name_definition"); | ||
59 | let file_id = import_candidate.file_id.into(); | ||
60 | let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); | ||
61 | let candidate_name_node = if candidate_node.kind() != NAME { | ||
62 | candidate_node.children().find(|it| it.kind() == NAME)? | ||
63 | } else { | ||
64 | candidate_node | ||
65 | }; | ||
66 | classify_name( | ||
67 | &mut self.source_binder, | ||
68 | hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, | ||
69 | ) | ||
70 | .map(|it| it.kind) | ||
71 | } | ||
75 | } | 72 | } |