mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 21:05:13 +00:00
Rename assist: convert_ufcs_to_method
=> unqualify_method_call
This commit is contained in:
parent
44c84a8d28
commit
c782353a90
3 changed files with 39 additions and 39 deletions
|
@ -5,7 +5,7 @@ use syntax::{
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
// Assist: convert_ufcs_to_method
|
// Assist: unqualify_method_call
|
||||||
//
|
//
|
||||||
// Transforms universal function call syntax into a method call.
|
// Transforms universal function call syntax into a method call.
|
||||||
//
|
//
|
||||||
|
@ -22,7 +22,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
// }
|
// }
|
||||||
// # mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
// # mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn convert_ufcs_to_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn unqualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let call = ctx.find_node_at_offset::<ast::CallExpr>()?;
|
let call = ctx.find_node_at_offset::<ast::CallExpr>()?;
|
||||||
let ast::Expr::PathExpr(path_expr) = call.expr()? else { return None };
|
let ast::Expr::PathExpr(path_expr) = call.expr()? else { return None };
|
||||||
let path = path_expr.path()?;
|
let path = path_expr.path()?;
|
||||||
|
@ -66,8 +66,8 @@ pub(crate) fn convert_ufcs_to_method(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||||
);
|
);
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("convert_ufcs_to_method", AssistKind::RefactorRewrite),
|
AssistId("unqualify_method_call", AssistKind::RefactorRewrite),
|
||||||
"Convert UFCS to a method call",
|
"Unqualify method call",
|
||||||
call.syntax().text_range(),
|
call.syntax().text_range(),
|
||||||
|edit| {
|
|edit| {
|
||||||
edit.delete(delete_path);
|
edit.delete(delete_path);
|
||||||
|
@ -105,9 +105,9 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_simple() {
|
fn unqualify_method_call_simple() {
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
struct S;
|
struct S;
|
||||||
impl S { fn f(self, S: S) {} }
|
impl S { fn f(self, S: S) {} }
|
||||||
|
@ -120,9 +120,9 @@ fn f() { S.f(S); }"#,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_trait() {
|
fn unqualify_method_call_trait() {
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
//- minicore: add
|
//- minicore: add
|
||||||
fn f() { <u32 as core::ops::Add>::$0add(2, 2); }"#,
|
fn f() { <u32 as core::ops::Add>::$0add(2, 2); }"#,
|
||||||
|
@ -131,7 +131,7 @@ fn f() { 2.add(2); }"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
//- minicore: add
|
//- minicore: add
|
||||||
fn f() { core::ops::Add::$0add(2, 2); }"#,
|
fn f() { core::ops::Add::$0add(2, 2); }"#,
|
||||||
|
@ -140,7 +140,7 @@ fn f() { 2.add(2); }"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
//- minicore: add
|
//- minicore: add
|
||||||
use core::ops::Add;
|
use core::ops::Add;
|
||||||
|
@ -152,9 +152,9 @@ fn f() { 2.add(2); }"#,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_single_arg() {
|
fn unqualify_method_call_single_arg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
struct S;
|
struct S;
|
||||||
impl S { fn f(self) {} }
|
impl S { fn f(self) {} }
|
||||||
|
@ -167,9 +167,9 @@ fn f() { 2.add(2); }"#,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_parens() {
|
fn unqualify_method_call_parens() {
|
||||||
check_assist(
|
check_assist(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
//- minicore: deref
|
//- minicore: deref
|
||||||
struct S;
|
struct S;
|
||||||
|
@ -189,9 +189,9 @@ fn f() { (&S).deref(); }"#,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_doesnt_apply_with_cursor_not_on_path() {
|
fn unqualify_method_call_doesnt_apply_with_cursor_not_on_path() {
|
||||||
check_assist_not_applicable(
|
check_assist_not_applicable(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
//- minicore: add
|
//- minicore: add
|
||||||
fn f() { core::ops::Add::add(2,$0 2); }"#,
|
fn f() { core::ops::Add::add(2,$0 2); }"#,
|
||||||
|
@ -199,9 +199,9 @@ fn f() { core::ops::Add::add(2,$0 2); }"#,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ufcs2method_doesnt_apply_with_no_self() {
|
fn unqualify_method_call_doesnt_apply_with_no_self() {
|
||||||
check_assist_not_applicable(
|
check_assist_not_applicable(
|
||||||
convert_ufcs_to_method,
|
unqualify_method_call,
|
||||||
r#"
|
r#"
|
||||||
struct S;
|
struct S;
|
||||||
impl S { fn assoc(S: S, S: S) {} }
|
impl S { fn assoc(S: S, S: S) {} }
|
|
@ -126,7 +126,6 @@ mod handlers {
|
||||||
mod convert_to_guarded_return;
|
mod convert_to_guarded_return;
|
||||||
mod convert_two_arm_bool_match_to_matches_macro;
|
mod convert_two_arm_bool_match_to_matches_macro;
|
||||||
mod convert_while_to_loop;
|
mod convert_while_to_loop;
|
||||||
mod convert_ufcs_to_method;
|
|
||||||
mod destructure_tuple_binding;
|
mod destructure_tuple_binding;
|
||||||
mod expand_glob_import;
|
mod expand_glob_import;
|
||||||
mod extract_expressions_from_format_string;
|
mod extract_expressions_from_format_string;
|
||||||
|
@ -202,6 +201,7 @@ mod handlers {
|
||||||
mod unnecessary_async;
|
mod unnecessary_async;
|
||||||
mod unwrap_block;
|
mod unwrap_block;
|
||||||
mod unwrap_result_return_type;
|
mod unwrap_result_return_type;
|
||||||
|
mod unqualify_method_call;
|
||||||
mod wrap_return_type_in_result;
|
mod wrap_return_type_in_result;
|
||||||
|
|
||||||
pub(crate) fn all() -> &'static [Handler] {
|
pub(crate) fn all() -> &'static [Handler] {
|
||||||
|
@ -219,7 +219,6 @@ mod handlers {
|
||||||
convert_bool_then::convert_bool_then_to_if,
|
convert_bool_then::convert_bool_then_to_if,
|
||||||
convert_bool_then::convert_if_to_bool_then,
|
convert_bool_then::convert_if_to_bool_then,
|
||||||
convert_comment_block::convert_comment_block,
|
convert_comment_block::convert_comment_block,
|
||||||
convert_ufcs_to_method::convert_ufcs_to_method,
|
|
||||||
convert_integer_literal::convert_integer_literal,
|
convert_integer_literal::convert_integer_literal,
|
||||||
convert_into_to_from::convert_into_to_from,
|
convert_into_to_from::convert_into_to_from,
|
||||||
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
|
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
|
||||||
|
@ -308,6 +307,7 @@ mod handlers {
|
||||||
unwrap_block::unwrap_block,
|
unwrap_block::unwrap_block,
|
||||||
unwrap_result_return_type::unwrap_result_return_type,
|
unwrap_result_return_type::unwrap_result_return_type,
|
||||||
unwrap_tuple::unwrap_tuple,
|
unwrap_tuple::unwrap_tuple,
|
||||||
|
unqualify_method_call::unqualify_method_call,
|
||||||
wrap_return_type_in_result::wrap_return_type_in_result,
|
wrap_return_type_in_result::wrap_return_type_in_result,
|
||||||
// These are manually sorted for better priorities. By default,
|
// These are manually sorted for better priorities. By default,
|
||||||
// priority is determined by the size of the target range (smaller
|
// priority is determined by the size of the target range (smaller
|
||||||
|
|
|
@ -554,25 +554,6 @@ fn main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn doctest_convert_ufcs_to_method() {
|
|
||||||
check_doc_test(
|
|
||||||
"convert_ufcs_to_method",
|
|
||||||
r#####"
|
|
||||||
fn main() {
|
|
||||||
std::ops::Add::add$0(1, 2);
|
|
||||||
}
|
|
||||||
mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
|
||||||
"#####,
|
|
||||||
r#####"
|
|
||||||
fn main() {
|
|
||||||
1.add(2);
|
|
||||||
}
|
|
||||||
mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
|
||||||
"#####,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn doctest_convert_while_to_loop() {
|
fn doctest_convert_while_to_loop() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
|
@ -2552,6 +2533,25 @@ pub async fn bar() { foo() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn doctest_unqualify_method_call() {
|
||||||
|
check_doc_test(
|
||||||
|
"unqualify_method_call",
|
||||||
|
r#####"
|
||||||
|
fn main() {
|
||||||
|
std::ops::Add::add$0(1, 2);
|
||||||
|
}
|
||||||
|
mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
||||||
|
"#####,
|
||||||
|
r#####"
|
||||||
|
fn main() {
|
||||||
|
1.add(2);
|
||||||
|
}
|
||||||
|
mod std { pub mod ops { pub trait Add { fn add(self, _: Self) {} } impl Add for i32 {} } }
|
||||||
|
"#####,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn doctest_unwrap_block() {
|
fn doctest_unwrap_block() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
|
|
Loading…
Reference in a new issue