aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-06 15:26:43 +0000
committerAleksey Kladov <[email protected]>2020-02-06 15:26:43 +0000
commitdfbe96750b69fc69e64f3a6094e2c1d574ab42fa (patch)
tree696f118a3555b446f930becee802574e344d1afc /crates/ra_ide/src
parentec23030e16bdf3a020ca0b5839ed100b707ff744 (diff)
Move imports locator to ide_db
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/assists.rs4
-rw-r--r--crates/ra_ide/src/imports_locator.rs75
-rw-r--r--crates/ra_ide/src/lib.rs1
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 @@
3use either::Either; 3use either::Either;
4use ra_assists::{AssistAction, AssistLabel}; 4use ra_assists::{AssistAction, AssistLabel};
5use ra_db::{FilePosition, FileRange}; 5use ra_db::{FilePosition, FileRange};
6use ra_ide_db::RootDatabase; 6use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase};
7 7
8use crate::{imports_locator::ImportsLocatorIde, FileId, SourceChange, SourceFileEdit}; 8use crate::{FileId, SourceChange, SourceFileEdit};
9 9
10pub use ra_assists::AssistId; 10pub 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
4use hir::{db::HirDatabase, ModuleDef, SourceBinder};
5use ra_assists::ImportsLocator;
6use ra_ide_db::{
7 defs::NameKind,
8 symbol_index::{self, FileSymbol},
9 RootDatabase,
10};
11use ra_prof::profile;
12use ra_syntax::{ast, AstNode, SyntaxKind::NAME};
13
14use crate::{references::classify_name, Query};
15
16pub(crate) struct ImportsLocatorIde<'a> {
17 source_binder: SourceBinder<'a, RootDatabase>,
18}
19
20impl<'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
46impl 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;
26mod parent_module; 26mod parent_module;
27mod references; 27mod references;
28mod impls; 28mod impls;
29mod imports_locator;
30mod assists; 29mod assists;
31mod diagnostics; 30mod diagnostics;
32mod syntax_tree; 31mod syntax_tree;