File tree Expand file tree Collapse file tree 1 file changed +52
-4
lines changed
crates/ide_assists/src/handlers Expand file tree Collapse file tree 1 file changed +52
-4
lines changed Original file line number Diff line number Diff line change 1
1
use hir:: HirDisplay ;
2
2
use ide_db:: { base_db:: FileId , helpers:: SnippetCap } ;
3
3
use rustc_hash:: { FxHashMap , FxHashSet } ;
4
+ use stdx:: to_lower_snake_case;
4
5
use syntax:: {
5
6
ast:: {
6
7
self ,
@@ -257,14 +258,15 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
257
258
fn fn_arg_name ( fn_arg : & ast:: Expr ) -> Option < String > {
258
259
match fn_arg {
259
260
ast:: Expr :: CastExpr ( cast_expr) => fn_arg_name ( & cast_expr. expr ( ) ?) ,
260
- _ => Some (
261
- fn_arg
261
+ _ => {
262
+ let s = fn_arg
262
263
. syntax ( )
263
264
. descendants ( )
264
265
. filter ( |d| ast:: NameRef :: can_cast ( d. kind ( ) ) )
265
266
. last ( ) ?
266
- . to_string ( ) ,
267
- ) ,
267
+ . to_string ( ) ;
268
+ Some ( to_lower_snake_case ( & s) )
269
+ }
268
270
}
269
271
}
270
272
@@ -447,6 +449,52 @@ mod baz {
447
449
)
448
450
}
449
451
452
+ #[ test]
453
+ fn add_function_with_upper_camel_case_arg ( ) {
454
+ check_assist (
455
+ generate_function,
456
+ r"
457
+ struct BazBaz;
458
+ fn foo() {
459
+ bar$0(BazBaz);
460
+ }
461
+ " ,
462
+ r"
463
+ struct BazBaz;
464
+ fn foo() {
465
+ bar(BazBaz);
466
+ }
467
+
468
+ fn bar(baz_baz: BazBaz) ${0:-> ()} {
469
+ todo!()
470
+ }
471
+ " ,
472
+ ) ;
473
+ }
474
+
475
+ #[ test]
476
+ fn add_function_with_upper_camel_case_arg_as_cast ( ) {
477
+ check_assist (
478
+ generate_function,
479
+ r"
480
+ struct BazBaz;
481
+ fn foo() {
482
+ bar$0(&BazBaz as *const BazBaz);
483
+ }
484
+ " ,
485
+ r"
486
+ struct BazBaz;
487
+ fn foo() {
488
+ bar(&BazBaz as *const BazBaz);
489
+ }
490
+
491
+ fn bar(baz_baz: *const BazBaz) ${0:-> ()} {
492
+ todo!()
493
+ }
494
+ " ,
495
+ ) ;
496
+ }
497
+
450
498
#[ test]
451
499
fn add_function_with_function_call_arg ( ) {
452
500
check_assist (
You can’t perform that action at this time.
0 commit comments