From d221ff4f9e0e270939a2944a2471bc3f027a674b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 00:19:55 +0200 Subject: Auto import macros --- crates/ra_assists/src/ast_transform.rs | 2 +- crates/ra_assists/src/handlers/auto_import.rs | 34 ++++++++++++++--------- crates/ra_assists/src/handlers/fill_match_arms.rs | 5 ++-- crates/ra_hir/src/code_model.rs | 31 +++++++++++++-------- crates/ra_ide_db/src/imports_locator.rs | 8 ++---- 5 files changed, 46 insertions(+), 34 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 45558c448..34c816f16 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -129,7 +129,7 @@ impl<'a> QualifyPaths<'a> { let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; match resolution { PathResolution::Def(def) => { - let found_path = from.find_use_path(self.source_scope.db, def)?; + let found_path = from.find_use_path(self.source_scope.db, def.into())?; let mut path = path_to_ast(found_path); let type_args = p diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index bb280f633..49d8c4c3d 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -4,7 +4,7 @@ use hir::{ AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait, Type, }; -use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase}; +use ra_ide_db::{defs::Definition, imports_locator::ImportsLocator, RootDatabase}; use ra_prof::profile; use ra_syntax::{ ast::{self, AstNode}, @@ -127,14 +127,16 @@ impl AutoImportAssets { ImportsLocator::new(db) .find_imports(&self.get_search_query()) .into_iter() - .filter_map(|module_def| match &self.import_candidate { + .filter_map(|definition| match &self.import_candidate { ImportCandidate::TraitAssocItem(assoc_item_type, _) => { - let located_assoc_item = match module_def { - ModuleDef::Function(located_function) => located_function - .as_assoc_item(db) - .map(|assoc| assoc.container(db)) - .and_then(Self::assoc_to_trait), - ModuleDef::Const(located_const) => located_const + let located_assoc_item = match definition { + Definition::ModuleDef(ModuleDef::Function(located_function)) => { + located_function + .as_assoc_item(db) + .map(|assoc| assoc.container(db)) + .and_then(Self::assoc_to_trait) + } + Definition::ModuleDef(ModuleDef::Const(located_const)) => located_const .as_assoc_item(db) .map(|assoc| assoc.container(db)) .and_then(Self::assoc_to_trait), @@ -152,11 +154,13 @@ impl AutoImportAssets { None, |_, assoc| Self::assoc_to_trait(assoc.container(db)), ) - .map(ModuleDef::from) + .map(|located_trait| ModuleDef::from(located_trait).into()) } ImportCandidate::TraitMethod(function_callee, _) => { let located_assoc_item = - if let ModuleDef::Function(located_function) = module_def { + if let Definition::ModuleDef(ModuleDef::Function(located_function)) = + definition + { located_function .as_assoc_item(db) .map(|assoc| assoc.container(db)) @@ -178,11 +182,15 @@ impl AutoImportAssets { Self::assoc_to_trait(function.as_assoc_item(db)?.container(db)) }, ) - .map(ModuleDef::from) + .map(|located_trait| ModuleDef::from(located_trait).into()) } - _ => Some(module_def), + _ => match definition { + Definition::ModuleDef(module_def) => Some(module_def.into()), + Definition::Macro(macro_def) => Some(macro_def.into()), + _ => None, + }, }) - .filter_map(|module_def| self.module_with_name_to_import.find_use_path(db, module_def)) + .filter_map(|item| self.module_with_name_to_import.find_use_path(db, item)) .filter(|use_path| !use_path.segments.is_empty()) .take(20) .collect::>() diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 7463b2af7..869942b12 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -2,7 +2,7 @@ use std::iter; -use hir::{Adt, HasSource, Semantics}; +use hir::{Adt, HasSource, ModuleDef, Semantics}; use itertools::Itertools; use ra_ide_db::RootDatabase; @@ -154,7 +154,8 @@ fn resolve_tuple_of_enum_def( } fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option { - let path = crate::ast_transform::path_to_ast(module.find_use_path(db, var.into())?); + let path = + crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var).into())?); // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though let pat: ast::Pat = match var.source(db).value.kind() { diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index e91abf6f5..146e7820e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -139,6 +139,17 @@ impl ModuleDef { } } +impl From for ItemInNs { + fn from(module_def: ModuleDef) -> Self { + match module_def { + ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { + ItemInNs::Values(module_def.into()) + } + _ => ItemInNs::Types(module_def.into()), + } + } +} + pub use hir_def::{ attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, }; @@ -275,19 +286,9 @@ impl Module { pub fn find_use_path( self, db: &dyn HirDatabase, - item: ModuleDef, + item: ItemInNs, ) -> Option { - // FIXME expose namespace choice - hir_def::find_path::find_path(db.upcast(), determine_item_namespace(item), self.into()) - } -} - -fn determine_item_namespace(module_def: ModuleDef) -> ItemInNs { - match module_def { - ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { - ItemInNs::Values(module_def.into()) - } - _ => ItemInNs::Types(module_def.into()), + hir_def::find_path::find_path(db.upcast(), item, self.into()) } } @@ -759,6 +760,12 @@ impl MacroDef { } } +impl From for ItemInNs { + fn from(macro_def: MacroDef) -> Self { + ItemInNs::Macros(macro_def.into()) + } +} + /// Invariant: `inner.as_assoc_item(db).is_some()` /// We do not actively enforce this invariant. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ra_ide_db/src/imports_locator.rs index c96351982..24b6e4ad0 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::{ModuleDef, Semantics}; +use hir::Semantics; use ra_prof::profile; use ra_syntax::{ast, AstNode, SyntaxKind::NAME}; @@ -20,7 +20,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,10 +42,6 @@ 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(module_def), - _ => None, - }) .collect() } -- cgit v1.2.3 From d5e11b33a36755b139367e1f91a52f5ec27193f6 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 09:59:14 +0200 Subject: Remove the upcast --- crates/ra_hir/src/code_model.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 146e7820e..9e4aa6022 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -33,7 +33,11 @@ use ra_syntax::{ }; use rustc_hash::FxHashSet; -use crate::{db::HirDatabase, has_source::HasSource, CallableDef, HirDisplay, InFile, Name}; +use crate::{ + db::{DefDatabase, HirDatabase}, + has_source::HasSource, + CallableDef, HirDisplay, InFile, Name, +}; /// hir::Crate describes a single crate. It's the main interface with which /// a crate's dependencies interact. Mostly, it should be just a proxy for the @@ -285,10 +289,10 @@ impl Module { /// this module, if possible. pub fn find_use_path( self, - db: &dyn HirDatabase, + db: &dyn DefDatabase, item: ItemInNs, ) -> Option { - hir_def::find_path::find_path(db.upcast(), item, self.into()) + hir_def::find_path::find_path(db, item, self.into()) } } -- cgit v1.2.3 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_assists/Cargo.toml | 1 + crates/ra_assists/src/ast_transform.rs | 2 +- crates/ra_assists/src/handlers/auto_import.rs | 44 ++++++++++++----------- crates/ra_assists/src/handlers/fill_match_arms.rs | 3 +- crates/ra_hir/src/code_model.rs | 21 ++--------- crates/ra_hir/src/from_id.rs | 21 +++++++++-- crates/ra_ide_db/Cargo.toml | 1 + crates/ra_ide_db/src/imports_locator.rs | 10 ++++-- 8 files changed, 56 insertions(+), 47 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index 707746ad5..a87f4052a 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -12,6 +12,7 @@ format-buf = "1.0.0" join_to_string = "0.1.3" rustc-hash = "1.1.0" itertools = "0.9.0" +either = "1.5.3" ra_syntax = { path = "../ra_syntax" } ra_text_edit = { path = "../ra_text_edit" } diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 34c816f16..45558c448 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -129,7 +129,7 @@ impl<'a> QualifyPaths<'a> { let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; match resolution { PathResolution::Def(def) => { - let found_path = from.find_use_path(self.source_scope.db, def.into())?; + let found_path = from.find_use_path(self.source_scope.db, def)?; let mut path = path_to_ast(found_path); let type_args = p diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 49d8c4c3d..443eeaaf0 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -4,7 +4,7 @@ use hir::{ AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait, Type, }; -use ra_ide_db::{defs::Definition, imports_locator::ImportsLocator, RootDatabase}; +use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase}; use ra_prof::profile; use ra_syntax::{ ast::{self, AstNode}, @@ -17,6 +17,7 @@ use crate::{ utils::insert_use_statement, AssistId, }; +use either::Either; // Assist: auto_import // @@ -127,16 +128,14 @@ impl AutoImportAssets { ImportsLocator::new(db) .find_imports(&self.get_search_query()) .into_iter() - .filter_map(|definition| match &self.import_candidate { + .filter_map(|candidate| match &self.import_candidate { ImportCandidate::TraitAssocItem(assoc_item_type, _) => { - let located_assoc_item = match definition { - Definition::ModuleDef(ModuleDef::Function(located_function)) => { - located_function - .as_assoc_item(db) - .map(|assoc| assoc.container(db)) - .and_then(Self::assoc_to_trait) - } - Definition::ModuleDef(ModuleDef::Const(located_const)) => located_const + let located_assoc_item = match candidate { + Either::Left(ModuleDef::Function(located_function)) => located_function + .as_assoc_item(db) + .map(|assoc| assoc.container(db)) + .and_then(Self::assoc_to_trait), + Either::Left(ModuleDef::Const(located_const)) => located_const .as_assoc_item(db) .map(|assoc| assoc.container(db)) .and_then(Self::assoc_to_trait), @@ -154,13 +153,12 @@ impl AutoImportAssets { None, |_, assoc| Self::assoc_to_trait(assoc.container(db)), ) - .map(|located_trait| ModuleDef::from(located_trait).into()) + .map(ModuleDef::from) + .map(Either::Left) } ImportCandidate::TraitMethod(function_callee, _) => { let located_assoc_item = - if let Definition::ModuleDef(ModuleDef::Function(located_function)) = - definition - { + if let Either::Left(ModuleDef::Function(located_function)) = candidate { located_function .as_assoc_item(db) .map(|assoc| assoc.container(db)) @@ -182,15 +180,19 @@ impl AutoImportAssets { Self::assoc_to_trait(function.as_assoc_item(db)?.container(db)) }, ) - .map(|located_trait| ModuleDef::from(located_trait).into()) + .map(ModuleDef::from) + .map(Either::Left) + } + _ => Some(candidate), + }) + .filter_map(|candidate| match candidate { + Either::Left(module_def) => { + self.module_with_name_to_import.find_use_path(db, module_def) + } + Either::Right(macro_def) => { + self.module_with_name_to_import.find_use_path(db, macro_def) } - _ => match definition { - Definition::ModuleDef(module_def) => Some(module_def.into()), - Definition::Macro(macro_def) => Some(macro_def.into()), - _ => None, - }, }) - .filter_map(|item| self.module_with_name_to_import.find_use_path(db, item)) .filter(|use_path| !use_path.segments.is_empty()) .take(20) .collect::>() diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 869942b12..88b4c8926 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -154,8 +154,7 @@ fn resolve_tuple_of_enum_def( } fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option { - let path = - crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var).into())?); + let path = crate::ast_transform::path_to_ast(module.find_use_path(db, ModuleDef::from(var))?); // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though let pat: ast::Pat = match var.source(db).value.kind() { diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9e4aa6022..c5cfd875f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -143,17 +143,6 @@ impl ModuleDef { } } -impl From for ItemInNs { - fn from(module_def: ModuleDef) -> Self { - match module_def { - ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { - ItemInNs::Values(module_def.into()) - } - _ => ItemInNs::Types(module_def.into()), - } - } -} - pub use hir_def::{ attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, }; @@ -290,9 +279,9 @@ impl Module { pub fn find_use_path( self, db: &dyn DefDatabase, - item: ItemInNs, + item: impl Into, ) -> Option { - hir_def::find_path::find_path(db, item, self.into()) + hir_def::find_path::find_path(db, item.into(), self.into()) } } @@ -764,12 +753,6 @@ impl MacroDef { } } -impl From for ItemInNs { - fn from(macro_def: MacroDef) -> Self { - ItemInNs::Macros(macro_def.into()) - } -} - /// Invariant: `inner.as_assoc_item(db).is_some()` /// We do not actively enforce this invariant. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index c179b13c6..62fb52e72 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs @@ -9,8 +9,8 @@ use hir_def::{ }; use crate::{ - Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, ModuleDef, StructField, - VariantDef, + code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, + MacroDef, ModuleDef, StructField, VariantDef, }; macro_rules! from_id { @@ -228,3 +228,20 @@ impl From<(DefWithBodyId, PatId)> for Local { Local { parent, pat_id } } } + +impl From for ItemInNs { + fn from(macro_def: MacroDef) -> Self { + ItemInNs::Macros(macro_def.into()) + } +} + +impl From for ItemInNs { + fn from(module_def: ModuleDef) -> Self { + match module_def { + ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { + ItemInNs::Values(module_def.into()) + } + _ => ItemInNs::Types(module_def.into()), + } + } +} 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 From dd3b64124b086cf68c3f8b1e838601b5770a9795 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 23 Mar 2020 23:23:26 +0200 Subject: Add a test --- crates/ra_assists/src/handlers/auto_import.rs | 25 +++++++++++++++++++++++ crates/ra_assists/src/lib.rs | 29 ++++++++++++++++++--------- 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 443eeaaf0..99682e023 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -59,6 +59,7 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option { group.finish() } +#[derive(Debug)] struct AutoImportAssets { import_candidate: ImportCandidate, module_with_name_to_import: Module, @@ -449,6 +450,30 @@ mod tests { ); } + #[test] + fn macro_import() { + check_assist( + auto_import, + r" + //- /lib.rs crate:crate_with_macro + #[macro_export] + macro_rules! foo { + () => () + } + + //- /main.rs crate:main deps:crate_with_macro + fn main() { + foo<|> + }", + r"use crate_with_macro::foo; + +fn main() { + foo<|> +} +", + ); + } + #[test] fn auto_import_target() { check_assist_target( diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index b8704ea7d..bcc9b3f10 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -165,7 +165,6 @@ mod helpers { use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; - use ra_syntax::TextRange; use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset}; use crate::{AssistCtx, AssistHandler}; @@ -175,8 +174,7 @@ mod helpers { let (mut db, file_id) = RootDatabase::with_single_file(text); // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, // but it looks like this might need specialization? :( - let local_roots = vec![db.file_source_root(file_id)]; - db.set_local_roots(Arc::new(local_roots)); + db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)])); (db, file_id) } @@ -206,11 +204,24 @@ mod helpers { } fn check(assist: AssistHandler, before: &str, expected: ExpectedResult) { - let (range_or_offset, before) = extract_range_or_offset(before); - let range: TextRange = range_or_offset.into(); + let (text_without_caret, file_with_caret_id, range_or_offset, db) = + if before.contains("//-") { + let (mut db, position) = RootDatabase::with_position(before); + db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); + ( + db.file_text(position.file_id).as_ref().to_owned(), + position.file_id, + RangeOrOffset::Offset(position.offset), + db, + ) + } else { + let (range_or_offset, text_without_caret) = extract_range_or_offset(before); + let (db, file_id) = with_single_file(&text_without_caret); + (text_without_caret, file_id, range_or_offset, db) + }; + + let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; - let (db, file_id) = with_single_file(&before); - let frange = FileRange { file_id, range }; let sema = Semantics::new(&db); let assist_ctx = AssistCtx::new(&sema, frange, true); @@ -218,7 +229,7 @@ mod helpers { (Some(assist), ExpectedResult::After(after)) => { let action = assist.0[0].action.clone().unwrap(); - let mut actual = action.edit.apply(&before); + let mut actual = action.edit.apply(&text_without_caret); match action.cursor_position { None => { if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { @@ -237,7 +248,7 @@ mod helpers { (Some(assist), ExpectedResult::Target(target)) => { let action = assist.0[0].action.clone().unwrap(); let range = action.target.expect("expected target on action"); - assert_eq_text!(&before[range], target); + assert_eq_text!(&text_without_caret[range], target); } (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { -- cgit v1.2.3