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 11use hir:: HirDisplay ;
22use ide_db:: { base_db:: FileId , helpers:: SnippetCap } ;
33use rustc_hash:: { FxHashMap , FxHashSet } ;
4+ use stdx:: to_lower_snake_case;
45use syntax:: {
56 ast:: {
67 self ,
@@ -257,14 +258,15 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
257258fn fn_arg_name ( fn_arg : & ast:: Expr ) -> Option < String > {
258259 match fn_arg {
259260 ast:: Expr :: CastExpr ( cast_expr) => fn_arg_name ( & cast_expr. expr ( ) ?) ,
260- _ => Some (
261- fn_arg
261+ _ => {
262+ let s = fn_arg
262263 . syntax ( )
263264 . descendants ( )
264265 . filter ( |d| ast:: NameRef :: can_cast ( d. kind ( ) ) )
265266 . last ( ) ?
266- . to_string ( ) ,
267- ) ,
267+ . to_string ( ) ;
268+ Some ( to_lower_snake_case ( & s) )
269+ }
268270 }
269271}
270272
@@ -447,6 +449,52 @@ mod baz {
447449 )
448450 }
449451
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+
450498 #[ test]
451499 fn add_function_with_function_call_arg ( ) {
452500 check_assist (
You can’t perform that action at this time.
0 commit comments