From dfbe96750b69fc69e64f3a6094e2c1d574ab42fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:26:43 +0100 Subject: Move imports locator to ide_db --- crates/ra_ide/src/assists.rs | 4 +- crates/ra_ide/src/imports_locator.rs | 75 ------------------------------------ crates/ra_ide/src/lib.rs | 1 - 3 files changed, 2 insertions(+), 78 deletions(-) delete mode 100644 crates/ra_ide/src/imports_locator.rs (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index f26047570..4a7d8cfa9 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs @@ -3,9 +3,9 @@ use either::Either; use ra_assists::{AssistAction, AssistLabel}; use ra_db::{FilePosition, FileRange}; -use ra_ide_db::RootDatabase; +use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase}; -use crate::{imports_locator::ImportsLocatorIde, FileId, SourceChange, SourceFileEdit}; +use crate::{FileId, SourceChange, SourceFileEdit}; pub use ra_assists::AssistId; diff --git a/crates/ra_ide/src/imports_locator.rs b/crates/ra_ide/src/imports_locator.rs deleted file mode 100644 index 0dca0c86c..000000000 --- a/crates/ra_ide/src/imports_locator.rs +++ /dev/null @@ -1,75 +0,0 @@ -//! This module contains an import search funcionality that is provided to the ra_assists module. -//! Later, this should be moved away to a separate crate that is accessible from the ra_assists module. - -use hir::{db::HirDatabase, ModuleDef, SourceBinder}; -use ra_assists::ImportsLocator; -use ra_ide_db::{ - defs::NameKind, - symbol_index::{self, FileSymbol}, - RootDatabase, -}; -use ra_prof::profile; -use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; - -use crate::{references::classify_name, Query}; - -pub(crate) struct ImportsLocatorIde<'a> { - source_binder: SourceBinder<'a, RootDatabase>, -} - -impl<'a> ImportsLocatorIde<'a> { - pub(crate) fn new(db: &'a RootDatabase) -> Self { - Self { source_binder: SourceBinder::new(db) } - } - - fn get_name_definition( - &mut self, - db: &impl HirDatabase, - import_candidate: &FileSymbol, - ) -> Option { - let _p = profile("get_name_definition"); - let file_id = import_candidate.file_id.into(); - let candidate_node = import_candidate.ptr.to_node(&db.parse_or_expand(file_id)?); - let candidate_name_node = if candidate_node.kind() != NAME { - candidate_node.children().find(|it| it.kind() == NAME)? - } else { - candidate_node - }; - classify_name( - &mut self.source_binder, - hir::InFile { file_id, value: &ast::Name::cast(candidate_name_node)? }, - ) - .map(|it| it.kind) - } -} - -impl ImportsLocator for ImportsLocatorIde<'_> { - fn find_imports(&mut self, name_to_import: &str) -> Vec { - let _p = profile("search_for_imports"); - let db = self.source_binder.db; - - let project_results = { - let mut query = Query::new(name_to_import.to_string()); - query.exact(); - query.limit(40); - symbol_index::world_symbols(db, query) - }; - let lib_results = { - let mut query = Query::new(name_to_import.to_string()); - query.libs(); - query.exact(); - query.limit(40); - symbol_index::world_symbols(db, query) - }; - - project_results - .into_iter() - .chain(lib_results.into_iter()) - .filter_map(|import_candidate| self.get_name_definition(db, &import_candidate)) - .filter_map(|name_definition_to_import| match name_definition_to_import { - NameKind::Def(module_def) => Some(module_def), - _ => None, - }) - .collect() - } -} diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 5fb111a90..689921f3f 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -26,7 +26,6 @@ mod syntax_highlighting; mod parent_module; mod references; mod impls; -mod imports_locator; mod assists; mod diagnostics; mod syntax_tree; -- cgit v1.2.3