aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-11-13 17:16:56 +0000
committerKirill Bulatov <[email protected]>2020-11-16 19:19:06 +0000
commit4c8edd003aa447bd2da10fd81b24f582deacdc11 (patch)
tree6b7b97ba769e7b1c7de4feebfdcd06173bf52853 /crates/ide_db/src
parentd1556550f83b7b8e9dd42c80ab6e08a632dfd256 (diff)
Use imports_locator
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/imports_locator.rs65
1 files changed, 47 insertions, 18 deletions
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index e4f4b5427..71fb7207b 100644
--- a/crates/ide_db/src/imports_locator.rs
+++ b/crates/ide_db/src/imports_locator.rs
@@ -1,40 +1,69 @@
1//! This module contains an import search funcionality that is provided to the assists module. 1//! This module contains an import search funcionality that is provided to the assists module.
2//! Later, this should be moved away to a separate crate that is accessible from the assists module. 2//! Later, this should be moved away to a separate crate that is accessible from the assists module.
3 3
4use hir::{Crate, MacroDef, ModuleDef, Query as ImportMapQuery, Semantics}; 4use hir::{Crate, ExternalImportablesQuery, MacroDef, ModuleDef, Semantics};
5use syntax::{ast, AstNode, SyntaxKind::NAME}; 5use syntax::{ast, AstNode, SyntaxKind::NAME};
6 6
7use crate::{ 7use crate::{
8 defs::{Definition, NameClass}, 8 defs::{Definition, NameClass},
9 symbol_index::{self, FileSymbol, Query as SymbolQuery}, 9 symbol_index::{self, FileSymbol, Query as LocalImportablesQuery},
10 RootDatabase, 10 RootDatabase,
11}; 11};
12use either::Either; 12use either::Either;
13use rustc_hash::FxHashSet; 13use rustc_hash::FxHashSet;
14 14
15pub fn find_imports<'a>( 15pub fn find_exact_imports<'a>(
16 sema: &Semantics<'a, RootDatabase>, 16 sema: &Semantics<'a, RootDatabase>,
17 krate: Crate, 17 krate: Crate,
18 name_to_import: &str, 18 name_to_import: &str,
19) -> Vec<Either<ModuleDef, MacroDef>> { 19) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
20 let _p = profile::span("search_for_imports"); 20 let _p = profile::span("find_exact_imports");
21 find_imports(
22 sema,
23 krate,
24 {
25 let mut local_query = LocalImportablesQuery::new(name_to_import.to_string());
26 local_query.exact();
27 local_query.limit(40);
28 local_query
29 },
30 ExternalImportablesQuery::new(name_to_import).anchor_end().case_sensitive().limit(40),
31 )
32}
33
34pub fn find_similar_imports<'a>(
35 sema: &Semantics<'a, RootDatabase>,
36 krate: Crate,
37 name_to_import: &str,
38) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
39 let _p = profile::span("find_similar_imports");
40 find_imports(
41 sema,
42 krate,
43 {
44 let mut local_query = LocalImportablesQuery::new(name_to_import.to_string());
45 local_query.limit(40);
46 local_query
47 },
48 ExternalImportablesQuery::new(name_to_import).limit(40),
49 )
50}
51
52fn find_imports<'a>(
53 sema: &Semantics<'a, RootDatabase>,
54 krate: Crate,
55 local_query: LocalImportablesQuery,
56 external_query: ExternalImportablesQuery,
57) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
58 let _p = profile::span("find_similar_imports");
21 let db = sema.db; 59 let db = sema.db;
22 60
23 // Query dependencies first. 61 // Query dependencies first.
24 let mut candidates: FxHashSet<_> = krate 62 let mut candidates: FxHashSet<_> =
25 .query_external_importables( 63 krate.query_external_importables(db, external_query).collect();
26 db,
27 ImportMapQuery::new(name_to_import).anchor_end().case_sensitive().limit(40),
28 )
29 .collect();
30 64
31 // Query the local crate using the symbol index. 65 // Query the local crate using the symbol index.
32 let local_results = { 66 let local_results = symbol_index::crate_symbols(db, krate.into(), local_query);
33 let mut query = SymbolQuery::new(name_to_import.to_string());
34 query.exact();
35 query.limit(40);
36 symbol_index::crate_symbols(db, krate.into(), query)
37 };
38 67
39 candidates.extend( 68 candidates.extend(
40 local_results 69 local_results
@@ -47,7 +76,7 @@ pub fn find_imports<'a>(
47 }), 76 }),
48 ); 77 );
49 78
50 candidates.into_iter().collect() 79 candidates.into_iter()
51} 80}
52 81
53fn get_name_definition<'a>( 82fn get_name_definition<'a>(