From 4f27155d5cf6b12ed0df6f7dd430dcddda9e41d2 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 3 Feb 2020 13:56:03 +0200 Subject: Simplify paths searches --- crates/ra_assists/src/assists/auto_import.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists/src/assists') diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 7fd1f0e7d..e908ab1fc 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs @@ -1,7 +1,6 @@ use hir::{db::HirDatabase, ModPath}; use ra_syntax::{ ast::{self, AstNode}, - SyntaxKind::{NAME_REF, USE_ITEM}, SyntaxNode, }; @@ -33,11 +32,11 @@ pub(crate) fn auto_import( ) -> Option { let path_to_import: ast::Path = ctx.find_node_at_offset()?; let path_to_import_syntax = path_to_import.syntax(); - if path_to_import_syntax.ancestors().find(|ancestor| ancestor.kind() == USE_ITEM).is_some() { + if path_to_import_syntax.ancestors().find_map(ast::UseItem::cast).is_some() { return None; } let name_to_import = - path_to_import_syntax.descendants().find(|child| child.kind() == NAME_REF)?; + path_to_import_syntax.descendants().find_map(ast::NameRef::cast)?.syntax().to_string(); let module = path_to_import_syntax.ancestors().find_map(ast::Module::cast); let position = match module.and_then(|it| it.item_list()) { @@ -54,7 +53,7 @@ pub(crate) fn auto_import( } let proposed_imports = imports_locator - .find_imports(&name_to_import.to_string()) + .find_imports(&name_to_import) .into_iter() .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def)) .filter(|use_path| !use_path.segments.is_empty()) -- cgit v1.2.3