From fcf5bbbbeb1ab48e80d45483c810bae708f848a1 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 3 Feb 2020 13:35:14 +0200 Subject: Fix inlay hints test snippet compilation --- crates/ra_ide/src/inlay_hints.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 393ca9447..de447a5aa 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -376,7 +376,7 @@ fn main() { let mut start = 0; (0..2).for_each(|increment| { start += increment; - }) + }); let multiply = |a, b, c, d| a * b * c * d; let _: i32 = multiply(1, 2, 3, 4); @@ -399,37 +399,37 @@ fn main() { label: "i32", }, InlayHint { - range: [114; 122), + range: [115; 123), kind: TypeHint, label: "|…| -> i32", }, InlayHint { - range: [126; 127), + range: [127; 128), kind: TypeHint, label: "i32", }, InlayHint { - range: [129; 130), + range: [130; 131), kind: TypeHint, label: "i32", }, InlayHint { - range: [132; 133), + range: [133; 134), kind: TypeHint, label: "i32", }, InlayHint { - range: [135; 136), + range: [136; 137), kind: TypeHint, label: "i32", }, InlayHint { - range: [200; 212), + range: [201; 213), kind: TypeHint, label: "&|…| -> i32", }, InlayHint { - range: [235; 244), + range: [236; 245), kind: TypeHint, label: "|| -> i32", }, -- cgit v1.2.3 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') 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