From b5c330bf5a1884ff8ad196a23fa6e356c460e130 Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Sat, 2 May 2020 18:10:23 +0200 Subject: Make `change_visibility` assist work for tuple struct field visibility --- crates/ra_assists/src/handlers/change_visibility.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 44f6a1dae..1cd532e80 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -47,8 +47,7 @@ fn add_vis(ctx: AssistCtx) -> Option { return None; } (vis_offset(&parent), keyword.text_range()) - } else { - let field_name: ast::Name = ctx.find_node_at_offset()?; + } else if let Some(field_name) = ctx.find_node_at_offset::() { let field = field_name.syntax().ancestors().find_map(ast::RecordFieldDef::cast)?; if field.name()? != field_name { tested_by!(change_visibility_field_false_positive); @@ -58,6 +57,13 @@ fn add_vis(ctx: AssistCtx) -> Option { return None; } (vis_offset(field.syntax()), field_name.syntax().text_range()) + } else if let Some(field) = ctx.find_node_at_offset::() { + if field.visibility().is_some() { + return None; + } + (vis_offset(field.syntax()), field.syntax().text_range()) + } else { + return None; }; ctx.add_assist(AssistId("change_visibility"), "Change visibility to pub(crate)", |edit| { @@ -129,7 +135,8 @@ mod tests { change_visibility, r"struct S { <|>field: u32 }", r"struct S { <|>pub(crate) field: u32 }", - ) + ); + check_assist(change_visibility, r"struct S ( <|>u32 )", r"struct S ( <|>pub(crate) u32 )"); } #[test] -- cgit v1.2.3 From 92665358cd98913e3fef8294e1889cc0bb919e3f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 5 May 2020 23:56:10 +0800 Subject: Rename ImplItem to AssocItem --- .../src/handlers/add_missing_impl_members.rs | 26 +++++++++++----------- crates/ra_assists/src/handlers/add_new.rs | 4 ++-- crates/ra_assists/src/utils.rs | 10 ++++----- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index e466c9a86..e47feda71 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs @@ -10,7 +10,7 @@ use ra_syntax::{ use crate::{ ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, - utils::{get_missing_impl_items, resolve_target_trait}, + utils::{get_missing_assoc_items, resolve_target_trait}, Assist, AssistCtx, AssistId, }; @@ -112,25 +112,25 @@ fn add_missing_impl_members_inner( let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?; - let def_name = |item: &ast::ImplItem| -> Option { + let def_name = |item: &ast::AssocItem| -> Option { match item { - ast::ImplItem::FnDef(def) => def.name(), - ast::ImplItem::TypeAliasDef(def) => def.name(), - ast::ImplItem::ConstDef(def) => def.name(), + ast::AssocItem::FnDef(def) => def.name(), + ast::AssocItem::TypeAliasDef(def) => def.name(), + ast::AssocItem::ConstDef(def) => def.name(), } .map(|it| it.text().clone()) }; - let missing_items = get_missing_impl_items(&ctx.sema, &impl_node) + let missing_items = get_missing_assoc_items(&ctx.sema, &impl_node) .iter() .map(|i| match i { - hir::AssocItem::Function(i) => ast::ImplItem::FnDef(i.source(ctx.db).value), - hir::AssocItem::TypeAlias(i) => ast::ImplItem::TypeAliasDef(i.source(ctx.db).value), - hir::AssocItem::Const(i) => ast::ImplItem::ConstDef(i.source(ctx.db).value), + hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db).value), + hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db).value), + hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db).value), }) .filter(|t| def_name(&t).is_some()) .filter(|t| match t { - ast::ImplItem::FnDef(def) => match mode { + ast::AssocItem::FnDef(def) => match mode { AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), }, @@ -145,7 +145,7 @@ fn add_missing_impl_members_inner( let sema = ctx.sema; ctx.add_assist(AssistId(assist_id), label, |edit| { - let n_existing_items = impl_item_list.impl_items().count(); + let n_existing_items = impl_item_list.assoc_items().count(); let source_scope = sema.scope_for_def(trait_); let target_scope = sema.scope(impl_item_list.syntax()); let ast_transform = QualifyPaths::new(&target_scope, &source_scope) @@ -154,13 +154,13 @@ fn add_missing_impl_members_inner( .into_iter() .map(|it| ast_transform::apply(&*ast_transform, it)) .map(|it| match it { - ast::ImplItem::FnDef(def) => ast::ImplItem::FnDef(add_body(def)), + ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), _ => it, }) .map(|it| edit::remove_attrs_and_docs(&it)); let new_impl_item_list = impl_item_list.append_items(items); let cursor_position = { - let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap(); + let first_new_item = new_impl_item_list.assoc_items().nth(n_existing_items).unwrap(); first_new_item.syntax().text_range().start() }; diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 0f9174a29..e8a36c7de 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -162,8 +162,8 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option bool { if let Some(il) = imp.item_list() { - for item in il.impl_items() { - if let ast::ImplItem::FnDef(f) = item { + for item in il.assoc_items() { + if let ast::AssocItem::FnDef(f) = item { if let Some(name) = f.name() { if name.text().eq_ignore_ascii_case("new") { return true; diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 6be704ce3..2f15a3f15 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -13,7 +13,7 @@ use rustc_hash::FxHashSet; pub(crate) use insert_use::insert_use_statement; -pub fn get_missing_impl_items( +pub fn get_missing_assoc_items( sema: &Semantics, impl_def: &ast::ImplDef, ) -> Vec { @@ -23,21 +23,21 @@ pub fn get_missing_impl_items( let mut impl_type = FxHashSet::default(); if let Some(item_list) = impl_def.item_list() { - for item in item_list.impl_items() { + for item in item_list.assoc_items() { match item { - ast::ImplItem::FnDef(f) => { + ast::AssocItem::FnDef(f) => { if let Some(n) = f.name() { impl_fns_consts.insert(n.syntax().to_string()); } } - ast::ImplItem::TypeAliasDef(t) => { + ast::AssocItem::TypeAliasDef(t) => { if let Some(n) = t.name() { impl_type.insert(n.syntax().to_string()); } } - ast::ImplItem::ConstDef(c) => { + ast::AssocItem::ConstDef(c) => { if let Some(n) = c.name() { impl_fns_consts.insert(n.syntax().to_string()); } -- cgit v1.2.3 From 13c078db9cba8bbbf48918a928cd2533571a7f5d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 20:30:33 +0200 Subject: Flip Assist::new arguments --- crates/ra_assists/src/assist_ctx.rs | 4 ++-- crates/ra_assists/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index da2880037..d6f585d0e 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -100,7 +100,7 @@ impl<'a> AssistCtx<'a> { label: impl Into, f: impl FnOnce(&mut ActionBuilder), ) -> Option { - let label = AssistLabel::new(label.into(), id); + let label = AssistLabel::new(id, label.into()); let mut info = AssistInfo::new(label); if self.should_compute_edit { @@ -157,7 +157,7 @@ impl<'a> AssistGroup<'a> { label: impl Into, f: impl FnOnce(&mut ActionBuilder), ) { - let label = AssistLabel::new(label.into(), id); + let label = AssistLabel::new(id, label.into()); let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group_name.clone())); if self.ctx.should_compute_edit { diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index c5df86600..6156f4e2c 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -32,16 +32,16 @@ pub struct AssistId(pub &'static str); #[derive(Debug, Clone)] pub struct AssistLabel { + pub id: AssistId, /// Short description of the assist, as shown in the UI. pub label: String, - pub id: AssistId, } #[derive(Clone, Debug)] pub struct GroupLabel(pub String); impl AssistLabel { - pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { + pub(crate) fn new(id: AssistId, label: String) -> AssistLabel { // FIXME: make fields private, so that this invariant can't be broken assert!(label.starts_with(|c: char| c.is_uppercase())); AssistLabel { label, id } -- cgit v1.2.3 From d5b9282ede9947e5743608054e09222033a4e6e4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 20:33:10 +0200 Subject: Minor rename --- crates/ra_assists/src/assist_ctx.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index d6f585d0e..1020fed29 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -116,7 +116,7 @@ impl<'a> AssistCtx<'a> { } pub(crate) fn add_assist_group(self, group_name: impl Into) -> AssistGroup<'a> { - AssistGroup { ctx: self, group_name: group_name.into(), assists: Vec::new() } + AssistGroup { ctx: self, group: group_name.into(), assists: Vec::new() } } pub(crate) fn token_at_offset(&self) -> TokenAtOffset { @@ -146,7 +146,7 @@ impl<'a> AssistCtx<'a> { pub(crate) struct AssistGroup<'a> { ctx: AssistCtx<'a>, - group_name: String, + group: String, assists: Vec, } @@ -159,7 +159,7 @@ impl<'a> AssistGroup<'a> { ) { let label = AssistLabel::new(id, label.into()); - let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group_name.clone())); + let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group.clone())); if self.ctx.should_compute_edit { let action = { let mut edit = ActionBuilder::new(&self.ctx); -- cgit v1.2.3 From 6c2414430aca92f95eda9f0238dce8af2de552af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 20:34:45 +0200 Subject: use GroupLabel for type safety --- crates/ra_assists/src/assist_ctx.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 1020fed29..d88ae4413 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -116,7 +116,8 @@ impl<'a> AssistCtx<'a> { } pub(crate) fn add_assist_group(self, group_name: impl Into) -> AssistGroup<'a> { - AssistGroup { ctx: self, group: group_name.into(), assists: Vec::new() } + let group = GroupLabel(group_name.into()); + AssistGroup { ctx: self, group, assists: Vec::new() } } pub(crate) fn token_at_offset(&self) -> TokenAtOffset { @@ -146,7 +147,7 @@ impl<'a> AssistCtx<'a> { pub(crate) struct AssistGroup<'a> { ctx: AssistCtx<'a>, - group: String, + group: GroupLabel, assists: Vec, } @@ -159,7 +160,7 @@ impl<'a> AssistGroup<'a> { ) { let label = AssistLabel::new(id, label.into()); - let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group.clone())); + let mut info = AssistInfo::new(label).with_group(self.group.clone()); if self.ctx.should_compute_edit { let action = { let mut edit = ActionBuilder::new(&self.ctx); -- cgit v1.2.3 From aee22c73c3cafdb6f4b3f97bc483791d4ed2e902 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 20:42:52 +0200 Subject: Move group_label where it belongs --- crates/ra_assists/src/assist_ctx.rs | 7 +++---- crates/ra_assists/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index d88ae4413..82f61bc8f 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -38,8 +38,7 @@ impl AssistInfo { pub(crate) fn into_resolved(self) -> Option { let label = self.label; - let group_label = self.group_label; - self.action.map(|action| ResolvedAssist { label, group_label, action }) + self.action.map(|action| ResolvedAssist { label, action }) } } @@ -100,7 +99,7 @@ impl<'a> AssistCtx<'a> { label: impl Into, f: impl FnOnce(&mut ActionBuilder), ) -> Option { - let label = AssistLabel::new(id, label.into()); + let label = AssistLabel::new(id, label.into(), None); let mut info = AssistInfo::new(label); if self.should_compute_edit { @@ -158,7 +157,7 @@ impl<'a> AssistGroup<'a> { label: impl Into, f: impl FnOnce(&mut ActionBuilder), ) { - let label = AssistLabel::new(id, label.into()); + let label = AssistLabel::new(id, label.into(), Some(self.group.clone())); let mut info = AssistInfo::new(label).with_group(self.group.clone()); if self.ctx.should_compute_edit { diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 6156f4e2c..1b31d655b 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -35,16 +35,17 @@ pub struct AssistLabel { pub id: AssistId, /// Short description of the assist, as shown in the UI. pub label: String, + pub group: Option, } #[derive(Clone, Debug)] pub struct GroupLabel(pub String); impl AssistLabel { - pub(crate) fn new(id: AssistId, label: String) -> AssistLabel { + pub(crate) fn new(id: AssistId, label: String, group: Option) -> AssistLabel { // FIXME: make fields private, so that this invariant can't be broken assert!(label.starts_with(|c: char| c.is_uppercase())); - AssistLabel { label, id } + AssistLabel { id, label, group } } } @@ -60,7 +61,6 @@ pub struct AssistAction { #[derive(Debug, Clone)] pub struct ResolvedAssist { pub label: AssistLabel, - pub group_label: Option, pub action: AssistAction, } -- cgit v1.2.3 From df00da15c435f3105007146cbbfc9afc34ad311c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 20:44:13 +0200 Subject: Fix compilation --- crates/ra_assists/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 1b31d655b..5cec10088 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -17,13 +17,13 @@ mod doc_tests; pub mod utils; pub mod ast_transform; +use hir::Semantics; use ra_db::{FileId, FileRange}; use ra_ide_db::RootDatabase; use ra_syntax::{TextRange, TextSize}; use ra_text_edit::TextEdit; pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; -use hir::Semantics; /// Unique identifier of the assist, should not be shown to the user /// directly. -- cgit v1.2.3 From 381cbc6088b6c4238b0f82df8ef37b552257ae59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 22:14:01 +0200 Subject: Minor cleanups --- crates/ra_assists/src/assist_ctx.rs | 1 - crates/ra_assists/src/lib.rs | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 82f61bc8f..89547ce03 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -42,7 +42,6 @@ impl AssistInfo { } } -pub(crate) type AssistHandler = fn(AssistCtx) -> Option; /// `AssistCtx` allows to apply an assist or check if it could be applied. /// diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 5cec10088..ad85f5553 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -23,7 +23,7 @@ use ra_ide_db::RootDatabase; use ra_syntax::{TextRange, TextSize}; use ra_text_edit::TextEdit; -pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; +pub(crate) use crate::assist_ctx::{Assist, AssistCtx}; /// Unique identifier of the assist, should not be shown to the user /// directly. @@ -109,7 +109,9 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec Option; mod add_custom_impl; mod add_derive; @@ -145,12 +147,13 @@ mod handlers { mod reorder_fields; mod unwrap_block; - pub(crate) fn all() -> &'static [AssistHandler] { + pub(crate) fn all() -> &'static [Handler] { &[ // These are alphabetic for the foolish consistency add_custom_impl::add_custom_impl, add_derive::add_derive, add_explicit_type::add_explicit_type, + add_from_impl_for_enum::add_from_impl_for_enum, add_function::add_function, add_impl::add_impl, add_new::add_new, @@ -176,17 +179,18 @@ mod handlers { raw_string::remove_hash, remove_dbg::remove_dbg, remove_mut::remove_mut, + reorder_fields::reorder_fields, replace_if_let_with_match::replace_if_let_with_match, replace_let_with_if_let::replace_let_with_if_let, replace_qualified_name_with_use::replace_qualified_name_with_use, replace_unwrap_with_match::replace_unwrap_with_match, split_import::split_import, - add_from_impl_for_enum::add_from_impl_for_enum, unwrap_block::unwrap_block, // These are manually sorted for better priorities add_missing_impl_members::add_missing_impl_members, add_missing_impl_members::add_missing_default_members, - reorder_fields::reorder_fields, + // Are you sure you want to add new assist here, and not to the + // sorted list above? ] } } -- cgit v1.2.3 From 4a6fa8f0dfcebbb4ea80394e5e4ca21f076f58f2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:15:49 +0200 Subject: Rename AtomTextEdit -> Indel --- crates/ra_assists/src/assist_ctx.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 89547ce03..83dd270c6 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -4,14 +4,13 @@ use ra_db::FileRange; use ra_fmt::{leading_indent, reindent}; use ra_ide_db::RootDatabase; use ra_syntax::{ - algo::{self, find_covering_element, find_node_at_offset}, + algo::{self, find_covering_element, find_node_at_offset, SyntaxRewriter}, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, }; use ra_text_edit::TextEditBuilder; use crate::{AssistAction, AssistFile, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; -use algo::SyntaxRewriter; #[derive(Clone, Debug)] pub(crate) struct Assist(pub(crate) Vec); @@ -42,7 +41,6 @@ impl AssistInfo { } } - /// `AssistCtx` allows to apply an assist or check if it could be applied. /// /// Assists use a somewhat over-engineered approach, given the current needs. The -- cgit v1.2.3 From ca9e0f5fe9ad29ab0c5a0771a0d0eaec97e4104b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 May 2020 23:48:26 +0200 Subject: Fixup tests --- crates/ra_assists/src/doc_tests.rs | 6 +++++- crates/ra_assists/src/lib.rs | 20 ++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs index c0f9bc1fb..f627f31dc 100644 --- a/crates/ra_assists/src/doc_tests.rs +++ b/crates/ra_assists/src/doc_tests.rs @@ -30,6 +30,10 @@ fn check(assist_id: &str, before: &str, after: &str) { ) }); - let actual = assist.action.edit.apply(&before); + let actual = { + let mut actual = before.clone(); + assist.action.edit.apply(&mut actual); + actual + }; assert_eq_text!(after, &actual); } diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index ad85f5553..0f94f5ee8 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -199,12 +199,12 @@ mod handlers { mod helpers { use std::sync::Arc; + use hir::Semantics; use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset}; - use crate::{AssistCtx, AssistFile, AssistHandler}; - use hir::Semantics; + use crate::{handlers::Handler, AssistCtx, AssistFile}; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { let (mut db, file_id) = RootDatabase::with_single_file(text); @@ -214,22 +214,18 @@ mod helpers { (db, file_id) } - pub(crate) fn check_assist( - assist: AssistHandler, - ra_fixture_before: &str, - ra_fixture_after: &str, - ) { + pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); } // FIXME: instead of having a separate function here, maybe use // `extract_ranges` and mark the target as ` ` in the // fixuture? - pub(crate) fn check_assist_target(assist: AssistHandler, ra_fixture: &str, target: &str) { + pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { check(assist, ra_fixture, ExpectedResult::Target(target)); } - pub(crate) fn check_assist_not_applicable(assist: AssistHandler, ra_fixture: &str) { + pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { check(assist, ra_fixture, ExpectedResult::NotApplicable); } @@ -239,7 +235,7 @@ mod helpers { Target(&'a str), } - fn check(assist: AssistHandler, before: &str, expected: ExpectedResult) { + fn check(assist: Handler, before: &str, expected: ExpectedResult) { let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { let (mut db, position) = RootDatabase::with_position(before); @@ -265,13 +261,13 @@ mod helpers { (Some(assist), ExpectedResult::After(after)) => { let action = assist.0[0].action.clone().unwrap(); - let assisted_file_text = if let AssistFile::TargetFile(file_id) = action.file { + let mut actual = if let AssistFile::TargetFile(file_id) = action.file { db.file_text(file_id).as_ref().to_owned() } else { text_without_caret }; + action.edit.apply(&mut actual); - let mut actual = action.edit.apply(&assisted_file_text); match action.cursor_position { None => { if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { -- cgit v1.2.3