diff options
author | Aleksey Kladov <[email protected]> | 2020-02-06 15:26:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-06 15:26:43 +0000 |
commit | dfbe96750b69fc69e64f3a6094e2c1d574ab42fa (patch) | |
tree | 696f118a3555b446f930becee802574e344d1afc /crates/ra_ide/src | |
parent | ec23030e16bdf3a020ca0b5839ed100b707ff744 (diff) |
Move imports locator to ide_db
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/assists.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/imports_locator.rs | 75 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 1 |
3 files changed, 2 insertions, 78 deletions
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index f26047570..4a7d8cfa9 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs | |||
@@ -3,9 +3,9 @@ | |||
3 | use either::Either; | 3 | use either::Either; |
4 | use ra_assists::{AssistAction, AssistLabel}; | 4 | use ra_assists::{AssistAction, AssistLabel}; |
5 | use ra_db::{FilePosition, FileRange}; | 5 | use ra_db::{FilePosition, FileRange}; |
6 | use ra_ide_db::RootDatabase; | 6 | use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase}; |
7 | 7 | ||
8 | use crate::{imports_locator::ImportsLocatorIde, FileId, SourceChange, SourceFileEdit}; | 8 | use crate::{FileId, SourceChange, SourceFileEdit}; |
9 | 9 | ||
10 | pub use ra_assists::AssistId; | 10 | pub use ra_assists::AssistId; |
11 | 11 | ||
diff --git a/crates/ra_ide/src/imports_locator.rs b/crates/ra_ide/src/imports_locator.rs deleted file mode 100644 index 0dca0c86c..000000000 --- a/crates/ra_ide/src/imports_locator.rs +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | //! This module contains an import search funcionality that is provided to the ra_assists module. | ||
2 | //! Later, this should be moved away to a separate crate that is accessible from the ra_assists module. | ||
3 | |||
4 | use hir::{db::HirDatabase, ModuleDef, SourceBinder}; | ||
5 | use ra_assists::ImportsLocator; | ||
6 | use ra_ide_db::{ | ||
7 | defs::NameKind, | ||
8 | symbol_index::{self, FileSymbol}, | ||
9 | RootDatabase, | ||
10 | }; | ||
11 | use ra_prof::profile; | ||
12 | use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; | ||
13 | |||
14 | use crate::{references::classify_name, Query}; | ||
15 | |||
16 | pub(crate) struct ImportsLocatorIde<'a> { | ||
17 | source_binder: SourceBinder<'a, RootDatabase>, | ||
18 | } | ||
19 | |||
20 | impl<'a> ImportsLocatorIde<'a> { | ||
21 | pub(crate) fn new(db: &'a RootDatabase) -> Self { | ||
22 | Self { source_binder: SourceBinder::new(db) } | ||
23 | } | ||
24 | |||
25 | fn get_name_definition( | ||
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"); | ||
49 | let db = self.source_binder.db; | ||
50 | |||
51 | let project_results = { | ||
52 | let mut query = Query::new(name_to_import.to_string()); | ||
53 | query.exact(); | ||
54 | query.limit(40); | ||
55 | symbol_index::world_symbols(db, query) | ||
56 | }; | ||
57 | let lib_results = { | ||
58 | let mut query = Query::new(name_to_import.to_string()); | ||
59 | query.libs(); | ||
60 | query.exact(); | ||
61 | query.limit(40); | ||
62 | symbol_index::world_symbols(db, query) | ||
63 | }; | ||
64 | |||
65 | project_results | ||
66 | .into_iter() | ||
67 | .chain(lib_results.into_iter()) | ||
68 | .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) | ||
69 | .filter_map(|name_definition_to_import| match name_definition_to_import { | ||
70 | NameKind::Def(module_def) => Some(module_def), | ||
71 | _ => None, | ||
72 | }) | ||
73 | .collect() | ||
74 | } | ||
75 | } | ||
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 5fb111a90..689921f3f 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -26,7 +26,6 @@ mod syntax_highlighting; | |||
26 | mod parent_module; | 26 | mod parent_module; |
27 | mod references; | 27 | mod references; |
28 | mod impls; | 28 | mod impls; |
29 | mod imports_locator; | ||
30 | mod assists; | 29 | mod assists; |
31 | mod diagnostics; | 30 | mod diagnostics; |
32 | mod syntax_tree; | 31 | mod syntax_tree; |