diff options
author | Kirill Bulatov <[email protected]> | 2021-01-16 22:53:15 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-01-17 00:57:34 +0000 |
commit | 68626e4ef5acfea05812b68f41efa2bcd5bea448 (patch) | |
tree | 92ec1a8a69ce3058fd6da44f2f80f2460c9bda1d /crates/ide_db | |
parent | db335a1bbf1d1bea2c761f67efb4b49831738e31 (diff) |
Draft the working completion
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/helpers/import_assets.rs | 30 | ||||
-rw-r--r-- | crates/ide_db/src/imports_locator.rs | 16 |
2 files changed, 30 insertions, 16 deletions
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index e284220c1..a080b6ca7 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs | |||
@@ -5,7 +5,7 @@ use rustc_hash::FxHashSet; | |||
5 | use syntax::{ast, AstNode}; | 5 | use syntax::{ast, AstNode}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | imports_locator::{self, AssocItemSearch}, | 8 | imports_locator::{self, AssocItemSearch, DEFAULT_QUERY_SEARCH_LIMIT}, |
9 | RootDatabase, | 9 | RootDatabase, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -173,6 +173,7 @@ impl ImportAssets { | |||
173 | let current_crate = self.module_with_candidate.krate(); | 173 | let current_crate = self.module_with_candidate.krate(); |
174 | 174 | ||
175 | let filter = |candidate: Either<hir::ModuleDef, hir::MacroDef>| { | 175 | let filter = |candidate: Either<hir::ModuleDef, hir::MacroDef>| { |
176 | // TODO kb process all traits at once instead? | ||
176 | trait_candidates.clear(); | 177 | trait_candidates.clear(); |
177 | match &self.import_candidate { | 178 | match &self.import_candidate { |
178 | ImportCandidate::TraitAssocItem(trait_candidate) => { | 179 | ImportCandidate::TraitAssocItem(trait_candidate) => { |
@@ -191,6 +192,11 @@ impl ImportAssets { | |||
191 | None, | 192 | None, |
192 | |_, assoc| { | 193 | |_, assoc| { |
193 | if canidate_assoc_item == assoc { | 194 | if canidate_assoc_item == assoc { |
195 | if let AssocItem::Function(f) = assoc { | ||
196 | if f.self_param(db).is_some() { | ||
197 | return None; | ||
198 | } | ||
199 | } | ||
194 | Some(assoc_to_module_def(assoc)) | 200 | Some(assoc_to_module_def(assoc)) |
195 | } else { | 201 | } else { |
196 | None | 202 | None |
@@ -238,17 +244,21 @@ impl ImportAssets { | |||
238 | // see https://github.com/rust-analyzer/rust-analyzer/pull/7293#issuecomment-761585032 | 244 | // see https://github.com/rust-analyzer/rust-analyzer/pull/7293#issuecomment-761585032 |
239 | // and https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Blanket.20trait.20impls.20lookup | 245 | // and https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Blanket.20trait.20impls.20lookup |
240 | // for the details | 246 | // for the details |
241 | NameToImport::Fuzzy(fuzzy_name) => imports_locator::find_similar_imports( | 247 | NameToImport::Fuzzy(fuzzy_name) => { |
242 | sema, | 248 | let (assoc_item_search, limit) = match self.import_candidate { |
243 | current_crate, | ||
244 | fuzzy_name.clone(), | ||
245 | match self.import_candidate { | ||
246 | ImportCandidate::TraitAssocItem(_) | ImportCandidate::TraitMethod(_) => { | 249 | ImportCandidate::TraitAssocItem(_) | ImportCandidate::TraitMethod(_) => { |
247 | AssocItemSearch::AssocItemsOnly | 250 | (AssocItemSearch::AssocItemsOnly, None) |
248 | } | 251 | } |
249 | _ => AssocItemSearch::Exclude, | 252 | _ => (AssocItemSearch::Exclude, Some(DEFAULT_QUERY_SEARCH_LIMIT)), |
250 | }, | 253 | }; |
251 | ), | 254 | imports_locator::find_similar_imports( |
255 | sema, | ||
256 | current_crate, | ||
257 | fuzzy_name.clone(), | ||
258 | assoc_item_search, | ||
259 | limit, | ||
260 | ) | ||
261 | } | ||
252 | }; | 262 | }; |
253 | 263 | ||
254 | let mut res = unfiltered_imports | 264 | let mut res = unfiltered_imports |
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs index d69e65960..502e8281a 100644 --- a/crates/ide_db/src/imports_locator.rs +++ b/crates/ide_db/src/imports_locator.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
15 | use either::Either; | 15 | use either::Either; |
16 | use rustc_hash::FxHashSet; | 16 | use rustc_hash::FxHashSet; |
17 | 17 | ||
18 | const QUERY_SEARCH_LIMIT: usize = 40; | 18 | pub(crate) const DEFAULT_QUERY_SEARCH_LIMIT: usize = 40; |
19 | 19 | ||
20 | pub fn find_exact_imports<'a>( | 20 | pub fn find_exact_imports<'a>( |
21 | sema: &Semantics<'a, RootDatabase>, | 21 | sema: &Semantics<'a, RootDatabase>, |
@@ -29,11 +29,11 @@ pub fn find_exact_imports<'a>( | |||
29 | { | 29 | { |
30 | let mut local_query = symbol_index::Query::new(name_to_import.clone()); | 30 | let mut local_query = symbol_index::Query::new(name_to_import.clone()); |
31 | local_query.exact(); | 31 | local_query.exact(); |
32 | local_query.limit(QUERY_SEARCH_LIMIT); | 32 | local_query.limit(DEFAULT_QUERY_SEARCH_LIMIT); |
33 | local_query | 33 | local_query |
34 | }, | 34 | }, |
35 | import_map::Query::new(name_to_import) | 35 | import_map::Query::new(name_to_import) |
36 | .limit(QUERY_SEARCH_LIMIT) | 36 | .limit(DEFAULT_QUERY_SEARCH_LIMIT) |
37 | .name_only() | 37 | .name_only() |
38 | .search_mode(import_map::SearchMode::Equals) | 38 | .search_mode(import_map::SearchMode::Equals) |
39 | .case_sensitive(), | 39 | .case_sensitive(), |
@@ -51,13 +51,13 @@ pub fn find_similar_imports<'a>( | |||
51 | krate: Crate, | 51 | krate: Crate, |
52 | fuzzy_search_string: String, | 52 | fuzzy_search_string: String, |
53 | assoc_item_search: AssocItemSearch, | 53 | assoc_item_search: AssocItemSearch, |
54 | limit: Option<usize>, | ||
54 | ) -> Box<dyn Iterator<Item = Either<ModuleDef, MacroDef>> + 'a> { | 55 | ) -> Box<dyn Iterator<Item = Either<ModuleDef, MacroDef>> + 'a> { |
55 | let _p = profile::span("find_similar_imports"); | 56 | let _p = profile::span("find_similar_imports"); |
56 | 57 | ||
57 | let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) | 58 | let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) |
58 | .search_mode(import_map::SearchMode::Fuzzy) | 59 | .search_mode(import_map::SearchMode::Fuzzy) |
59 | .name_only() | 60 | .name_only(); |
60 | .limit(QUERY_SEARCH_LIMIT); | ||
61 | 61 | ||
62 | match assoc_item_search { | 62 | match assoc_item_search { |
63 | AssocItemSearch::Include => {} | 63 | AssocItemSearch::Include => {} |
@@ -70,7 +70,11 @@ pub fn find_similar_imports<'a>( | |||
70 | } | 70 | } |
71 | 71 | ||
72 | let mut local_query = symbol_index::Query::new(fuzzy_search_string); | 72 | let mut local_query = symbol_index::Query::new(fuzzy_search_string); |
73 | local_query.limit(QUERY_SEARCH_LIMIT); | 73 | |
74 | if let Some(limit) = limit { | ||
75 | external_query = external_query.limit(limit); | ||
76 | local_query.limit(limit); | ||
77 | } | ||
74 | 78 | ||
75 | let db = sema.db; | 79 | let db = sema.db; |
76 | Box::new(find_imports(sema, krate, local_query, external_query).filter( | 80 | Box::new(find_imports(sema, krate, local_query, external_query).filter( |