Skip to content

Commit 9290399

Browse files
unvalleyVeykril
authored andcommitted
fix: rename to extract_expressions_from_format_string
1 parent 25717af commit 9290399

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

crates/ide-assists/src/handlers/move_format_string_arg.rs renamed to crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use itertools::Itertools;
1010
use stdx::format_to;
1111
use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
1212

13-
// Assist: move_format_string_arg
13+
// Assist: extract_expressions_from_format_string
1414
//
1515
// Move an expression out of a format string.
1616
//
@@ -40,7 +40,10 @@ use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
4040
// }
4141
// ```
4242

43-
pub(crate) fn move_format_string_arg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
43+
pub(crate) fn extract_expressions_from_format_string(
44+
acc: &mut Assists,
45+
ctx: &AssistContext<'_>,
46+
) -> Option<()> {
4447
let fmt_string = ctx.find_token_at_offset::<ast::String>()?;
4548
let tt = fmt_string.syntax().parent().and_then(ast::TokenTree::cast)?;
4649

@@ -58,7 +61,7 @@ pub(crate) fn move_format_string_arg(acc: &mut Assists, ctx: &AssistContext<'_>)
5861

5962
acc.add(
6063
AssistId(
61-
"move_format_string_arg",
64+
"extract_expressions_from_format_string",
6265
// if there aren't any expressions, then make the assist a RefactorExtract
6366
if extracted_args.iter().filter(|f| matches!(f, Arg::Expr(_))).count() == 0 {
6467
AssistKind::RefactorExtract
@@ -171,7 +174,7 @@ macro_rules! print {
171174
#[test]
172175
fn multiple_middle_arg() {
173176
check_assist(
174-
move_format_string_arg,
177+
extract_expressions_from_format_string,
175178
&add_macro_decl(
176179
r#"
177180
fn main() {
@@ -192,7 +195,7 @@ fn main() {
192195
#[test]
193196
fn single_arg() {
194197
check_assist(
195-
move_format_string_arg,
198+
extract_expressions_from_format_string,
196199
&add_macro_decl(
197200
r#"
198201
fn main() {
@@ -213,7 +216,7 @@ fn main() {
213216
#[test]
214217
fn multiple_middle_placeholders_arg() {
215218
check_assist(
216-
move_format_string_arg,
219+
extract_expressions_from_format_string,
217220
&add_macro_decl(
218221
r#"
219222
fn main() {
@@ -234,7 +237,7 @@ fn main() {
234237
#[test]
235238
fn multiple_trailing_args() {
236239
check_assist(
237-
move_format_string_arg,
240+
extract_expressions_from_format_string,
238241
&add_macro_decl(
239242
r#"
240243
fn main() {
@@ -255,7 +258,7 @@ fn main() {
255258
#[test]
256259
fn improper_commas() {
257260
check_assist(
258-
move_format_string_arg,
261+
extract_expressions_from_format_string,
259262
&add_macro_decl(
260263
r#"
261264
fn main() {
@@ -276,7 +279,7 @@ fn main() {
276279
#[test]
277280
fn nested_tt() {
278281
check_assist(
279-
move_format_string_arg,
282+
extract_expressions_from_format_string,
280283
&add_macro_decl(
281284
r#"
282285
fn main() {

crates/ide-assists/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod handlers {
138138
mod flip_binexpr;
139139
mod flip_comma;
140140
mod flip_trait_bound;
141-
mod move_format_string_arg;
141+
mod extract_expressions_from_format_string;
142142
mod generate_constant;
143143
mod generate_default_from_enum_variant;
144144
mod generate_default_from_new;
@@ -230,6 +230,7 @@ mod handlers {
230230
convert_while_to_loop::convert_while_to_loop,
231231
destructure_tuple_binding::destructure_tuple_binding,
232232
expand_glob_import::expand_glob_import,
233+
extract_expressions_from_format_string::extract_expressions_from_format_string,
233234
extract_struct_from_enum_variant::extract_struct_from_enum_variant,
234235
extract_type_alias::extract_type_alias,
235236
fix_visibility::fix_visibility,
@@ -264,7 +265,6 @@ mod handlers {
264265
merge_match_arms::merge_match_arms,
265266
move_bounds::move_bounds_to_where_clause,
266267
move_const_to_impl::move_const_to_impl,
267-
move_format_string_arg::move_format_string_arg,
268268
move_guard::move_arm_cond_to_match_guard,
269269
move_guard::move_guard_to_arm_body,
270270
move_module_to_file::move_module_to_file,

crates/ide-assists/src/tests/generated.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,37 @@ fn qux(bar: Bar, baz: Baz) {}
624624
)
625625
}
626626

627+
#[test]
628+
fn doctest_extract_expressions_from_format_string() {
629+
check_doc_test(
630+
"extract_expressions_from_format_string",
631+
r#####"
632+
macro_rules! format_args {
633+
($lit:literal $(tt:tt)*) => { 0 },
634+
}
635+
macro_rules! print {
636+
($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
637+
}
638+
639+
fn main() {
640+
print!("{x + 1}$0");
641+
}
642+
"#####,
643+
r#####"
644+
macro_rules! format_args {
645+
($lit:literal $(tt:tt)*) => { 0 },
646+
}
647+
macro_rules! print {
648+
($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
649+
}
650+
651+
fn main() {
652+
print!("{}"$0, x + 1);
653+
}
654+
"#####,
655+
)
656+
}
657+
627658
#[test]
628659
fn doctest_extract_function() {
629660
check_doc_test(
@@ -1703,37 +1734,6 @@ impl S {
17031734
)
17041735
}
17051736

1706-
#[test]
1707-
fn doctest_move_format_string_arg() {
1708-
check_doc_test(
1709-
"move_format_string_arg",
1710-
r#####"
1711-
macro_rules! format_args {
1712-
($lit:literal $(tt:tt)*) => { 0 },
1713-
}
1714-
macro_rules! print {
1715-
($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
1716-
}
1717-
1718-
fn main() {
1719-
print!("{x + 1}$0");
1720-
}
1721-
"#####,
1722-
r#####"
1723-
macro_rules! format_args {
1724-
($lit:literal $(tt:tt)*) => { 0 },
1725-
}
1726-
macro_rules! print {
1727-
($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
1728-
}
1729-
1730-
fn main() {
1731-
print!("{}"$0, x + 1);
1732-
}
1733-
"#####,
1734-
)
1735-
}
1736-
17371737
#[test]
17381738
fn doctest_move_from_mod_rs() {
17391739
check_doc_test(

0 commit comments

Comments
 (0)