aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
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>(