aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-01-04 16:33:05 +0000
committerKirill Bulatov <[email protected]>2021-01-04 16:33:05 +0000
commitca42a52051e69d441b3f32ba4268286a8f0d8685 (patch)
tree217c9b610f657a3b60833c4e7b1c0bbf5c29d122 /crates/ide_db/src
parented1ef3ae13a8f7bc2144bd06d0271d9a6e3205a0 (diff)
Code review fixes
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/imports_locator.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index 0f4c2ca47..0782ab070 100644
--- a/crates/ide_db/src/imports_locator.rs
+++ b/crates/ide_db/src/imports_locator.rs
@@ -1,7 +1,7 @@
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::{import_map, Crate, MacroDef, ModuleDef, Semantics}; 4use hir::{import_map, AsAssocItem, Crate, MacroDef, ModuleDef, Semantics};
5use syntax::{ast, AstNode, SyntaxKind::NAME}; 5use syntax::{ast, AstNode, SyntaxKind::NAME};
6 6
7use crate::{ 7use crate::{
@@ -40,8 +40,9 @@ pub fn find_similar_imports<'a>(
40 krate: Crate, 40 krate: Crate,
41 limit: Option<usize>, 41 limit: Option<usize>,
42 fuzzy_search_string: String, 42 fuzzy_search_string: String,
43 ignore_assoc_items: bool,
43 name_only: bool, 44 name_only: bool,
44) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { 45) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> + 'a {
45 let _p = profile::span("find_similar_imports"); 46 let _p = profile::span("find_similar_imports");
46 47
47 let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) 48 let mut external_query = import_map::Query::new(fuzzy_search_string.clone())
@@ -57,7 +58,21 @@ pub fn find_similar_imports<'a>(
57 external_query = external_query.limit(limit); 58 external_query = external_query.limit(limit);
58 } 59 }
59 60
60 find_imports(sema, krate, local_query, external_query) 61 let db = sema.db;
62 find_imports(sema, krate, local_query, external_query).filter(move |import_candidate| {
63 if ignore_assoc_items {
64 match import_candidate {
65 Either::Left(ModuleDef::Function(function)) => function.as_assoc_item(db).is_none(),
66 Either::Left(ModuleDef::Const(const_)) => const_.as_assoc_item(db).is_none(),
67 Either::Left(ModuleDef::TypeAlias(type_alias)) => {
68 type_alias.as_assoc_item(db).is_none()
69 }
70 _ => true,
71 }
72 } else {
73 true
74 }
75 })
61} 76}
62 77
63fn find_imports<'a>( 78fn find_imports<'a>(