From f915ab79fa1b11982b8e82e2db5b2486a893bed4 Mon Sep 17 00:00:00 2001 From: Vladyslav Katasonov Date: Tue, 16 Feb 2021 05:55:47 +0300 Subject: suggest parameter name before function name --- crates/ide_assists/src/handlers/extract_variable.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ide_assists/src') diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs index 32e54fd57..2c47be987 100644 --- a/crates/ide_assists/src/handlers/extract_variable.rs +++ b/crates/ide_assists/src/handlers/extract_variable.rs @@ -176,9 +176,9 @@ impl Anchor { fn suggest_variable_name(ctx: &AssistContext, expr: &ast::Expr) -> String { // FIXME: account for existing names in the scope - suggest_name_from_func(expr) + suggest_name_from_param(ctx, expr) + .or_else(|| suggest_name_from_func(expr)) .or_else(|| suggest_name_from_method(expr)) - .or_else(|| suggest_name_from_param(ctx, expr)) .or_else(|| suggest_name_by_type(ctx, expr)) .unwrap_or_else(|| "var_name".to_string()) } @@ -815,7 +815,7 @@ fn foo() { } #[test] - fn extract_var_function_name_has_precedence() { + fn extract_var_parameter_name_has_precedence_over_function() { check_assist( extract_variable, r#" @@ -829,8 +829,8 @@ fn foo() { fn bar(test: u32, size: u32) fn foo() { - let $0symbol_size = symbol_size(1, 2); - bar(1, symbol_size); + let $0size = symbol_size(1, 2); + bar(1, size); } "#, ) -- cgit v1.2.3