From ca42a52051e69d441b3f32ba4268286a8f0d8685 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 4 Jan 2021 18:33:05 +0200 Subject: Code review fixes --- crates/ide_db/src/imports_locator.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'crates/ide_db/src') 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 @@ //! This module contains an import search funcionality that is provided to the assists module. //! Later, this should be moved away to a separate crate that is accessible from the assists module. -use hir::{import_map, Crate, MacroDef, ModuleDef, Semantics}; +use hir::{import_map, AsAssocItem, Crate, MacroDef, ModuleDef, Semantics}; use syntax::{ast, AstNode, SyntaxKind::NAME}; use crate::{ @@ -40,8 +40,9 @@ pub fn find_similar_imports<'a>( krate: Crate, limit: Option, fuzzy_search_string: String, + ignore_assoc_items: bool, name_only: bool, -) -> impl Iterator> { +) -> impl Iterator> + 'a { let _p = profile::span("find_similar_imports"); let mut external_query = import_map::Query::new(fuzzy_search_string.clone()) @@ -57,7 +58,21 @@ pub fn find_similar_imports<'a>( external_query = external_query.limit(limit); } - find_imports(sema, krate, local_query, external_query) + let db = sema.db; + find_imports(sema, krate, local_query, external_query).filter(move |import_candidate| { + if ignore_assoc_items { + match import_candidate { + Either::Left(ModuleDef::Function(function)) => function.as_assoc_item(db).is_none(), + Either::Left(ModuleDef::Const(const_)) => const_.as_assoc_item(db).is_none(), + Either::Left(ModuleDef::TypeAlias(type_alias)) => { + type_alias.as_assoc_item(db).is_none() + } + _ => true, + } + } else { + true + } + }) } fn find_imports<'a>( -- cgit v1.2.3