|
1 |
| -use hir::{HasSource, HirDisplay, Module, ModuleDef, TypeInfo}; |
| 1 | +use hir::{HasSource, HirDisplay, Module, ModuleDef, Semantics, TypeInfo}; |
2 | 2 | use ide_db::{
|
3 | 3 | base_db::FileId,
|
4 | 4 | defs::{Definition, NameRefClass},
|
5 | 5 | helpers::SnippetCap,
|
| 6 | + RootDatabase, |
6 | 7 | };
|
7 | 8 | use rustc_hash::{FxHashMap, FxHashSet};
|
8 | 9 | use stdx::to_lower_snake_case;
|
@@ -442,7 +443,7 @@ fn fn_args(
|
442 | 443 | let mut arg_names = Vec::new();
|
443 | 444 | let mut arg_types = Vec::new();
|
444 | 445 | for arg in call.arg_list()?.args() {
|
445 |
| - arg_names.push(fn_arg_name(ctx, &arg)); |
| 446 | + arg_names.push(fn_arg_name(&ctx.sema, &arg)); |
446 | 447 | arg_types.push(match fn_arg_type(ctx, target_module, &arg) {
|
447 | 448 | Some(ty) => {
|
448 | 449 | if !ty.is_empty() && ty.starts_with('&') {
|
@@ -507,23 +508,16 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
|
507 | 508 | }
|
508 | 509 | }
|
509 | 510 |
|
510 |
| -fn fn_arg_name(ctx: &AssistContext, arg_expr: &ast::Expr) -> String { |
| 511 | +fn fn_arg_name(sema: &Semantics<RootDatabase>, arg_expr: &ast::Expr) -> String { |
511 | 512 | let name = (|| match arg_expr {
|
512 |
| - ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(ctx, &cast_expr.expr()?)), |
| 513 | + ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)), |
513 | 514 | expr => {
|
514 | 515 | let name_ref = expr.syntax().descendants().filter_map(ast::NameRef::cast).last()?;
|
515 |
| - if let Some(NameRefClass::Definition(def)) = |
516 |
| - NameRefClass::classify(&ctx.sema, &name_ref) |
| 516 | + if let Some(NameRefClass::Definition(Definition::ModuleDef( |
| 517 | + ModuleDef::Const(_) | ModuleDef::Static(_), |
| 518 | + ))) = NameRefClass::classify(sema, &name_ref) |
517 | 519 | {
|
518 |
| - match def { |
519 |
| - Definition::ModuleDef(ModuleDef::Const(_)) => { |
520 |
| - return Some(name_ref.to_string().to_lowercase()); |
521 |
| - } |
522 |
| - Definition::ModuleDef(ModuleDef::Static(_)) => { |
523 |
| - return Some(name_ref.to_string().to_lowercase()); |
524 |
| - } |
525 |
| - _ => {} |
526 |
| - } |
| 520 | + return Some(name_ref.to_string().to_lowercase()); |
527 | 521 | };
|
528 | 522 | Some(to_lower_snake_case(&name_ref.to_string()))
|
529 | 523 | }
|
|
0 commit comments