From 949c580d1bc5bcf6d8bc1bec1c85f879166f7d73 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 9 Nov 2020 19:06:11 +0100 Subject: [PATCH 1/2] Add multiple file edit tes to remove_unused_param assist --- .../src/handlers/remove_unused_param.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/assists/src/handlers/remove_unused_param.rs b/crates/assists/src/handlers/remove_unused_param.rs index 5fccca54b80..a4bbf2e9e98 100644 --- a/crates/assists/src/handlers/remove_unused_param.rs +++ b/crates/assists/src/handlers/remove_unused_param.rs @@ -128,4 +128,37 @@ fn main() { foo(9, 2) } "#, ); } + + #[test] + fn remove_across_files() { + check_assist( + remove_unused_param, + r#" +//- /main.rs +fn foo(x: i32, <|>y: i32) { x; } + +mod foo; + +//- /foo.rs +use super::foo; + +fn bar() { + let _ = foo(1, 2); +} +"#, + r#" +//- /main.rs +fn foo(x: i32) { x; } + +mod foo; + +//- /foo.rs +use super::foo; + +fn bar() { + let _ = foo(1); +} +"#, + ) + } } From b6e2b28353ac5b630521d40e3bd31a8c3f530583 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 9 Nov 2020 19:18:26 +0100 Subject: [PATCH 2/2] Support qualified function calls in remove_unused_param --- .../src/handlers/remove_unused_param.rs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/crates/assists/src/handlers/remove_unused_param.rs b/crates/assists/src/handlers/remove_unused_param.rs index a4bbf2e9e98..1ff5e92b04f 100644 --- a/crates/assists/src/handlers/remove_unused_param.rs +++ b/crates/assists/src/handlers/remove_unused_param.rs @@ -73,7 +73,8 @@ fn process_usage( let source_file = ctx.sema.parse(usage.file_range.file_id); let call_expr: ast::CallExpr = find_node_at_range(source_file.syntax(), usage.file_range.range)?; - if call_expr.expr()?.syntax().text_range() != usage.file_range.range { + let call_expr_range = call_expr.expr()?.syntax().text_range(); + if !call_expr_range.contains_range(usage.file_range.range) { return None; } let arg = call_expr.arg_list()?.args().nth(arg_to_remove)?; @@ -117,6 +118,53 @@ fn b() { foo(9, ) } ); } + #[test] + fn remove_unused_qualified_call() { + check_assist( + remove_unused_param, + r#" +mod bar { pub fn foo(x: i32, <|>y: i32) { x; } } +fn b() { bar::foo(9, 2) } +"#, + r#" +mod bar { pub fn foo(x: i32) { x; } } +fn b() { bar::foo(9) } +"#, + ); + } + + #[test] + fn remove_unused_turbofished_func() { + check_assist( + remove_unused_param, + r#" +pub fn foo(x: T, <|>y: i32) { x; } +fn b() { foo::(9, 2) } +"#, + r#" +pub fn foo(x: T) { x; } +fn b() { foo::(9) } +"#, + ); + } + + #[test] + fn remove_unused_generic_unused_param_func() { + check_assist( + remove_unused_param, + r#" +pub fn foo(x: i32, <|>y: T) { x; } +fn b() { foo::(9, 2) } +fn b2() { foo(9, 2) } +"#, + r#" +pub fn foo(x: i32) { x; } +fn b() { foo::(9) } +fn b2() { foo(9) } +"#, + ); + } + #[test] fn keep_used() { mark::check!(keep_used);