2019-09-08 04:10:53 -05:00
|
|
|
//! `ra_assists` crate provides a bunch of code assists, also known as code
|
2019-02-03 12:26:35 -06:00
|
|
|
//! actions (in LSP) or intentions (in IntelliJ).
|
|
|
|
//!
|
|
|
|
//! An assist is a micro-refactoring, which is automatically activated in
|
|
|
|
//! certain context. For example, if the cursor is over `,`, a "swap `,`" assist
|
|
|
|
//! becomes available.
|
|
|
|
|
2020-04-06 09:58:16 -05:00
|
|
|
#[allow(unused)]
|
|
|
|
macro_rules! eprintln {
|
|
|
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
|
|
|
}
|
|
|
|
|
2019-02-03 12:26:35 -06:00
|
|
|
mod assist_ctx;
|
2019-02-24 05:22:25 -06:00
|
|
|
mod marks;
|
2019-10-25 06:16:46 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod doc_tests;
|
2020-02-09 12:24:34 -06:00
|
|
|
pub mod utils;
|
2020-01-10 11:26:18 -06:00
|
|
|
pub mod ast_transform;
|
2019-02-11 11:07:21 -06:00
|
|
|
|
2020-05-05 13:44:13 -05:00
|
|
|
use hir::Semantics;
|
2020-04-18 09:12:21 -05:00
|
|
|
use ra_db::{FileId, FileRange};
|
2020-02-06 10:17:51 -06:00
|
|
|
use ra_ide_db::RootDatabase;
|
2020-04-24 16:40:41 -05:00
|
|
|
use ra_syntax::{TextRange, TextSize};
|
2019-07-04 15:05:17 -05:00
|
|
|
use ra_text_edit::TextEdit;
|
2019-02-03 12:26:35 -06:00
|
|
|
|
2020-02-07 08:53:31 -06:00
|
|
|
pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler};
|
2019-02-03 12:26:35 -06:00
|
|
|
|
2019-02-24 04:53:35 -06:00
|
|
|
/// Unique identifier of the assist, should not be shown to the user
|
|
|
|
/// directly.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
pub struct AssistId(pub &'static str);
|
|
|
|
|
2019-02-11 11:07:21 -06:00
|
|
|
#[derive(Debug, Clone)]
|
2019-02-03 12:26:35 -06:00
|
|
|
pub struct AssistLabel {
|
2020-05-05 13:30:33 -05:00
|
|
|
pub id: AssistId,
|
2019-02-03 12:26:35 -06:00
|
|
|
/// Short description of the assist, as shown in the UI.
|
|
|
|
pub label: String,
|
2020-05-05 13:42:52 -05:00
|
|
|
pub group: Option<GroupLabel>,
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
2020-02-09 08:32:53 -06:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct GroupLabel(pub String);
|
|
|
|
|
2020-02-07 08:04:50 -06:00
|
|
|
impl AssistLabel {
|
2020-05-05 13:42:52 -05:00
|
|
|
pub(crate) fn new(id: AssistId, label: String, group: Option<GroupLabel>) -> AssistLabel {
|
2020-02-07 08:04:50 -06:00
|
|
|
// FIXME: make fields private, so that this invariant can't be broken
|
2020-02-18 22:29:34 -06:00
|
|
|
assert!(label.starts_with(|c: char| c.is_uppercase()));
|
2020-05-05 13:42:52 -05:00
|
|
|
AssistLabel { id, label, group }
|
2020-02-07 08:04:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 11:07:21 -06:00
|
|
|
#[derive(Debug, Clone)]
|
2019-02-03 12:26:35 -06:00
|
|
|
pub struct AssistAction {
|
|
|
|
pub edit: TextEdit,
|
2020-04-24 16:40:41 -05:00
|
|
|
pub cursor_position: Option<TextSize>,
|
2020-02-07 07:53:50 -06:00
|
|
|
// FIXME: This belongs to `AssistLabel`
|
2019-02-08 15:43:13 -06:00
|
|
|
pub target: Option<TextRange>,
|
2020-04-18 09:12:21 -05:00
|
|
|
pub file: AssistFile,
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
2020-01-11 16:40:36 -06:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ResolvedAssist {
|
|
|
|
pub label: AssistLabel,
|
2020-02-09 08:32:53 -06:00
|
|
|
pub action: AssistAction,
|
2020-01-11 16:40:36 -06:00
|
|
|
}
|
|
|
|
|
2020-04-18 09:12:21 -05:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub enum AssistFile {
|
|
|
|
CurrentFile,
|
|
|
|
TargetFile(FileId),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AssistFile {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::CurrentFile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 06:16:46 -05:00
|
|
|
/// Return all the assists applicable at the given position.
|
2019-02-03 12:26:35 -06:00
|
|
|
///
|
|
|
|
/// Assists are returned in the "unresolved" state, that is only labels are
|
|
|
|
/// returned, without actual edits.
|
2020-02-06 11:46:11 -06:00
|
|
|
pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> {
|
2020-02-18 11:35:10 -06:00
|
|
|
let sema = Semantics::new(db);
|
|
|
|
let ctx = AssistCtx::new(&sema, range, false);
|
2020-02-07 08:53:31 -06:00
|
|
|
handlers::all()
|
2020-02-07 07:53:50 -06:00
|
|
|
.iter()
|
|
|
|
.filter_map(|f| f(ctx.clone()))
|
2020-02-09 08:32:53 -06:00
|
|
|
.flat_map(|it| it.0)
|
|
|
|
.map(|a| a.label)
|
2020-02-07 07:53:50 -06:00
|
|
|
.collect()
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return all the assists applicable at the given position.
|
|
|
|
///
|
|
|
|
/// Assists are returned in the "resolved" state, that is with edit fully
|
|
|
|
/// computed.
|
2020-02-06 11:46:11 -06:00
|
|
|
pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
|
2020-02-18 11:35:10 -06:00
|
|
|
let sema = Semantics::new(db);
|
|
|
|
let ctx = AssistCtx::new(&sema, range, true);
|
2020-02-07 08:53:31 -06:00
|
|
|
let mut a = handlers::all()
|
2020-02-07 07:53:50 -06:00
|
|
|
.iter()
|
|
|
|
.filter_map(|f| f(ctx.clone()))
|
2020-02-09 08:32:53 -06:00
|
|
|
.flat_map(|it| it.0)
|
|
|
|
.map(|it| it.into_resolved().unwrap())
|
2020-02-07 07:55:47 -06:00
|
|
|
.collect::<Vec<_>>();
|
2020-04-24 16:40:41 -05:00
|
|
|
a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len()));
|
2020-02-07 07:53:50 -06:00
|
|
|
a
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
2020-02-07 08:53:31 -06:00
|
|
|
mod handlers {
|
|
|
|
use crate::AssistHandler;
|
2019-09-25 06:29:41 -05:00
|
|
|
|
2020-03-18 10:48:45 -05:00
|
|
|
mod add_custom_impl;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod add_derive;
|
|
|
|
mod add_explicit_type;
|
2020-03-26 14:59:35 -05:00
|
|
|
mod add_function;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod add_impl;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod add_missing_impl_members;
|
2019-11-09 09:56:36 -06:00
|
|
|
mod add_new;
|
2019-10-03 15:19:46 -05:00
|
|
|
mod apply_demorgan;
|
2019-12-23 18:19:09 -06:00
|
|
|
mod auto_import;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod change_visibility;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod early_return;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod fill_match_arms;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod flip_binexpr;
|
|
|
|
mod flip_comma;
|
|
|
|
mod flip_trait_bound;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod inline_local_variable;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod introduce_variable;
|
|
|
|
mod invert_if;
|
2020-03-18 10:41:24 -05:00
|
|
|
mod merge_imports;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod merge_match_arms;
|
|
|
|
mod move_bounds;
|
|
|
|
mod move_guard;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod raw_string;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod remove_dbg;
|
2020-02-19 05:44:20 -06:00
|
|
|
mod remove_mut;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod replace_if_let_with_match;
|
2020-03-27 06:12:17 -05:00
|
|
|
mod replace_let_with_if_let;
|
2020-03-18 10:48:45 -05:00
|
|
|
mod replace_qualified_name_with_use;
|
2020-03-26 04:16:10 -05:00
|
|
|
mod replace_unwrap_with_match;
|
2019-09-25 06:29:41 -05:00
|
|
|
mod split_import;
|
2020-04-01 16:26:41 -05:00
|
|
|
mod add_from_impl_for_enum;
|
2020-04-09 17:35:43 -05:00
|
|
|
mod reorder_fields;
|
2020-04-29 06:52:55 -05:00
|
|
|
mod unwrap_block;
|
2019-09-25 06:29:41 -05:00
|
|
|
|
2020-02-07 08:53:31 -06:00
|
|
|
pub(crate) fn all() -> &'static [AssistHandler] {
|
2019-09-25 06:29:41 -05:00
|
|
|
&[
|
2020-04-09 03:00:27 -05:00
|
|
|
// These are alphabetic for the foolish consistency
|
2020-03-18 10:48:45 -05:00
|
|
|
add_custom_impl::add_custom_impl,
|
2019-09-25 06:29:41 -05:00
|
|
|
add_derive::add_derive,
|
|
|
|
add_explicit_type::add_explicit_type,
|
2020-03-26 14:59:35 -05:00
|
|
|
add_function::add_function,
|
2019-09-25 06:29:41 -05:00
|
|
|
add_impl::add_impl,
|
2019-11-09 09:56:36 -06:00
|
|
|
add_new::add_new,
|
2019-10-03 15:19:46 -05:00
|
|
|
apply_demorgan::apply_demorgan,
|
2020-03-18 10:48:45 -05:00
|
|
|
auto_import::auto_import,
|
2019-09-25 06:29:41 -05:00
|
|
|
change_visibility::change_visibility,
|
2020-03-18 10:48:45 -05:00
|
|
|
early_return::convert_to_guarded_return,
|
2019-09-25 06:29:41 -05:00
|
|
|
fill_match_arms::fill_match_arms,
|
|
|
|
flip_binexpr::flip_binexpr,
|
2020-03-18 10:48:45 -05:00
|
|
|
flip_comma::flip_comma,
|
2019-10-26 15:24:48 -05:00
|
|
|
flip_trait_bound::flip_trait_bound,
|
2020-01-19 10:39:53 -06:00
|
|
|
inline_local_variable::inline_local_variable,
|
2020-03-18 10:48:45 -05:00
|
|
|
introduce_variable::introduce_variable,
|
|
|
|
invert_if::invert_if,
|
2020-03-18 10:41:24 -05:00
|
|
|
merge_imports::merge_imports,
|
2020-03-18 10:48:45 -05:00
|
|
|
merge_match_arms::merge_match_arms,
|
2019-09-25 06:29:41 -05:00
|
|
|
move_bounds::move_bounds_to_where_clause,
|
2020-03-18 10:48:45 -05:00
|
|
|
move_guard::move_arm_cond_to_match_guard,
|
|
|
|
move_guard::move_guard_to_arm_body,
|
2019-09-25 06:29:41 -05:00
|
|
|
raw_string::add_hash,
|
|
|
|
raw_string::make_raw_string,
|
|
|
|
raw_string::make_usual_string,
|
|
|
|
raw_string::remove_hash,
|
2020-03-18 10:48:45 -05:00
|
|
|
remove_dbg::remove_dbg,
|
2020-02-19 05:44:20 -06:00
|
|
|
remove_mut::remove_mut,
|
2020-03-18 10:48:45 -05:00
|
|
|
replace_if_let_with_match::replace_if_let_with_match,
|
2020-03-27 06:12:17 -05:00
|
|
|
replace_let_with_if_let::replace_let_with_if_let,
|
2020-03-18 10:48:45 -05:00
|
|
|
replace_qualified_name_with_use::replace_qualified_name_with_use,
|
2020-03-26 04:16:10 -05:00
|
|
|
replace_unwrap_with_match::replace_unwrap_with_match,
|
2020-03-18 10:48:45 -05:00
|
|
|
split_import::split_import,
|
2020-04-01 16:26:41 -05:00
|
|
|
add_from_impl_for_enum::add_from_impl_for_enum,
|
2020-04-29 06:52:55 -05:00
|
|
|
unwrap_block::unwrap_block,
|
2020-04-09 03:00:27 -05:00
|
|
|
// These are manually sorted for better priorities
|
|
|
|
add_missing_impl_members::add_missing_impl_members,
|
|
|
|
add_missing_impl_members::add_missing_default_members,
|
2020-04-09 17:35:43 -05:00
|
|
|
reorder_fields::reorder_fields,
|
2019-09-25 06:29:41 -05:00
|
|
|
]
|
|
|
|
}
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod helpers {
|
2020-02-06 10:42:17 -06:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
|
|
|
|
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
|
2020-02-25 11:57:47 -06:00
|
|
|
use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset};
|
2019-02-03 12:26:35 -06:00
|
|
|
|
2020-04-20 11:02:36 -05:00
|
|
|
use crate::{AssistCtx, AssistFile, AssistHandler};
|
2020-02-18 11:35:10 -06:00
|
|
|
use hir::Semantics;
|
2019-02-03 12:26:35 -06:00
|
|
|
|
2020-02-06 10:42:17 -06:00
|
|
|
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
|
|
|
|
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? :(
|
2020-03-23 16:23:26 -05:00
|
|
|
db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)]));
|
2020-02-06 10:42:17 -06:00
|
|
|
(db, file_id)
|
|
|
|
}
|
|
|
|
|
2020-03-03 10:03:46 -06:00
|
|
|
pub(crate) fn check_assist(
|
|
|
|
assist: AssistHandler,
|
|
|
|
ra_fixture_before: &str,
|
|
|
|
ra_fixture_after: &str,
|
|
|
|
) {
|
|
|
|
check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after));
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
2020-02-25 11:57:47 -06:00
|
|
|
// FIXME: instead of having a separate function here, maybe use
|
|
|
|
// `extract_ranges` and mark the target as `<target> </target>` in the
|
|
|
|
// fixuture?
|
2020-03-03 09:56:42 -06:00
|
|
|
pub(crate) fn check_assist_target(assist: AssistHandler, ra_fixture: &str, target: &str) {
|
|
|
|
check(assist, ra_fixture, ExpectedResult::Target(target));
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|
|
|
|
|
2020-03-03 09:56:42 -06:00
|
|
|
pub(crate) fn check_assist_not_applicable(assist: AssistHandler, ra_fixture: &str) {
|
|
|
|
check(assist, ra_fixture, ExpectedResult::NotApplicable);
|
2020-02-25 11:57:47 -06:00
|
|
|
}
|
2019-02-08 17:34:05 -06:00
|
|
|
|
2020-02-25 11:57:47 -06:00
|
|
|
enum ExpectedResult<'a> {
|
|
|
|
NotApplicable,
|
|
|
|
After(&'a str),
|
|
|
|
Target(&'a str),
|
2019-02-08 17:34:05 -06:00
|
|
|
}
|
|
|
|
|
2020-02-25 11:57:47 -06:00
|
|
|
fn check(assist: AssistHandler, before: &str, expected: ExpectedResult) {
|
2020-03-23 16:23:26 -05:00
|
|
|
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() };
|
2020-02-25 11:57:47 -06:00
|
|
|
|
2020-02-18 11:35:10 -06:00
|
|
|
let sema = Semantics::new(&db);
|
|
|
|
let assist_ctx = AssistCtx::new(&sema, frange, true);
|
2019-02-08 17:34:05 -06:00
|
|
|
|
2020-02-25 11:57:47 -06:00
|
|
|
match (assist(assist_ctx), expected) {
|
|
|
|
(Some(assist), ExpectedResult::After(after)) => {
|
|
|
|
let action = assist.0[0].action.clone().unwrap();
|
2019-02-08 17:34:05 -06:00
|
|
|
|
2020-04-20 11:02:36 -05:00
|
|
|
let assisted_file_text = if let AssistFile::TargetFile(file_id) = action.file {
|
|
|
|
db.file_text(file_id).as_ref().to_owned()
|
|
|
|
} else {
|
|
|
|
text_without_caret
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut actual = action.edit.apply(&assisted_file_text);
|
2020-02-25 11:57:47 -06:00
|
|
|
match action.cursor_position {
|
|
|
|
None => {
|
|
|
|
if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {
|
|
|
|
let off = action
|
|
|
|
.edit
|
|
|
|
.apply_to_offset(before_cursor_pos)
|
|
|
|
.expect("cursor position is affected by the edit");
|
|
|
|
actual = add_cursor(&actual, off)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(off) => actual = add_cursor(&actual, off),
|
|
|
|
};
|
2019-12-23 18:19:09 -06:00
|
|
|
|
2020-02-25 11:57:47 -06:00
|
|
|
assert_eq_text!(after, &actual);
|
|
|
|
}
|
|
|
|
(Some(assist), ExpectedResult::Target(target)) => {
|
|
|
|
let action = assist.0[0].action.clone().unwrap();
|
|
|
|
let range = action.target.expect("expected target on action");
|
2020-03-23 16:23:26 -05:00
|
|
|
assert_eq_text!(&text_without_caret[range], target);
|
2020-02-25 11:57:47 -06:00
|
|
|
}
|
|
|
|
(Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),
|
|
|
|
(None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => {
|
|
|
|
panic!("code action is not applicable")
|
|
|
|
}
|
|
|
|
(None, ExpectedResult::NotApplicable) => (),
|
|
|
|
};
|
2019-02-24 05:18:10 -06:00
|
|
|
}
|
2019-02-08 15:43:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-02-06 10:42:17 -06:00
|
|
|
use ra_db::FileRange;
|
2019-07-04 15:05:17 -05:00
|
|
|
use ra_syntax::TextRange;
|
2019-02-24 05:18:10 -06:00
|
|
|
use test_utils::{extract_offset, extract_range};
|
2019-02-08 15:43:13 -06:00
|
|
|
|
2020-02-06 11:46:11 -06:00
|
|
|
use crate::{helpers, resolved_assists};
|
2019-11-04 13:28:47 -06:00
|
|
|
|
2019-02-08 15:43:13 -06:00
|
|
|
#[test]
|
2019-02-08 17:34:05 -06:00
|
|
|
fn assist_order_field_struct() {
|
2019-02-08 15:43:13 -06:00
|
|
|
let before = "struct Foo { <|>bar: u32 }";
|
|
|
|
let (before_cursor_pos, before) = extract_offset(before);
|
2020-02-06 10:42:17 -06:00
|
|
|
let (db, file_id) = helpers::with_single_file(&before);
|
2020-04-24 16:51:02 -05:00
|
|
|
let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
|
2020-02-06 11:46:11 -06:00
|
|
|
let assists = resolved_assists(&db, frange);
|
2019-02-08 15:43:13 -06:00
|
|
|
let mut assists = assists.iter();
|
|
|
|
|
2020-01-14 11:32:26 -06:00
|
|
|
assert_eq!(
|
2020-01-11 16:40:36 -06:00
|
|
|
assists.next().expect("expected assist").label.label,
|
2020-01-14 11:32:26 -06:00
|
|
|
"Change visibility to pub(crate)"
|
|
|
|
);
|
2020-01-11 16:40:36 -06:00
|
|
|
assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`");
|
2019-02-08 15:43:13 -06:00
|
|
|
}
|
2019-02-03 12:26:35 -06:00
|
|
|
|
2019-02-08 17:34:05 -06:00
|
|
|
#[test]
|
|
|
|
fn assist_order_if_expr() {
|
|
|
|
let before = "
|
|
|
|
pub fn test_some_range(a: int) -> bool {
|
2019-02-24 05:18:10 -06:00
|
|
|
if let 2..6 = <|>5<|> {
|
2019-02-08 17:34:05 -06:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}";
|
2019-02-24 05:18:10 -06:00
|
|
|
let (range, before) = extract_range(before);
|
2020-02-06 10:42:17 -06:00
|
|
|
let (db, file_id) = helpers::with_single_file(&before);
|
2019-02-24 05:18:10 -06:00
|
|
|
let frange = FileRange { file_id, range };
|
2020-02-06 11:46:11 -06:00
|
|
|
let assists = resolved_assists(&db, frange);
|
2019-02-08 17:34:05 -06:00
|
|
|
let mut assists = assists.iter();
|
|
|
|
|
2020-01-11 16:40:36 -06:00
|
|
|
assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable");
|
|
|
|
assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match");
|
2019-02-08 17:34:05 -06:00
|
|
|
}
|
2019-02-03 12:26:35 -06:00
|
|
|
}
|