@@ -491,14 +491,24 @@ fn format_function(id: FuncId, args: &ProcessRequestCallbackArgs) -> String {
491
491
string. push ( '(' ) ;
492
492
let parameters = & func_meta. parameters ;
493
493
for ( index, ( pattern, typ, visibility) ) in parameters. iter ( ) . enumerate ( ) {
494
+ let is_self = pattern_is_self ( pattern, args. interner ) ;
495
+
496
+ // `&mut self` is represented as a mutable reference type, not as a mutable pattern
497
+ if is_self && matches ! ( typ, Type :: MutableReference ( ..) ) {
498
+ string. push_str ( "&mut " ) ;
499
+ }
500
+
494
501
format_pattern ( pattern, args. interner , & mut string) ;
495
- if !pattern_is_self ( pattern, args. interner ) {
502
+
503
+ // Don't add type for `self` param
504
+ if !is_self {
496
505
string. push_str ( ": " ) ;
497
506
if matches ! ( visibility, Visibility :: Public ) {
498
507
string. push_str ( "pub " ) ;
499
508
}
500
509
string. push_str ( & format ! ( "{}" , typ) ) ;
501
510
}
511
+
502
512
if index != parameters. len ( ) - 1 {
503
513
string. push_str ( ", " ) ;
504
514
}
@@ -1238,4 +1248,12 @@ mod hover_tests {
1238
1248
. await ;
1239
1249
assert ! ( hover_text. contains( "Some docs" ) ) ;
1240
1250
}
1251
+
1252
+ #[ test]
1253
+ async fn hover_on_function_with_mut_self ( ) {
1254
+ let hover_text =
1255
+ get_hover_text ( "workspace" , "two/src/lib.nr" , Position { line : 96 , character : 10 } )
1256
+ . await ;
1257
+ assert ! ( hover_text. contains( "fn mut_self(&mut self)" ) ) ;
1258
+ }
1241
1259
}
0 commit comments