Unnamed repository; edit this file 'description' to name the repository.
fix: rename to extract_expressions_from_format_string
unvalley 2023-01-09
parent 25717af · commit 9290399
-rw-r--r--crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs (renamed from crates/ide-assists/src/handlers/move_format_string_arg.rs)21
-rw-r--r--crates/ide-assists/src/lib.rs4
-rw-r--r--crates/ide-assists/src/tests/generated.rs62
3 files changed, 45 insertions, 42 deletions
diff --git a/crates/ide-assists/src/handlers/move_format_string_arg.rs b/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs
index 11db6ae7f7..b1bc2a9e6d 100644
--- a/crates/ide-assists/src/handlers/move_format_string_arg.rs
+++ b/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs
@@ -10,7 +10,7 @@ use itertools::Itertools;
use stdx::format_to;
use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
-// Assist: move_format_string_arg
+// Assist: extract_expressions_from_format_string
//
// Move an expression out of a format string.
//
@@ -40,7 +40,10 @@ use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
// }
// ```
-pub(crate) fn move_format_string_arg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
+pub(crate) fn extract_expressions_from_format_string(
+ acc: &mut Assists,
+ ctx: &AssistContext<'_>,
+) -> Option<()> {
let fmt_string = ctx.find_token_at_offset::<ast::String>()?;
let tt = fmt_string.syntax().parent().and_then(ast::TokenTree::cast)?;
@@ -58,7 +61,7 @@ pub(crate) fn move_format_string_arg(acc: &mut Assists, ctx: &AssistContext<'_>)
acc.add(
AssistId(
- "move_format_string_arg",
+ "extract_expressions_from_format_string",
// if there aren't any expressions, then make the assist a RefactorExtract
if extracted_args.iter().filter(|f| matches!(f, Arg::Expr(_))).count() == 0 {
AssistKind::RefactorExtract
@@ -171,7 +174,7 @@ macro_rules! print {
#[test]
fn multiple_middle_arg() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
@@ -192,7 +195,7 @@ fn main() {
#[test]
fn single_arg() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
@@ -213,7 +216,7 @@ fn main() {
#[test]
fn multiple_middle_placeholders_arg() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
@@ -234,7 +237,7 @@ fn main() {
#[test]
fn multiple_trailing_args() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
@@ -255,7 +258,7 @@ fn main() {
#[test]
fn improper_commas() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
@@ -276,7 +279,7 @@ fn main() {
#[test]
fn nested_tt() {
check_assist(
- move_format_string_arg,
+ extract_expressions_from_format_string,
&add_macro_decl(
r#"
fn main() {
diff --git a/crates/ide-assists/src/lib.rs b/crates/ide-assists/src/lib.rs
index 8b1247c640..0bf502fdbc 100644
--- a/crates/ide-assists/src/lib.rs
+++ b/crates/ide-assists/src/lib.rs
@@ -138,7 +138,7 @@ mod handlers {
mod flip_binexpr;
mod flip_comma;
mod flip_trait_bound;
- mod move_format_string_arg;
+ mod extract_expressions_from_format_string;
mod generate_constant;
mod generate_default_from_enum_variant;
mod generate_default_from_new;
@@ -230,6 +230,7 @@ mod handlers {
convert_while_to_loop::convert_while_to_loop,
destructure_tuple_binding::destructure_tuple_binding,
expand_glob_import::expand_glob_import,
+ extract_expressions_from_format_string::extract_expressions_from_format_string,
extract_struct_from_enum_variant::extract_struct_from_enum_variant,
extract_type_alias::extract_type_alias,
fix_visibility::fix_visibility,
@@ -264,7 +265,6 @@ mod handlers {
merge_match_arms::merge_match_arms,
move_bounds::move_bounds_to_where_clause,
move_const_to_impl::move_const_to_impl,
- move_format_string_arg::move_format_string_arg,
move_guard::move_arm_cond_to_match_guard,
move_guard::move_guard_to_arm_body,
move_module_to_file::move_module_to_file,
diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs
index 80b8c27c7c..5e24de6207 100644
--- a/crates/ide-assists/src/tests/generated.rs
+++ b/crates/ide-assists/src/tests/generated.rs
@@ -625,6 +625,37 @@ fn qux(bar: Bar, baz: Baz) {}
}
#[test]
+fn doctest_extract_expressions_from_format_string() {
+ check_doc_test(
+ "extract_expressions_from_format_string",
+ r#####"
+macro_rules! format_args {
+ ($lit:literal $(tt:tt)*) => { 0 },
+}
+macro_rules! print {
+ ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+}
+
+fn main() {
+ print!("{x + 1}$0");
+}
+"#####,
+ r#####"
+macro_rules! format_args {
+ ($lit:literal $(tt:tt)*) => { 0 },
+}
+macro_rules! print {
+ ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+}
+
+fn main() {
+ print!("{}"$0, x + 1);
+}
+"#####,
+ )
+}
+
+#[test]
fn doctest_extract_function() {
check_doc_test(
"extract_function",
@@ -1704,37 +1735,6 @@ impl S {
}
#[test]
-fn doctest_move_format_string_arg() {
- check_doc_test(
- "move_format_string_arg",
- r#####"
-macro_rules! format_args {
- ($lit:literal $(tt:tt)*) => { 0 },
-}
-macro_rules! print {
- ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
-}
-
-fn main() {
- print!("{x + 1}$0");
-}
-"#####,
- r#####"
-macro_rules! format_args {
- ($lit:literal $(tt:tt)*) => { 0 },
-}
-macro_rules! print {
- ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
-}
-
-fn main() {
- print!("{}"$0, x + 1);
-}
-"#####,
- )
-}
-
-#[test]
fn doctest_move_from_mod_rs() {
check_doc_test(
"move_from_mod_rs",