fix: rename to extract_expressions_from_format_string
This commit is contained in:
parent
25717af4aa
commit
9290399ec4
@ -10,7 +10,7 @@ use itertools::Itertools;
|
|||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
|
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.
|
// 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 fmt_string = ctx.find_token_at_offset::<ast::String>()?;
|
||||||
let tt = fmt_string.syntax().parent().and_then(ast::TokenTree::cast)?;
|
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(
|
acc.add(
|
||||||
AssistId(
|
AssistId(
|
||||||
"move_format_string_arg",
|
"extract_expressions_from_format_string",
|
||||||
// if there aren't any expressions, then make the assist a RefactorExtract
|
// if there aren't any expressions, then make the assist a RefactorExtract
|
||||||
if extracted_args.iter().filter(|f| matches!(f, Arg::Expr(_))).count() == 0 {
|
if extracted_args.iter().filter(|f| matches!(f, Arg::Expr(_))).count() == 0 {
|
||||||
AssistKind::RefactorExtract
|
AssistKind::RefactorExtract
|
||||||
@ -171,7 +174,7 @@ macro_rules! print {
|
|||||||
#[test]
|
#[test]
|
||||||
fn multiple_middle_arg() {
|
fn multiple_middle_arg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -192,7 +195,7 @@ fn main() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn single_arg() {
|
fn single_arg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -213,7 +216,7 @@ fn main() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn multiple_middle_placeholders_arg() {
|
fn multiple_middle_placeholders_arg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -234,7 +237,7 @@ fn main() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn multiple_trailing_args() {
|
fn multiple_trailing_args() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -255,7 +258,7 @@ fn main() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn improper_commas() {
|
fn improper_commas() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -276,7 +279,7 @@ fn main() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn nested_tt() {
|
fn nested_tt() {
|
||||||
check_assist(
|
check_assist(
|
||||||
move_format_string_arg,
|
extract_expressions_from_format_string,
|
||||||
&add_macro_decl(
|
&add_macro_decl(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
@ -138,7 +138,7 @@ mod handlers {
|
|||||||
mod flip_binexpr;
|
mod flip_binexpr;
|
||||||
mod flip_comma;
|
mod flip_comma;
|
||||||
mod flip_trait_bound;
|
mod flip_trait_bound;
|
||||||
mod move_format_string_arg;
|
mod extract_expressions_from_format_string;
|
||||||
mod generate_constant;
|
mod generate_constant;
|
||||||
mod generate_default_from_enum_variant;
|
mod generate_default_from_enum_variant;
|
||||||
mod generate_default_from_new;
|
mod generate_default_from_new;
|
||||||
@ -230,6 +230,7 @@ mod handlers {
|
|||||||
convert_while_to_loop::convert_while_to_loop,
|
convert_while_to_loop::convert_while_to_loop,
|
||||||
destructure_tuple_binding::destructure_tuple_binding,
|
destructure_tuple_binding::destructure_tuple_binding,
|
||||||
expand_glob_import::expand_glob_import,
|
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_struct_from_enum_variant::extract_struct_from_enum_variant,
|
||||||
extract_type_alias::extract_type_alias,
|
extract_type_alias::extract_type_alias,
|
||||||
fix_visibility::fix_visibility,
|
fix_visibility::fix_visibility,
|
||||||
@ -264,7 +265,6 @@ mod handlers {
|
|||||||
merge_match_arms::merge_match_arms,
|
merge_match_arms::merge_match_arms,
|
||||||
move_bounds::move_bounds_to_where_clause,
|
move_bounds::move_bounds_to_where_clause,
|
||||||
move_const_to_impl::move_const_to_impl,
|
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_arm_cond_to_match_guard,
|
||||||
move_guard::move_guard_to_arm_body,
|
move_guard::move_guard_to_arm_body,
|
||||||
move_module_to_file::move_module_to_file,
|
move_module_to_file::move_module_to_file,
|
||||||
|
@ -624,6 +624,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]
|
#[test]
|
||||||
fn doctest_extract_function() {
|
fn doctest_extract_function() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
@ -1703,37 +1734,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]
|
#[test]
|
||||||
fn doctest_move_from_mod_rs() {
|
fn doctest_move_from_mod_rs() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user