diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/apply_change.rs | 4 | ||||
-rw-r--r-- | crates/ide_db/src/imports_locator.rs | 67 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 2 |
3 files changed, 57 insertions, 16 deletions
diff --git a/crates/ide_db/src/apply_change.rs b/crates/ide_db/src/apply_change.rs index da16fa21d..987191fe3 100644 --- a/crates/ide_db/src/apply_change.rs +++ b/crates/ide_db/src/apply_change.rs | |||
@@ -76,7 +76,7 @@ impl RootDatabase { | |||
76 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); | 76 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); |
77 | 77 | ||
78 | base_db::ParseQuery.in_db(self).sweep(sweep); | 78 | base_db::ParseQuery.in_db(self).sweep(sweep); |
79 | hir::db::ParseMacroQuery.in_db(self).sweep(sweep); | 79 | hir::db::ParseMacroExpansionQuery.in_db(self).sweep(sweep); |
80 | 80 | ||
81 | // Macros do take significant space, but less then the syntax trees | 81 | // Macros do take significant space, but less then the syntax trees |
82 | // self.query(hir::db::MacroDefQuery).sweep(sweep); | 82 | // self.query(hir::db::MacroDefQuery).sweep(sweep); |
@@ -143,7 +143,7 @@ impl RootDatabase { | |||
143 | hir::db::AstIdMapQuery | 143 | hir::db::AstIdMapQuery |
144 | hir::db::MacroArgTextQuery | 144 | hir::db::MacroArgTextQuery |
145 | hir::db::MacroDefQuery | 145 | hir::db::MacroDefQuery |
146 | hir::db::ParseMacroQuery | 146 | hir::db::ParseMacroExpansionQuery |
147 | hir::db::MacroExpandQuery | 147 | hir::db::MacroExpandQuery |
148 | 148 | ||
149 | // DefDatabase | 149 | // DefDatabase |
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index df74be00b..09046d3c3 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs | |||
@@ -1,36 +1,77 @@ | |||
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 | ||
4 | use hir::{Crate, MacroDef, ModuleDef, Semantics}; | 4 | use hir::{import_map, Crate, MacroDef, ModuleDef, Semantics}; |
5 | use syntax::{ast, AstNode, SyntaxKind::NAME}; | 5 | use syntax::{ast, AstNode, SyntaxKind::NAME}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | defs::{Definition, NameClass}, | 8 | defs::{Definition, NameClass}, |
9 | symbol_index::{self, FileSymbol, Query}, | 9 | symbol_index::{self, FileSymbol}, |
10 | RootDatabase, | 10 | RootDatabase, |
11 | }; | 11 | }; |
12 | use either::Either; | 12 | use either::Either; |
13 | use rustc_hash::FxHashSet; | 13 | use rustc_hash::FxHashSet; |
14 | 14 | ||
15 | pub fn find_imports<'a>( | 15 | pub 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 = symbol_index::Query::new(name_to_import.to_string()); | ||
26 | local_query.exact(); | ||
27 | local_query.limit(40); | ||
28 | local_query | ||
29 | }, | ||
30 | import_map::Query::new(name_to_import).anchor_end().case_sensitive().limit(40), | ||
31 | ) | ||
32 | } | ||
33 | |||
34 | pub fn find_similar_imports<'a>( | ||
35 | sema: &Semantics<'a, RootDatabase>, | ||
36 | krate: Crate, | ||
37 | name_to_import: &str, | ||
38 | limit: usize, | ||
39 | ignore_modules: bool, | ||
40 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | ||
41 | let _p = profile::span("find_similar_imports"); | ||
42 | |||
43 | let mut external_query = import_map::Query::new(name_to_import).limit(limit); | ||
44 | if ignore_modules { | ||
45 | external_query = external_query.exclude_import_kind(import_map::ImportKind::Module); | ||
46 | } | ||
47 | |||
48 | find_imports( | ||
49 | sema, | ||
50 | krate, | ||
51 | { | ||
52 | let mut local_query = symbol_index::Query::new(name_to_import.to_string()); | ||
53 | local_query.limit(limit); | ||
54 | local_query | ||
55 | }, | ||
56 | external_query, | ||
57 | ) | ||
58 | } | ||
59 | |||
60 | fn find_imports<'a>( | ||
61 | sema: &Semantics<'a, RootDatabase>, | ||
62 | krate: Crate, | ||
63 | local_query: symbol_index::Query, | ||
64 | external_query: import_map::Query, | ||
65 | ) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { | ||
66 | let _p = profile::span("find_similar_imports"); | ||
21 | let db = sema.db; | 67 | let db = sema.db; |
22 | 68 | ||
23 | // Query dependencies first. | 69 | // Query dependencies first. |
24 | let mut candidates: FxHashSet<_> = | 70 | let mut candidates: FxHashSet<_> = |
25 | krate.query_external_importables(db, name_to_import).collect(); | 71 | krate.query_external_importables(db, external_query).collect(); |
26 | 72 | ||
27 | // Query the local crate using the symbol index. | 73 | // Query the local crate using the symbol index. |
28 | let local_results = { | 74 | let local_results = symbol_index::crate_symbols(db, krate.into(), local_query); |
29 | let mut query = Query::new(name_to_import.to_string()); | ||
30 | query.exact(); | ||
31 | query.limit(40); | ||
32 | symbol_index::crate_symbols(db, krate.into(), query) | ||
33 | }; | ||
34 | 75 | ||
35 | candidates.extend( | 76 | candidates.extend( |
36 | local_results | 77 | local_results |
@@ -43,7 +84,7 @@ pub fn find_imports<'a>( | |||
43 | }), | 84 | }), |
44 | ); | 85 | ); |
45 | 86 | ||
46 | candidates.into_iter().collect() | 87 | candidates.into_iter() |
47 | } | 88 | } |
48 | 89 | ||
49 | fn get_name_definition<'a>( | 90 | fn get_name_definition<'a>( |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 38ebdbf79..05139a651 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -113,7 +113,7 @@ impl RootDatabase { | |||
113 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 113 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
114 | let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP); | 114 | let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP); |
115 | base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); | 115 | base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
116 | hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity); | 116 | hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
117 | hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); | 117 | hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity); |
118 | } | 118 | } |
119 | } | 119 | } |