From 944f28fe5bf2b8e4316cc67bf5f824333fc4f180 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 13:34:56 +0200 Subject: Use more generic public api --- crates/ra_ide_db/Cargo.toml | 1 + crates/ra_ide_db/src/imports_locator.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_db') diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml index de4f5bce0..c3921bd40 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ra_ide_db/Cargo.toml @@ -17,6 +17,7 @@ fst = { version = "0.4", default-features = false } rustc-hash = "1.1.0" superslice = "1.0.0" once_cell = "1.3.1" +either = "1.5.3" ra_syntax = { path = "../ra_syntax" } ra_text_edit = { path = "../ra_text_edit" } diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index 24b6e4ad0..bf0d8db60 100644 --- a/crates/ra_ide_db/src/imports_locator.rs +++ b/crates/ra_ide_db/src/imports_locator.rs @@ -1,7 +1,7 @@ //! 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::Semantics; +use hir::{MacroDef, ModuleDef, Semantics}; use ra_prof::profile; use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; @@ -10,6 +10,7 @@ use crate::{ symbol_index::{self, FileSymbol, Query}, RootDatabase, }; +use either::Either; pub struct ImportsLocator<'a> { sema: Semantics<'a, RootDatabase>, @@ -20,7 +21,7 @@ impl<'a> ImportsLocator<'a> { Self { sema: Semantics::new(db) } } - pub fn find_imports(&mut self, name_to_import: &str) -> Vec { + pub fn find_imports(&mut self, name_to_import: &str) -> Vec> { let _p = profile("search_for_imports"); let db = self.sema.db; @@ -42,6 +43,11 @@ impl<'a> ImportsLocator<'a> { .into_iter() .chain(lib_results.into_iter()) .filter_map(|import_candidate| self.get_name_definition(&import_candidate)) + .filter_map(|name_definition_to_import| match name_definition_to_import { + Definition::ModuleDef(module_def) => Some(Either::Left(module_def)), + Definition::Macro(macro_def) => Some(Either::Right(macro_def)), + _ => None, + }) .collect() } -- cgit v1.2.3