@@ -16,6 +16,7 @@ pub struct InlayHintsConfig {
1616 pub type_hints : bool ,
1717 pub parameter_hints : bool ,
1818 pub chaining_hints : bool ,
19+ pub hide_named_constructor_hints : bool ,
1920 pub max_length : Option < usize > ,
2021}
2122
@@ -213,7 +214,9 @@ fn get_bind_pat_hints(
213214 Some ( label) => label,
214215 None => {
215216 let ty_name = ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) ;
216- if is_named_constructor ( sema, pat, & ty_name) . is_some ( ) {
217+ if config. hide_named_constructor_hints
218+ && is_named_constructor ( sema, pat, & ty_name) . is_some ( )
219+ {
217220 return None ;
218221 }
219222 ty_name. into ( )
@@ -537,6 +540,7 @@ mod tests {
537540 type_hints : true ,
538541 parameter_hints : true ,
539542 chaining_hints : true ,
543+ hide_named_constructor_hints : true ,
540544 max_length : None ,
541545 } ;
542546
@@ -552,6 +556,7 @@ mod tests {
552556 parameter_hints : true ,
553557 type_hints : false ,
554558 chaining_hints : false ,
559+ hide_named_constructor_hints : true ,
555560 max_length : None ,
556561 } ,
557562 ra_fixture,
@@ -565,6 +570,7 @@ mod tests {
565570 parameter_hints : false ,
566571 type_hints : true ,
567572 chaining_hints : false ,
573+ hide_named_constructor_hints : true ,
568574 max_length : None ,
569575 } ,
570576 ra_fixture,
@@ -578,6 +584,7 @@ mod tests {
578584 parameter_hints : false ,
579585 type_hints : false ,
580586 chaining_hints : true ,
587+ hide_named_constructor_hints : true ,
581588 max_length : None ,
582589 } ,
583590 ra_fixture,
@@ -608,6 +615,7 @@ mod tests {
608615 type_hints : false ,
609616 parameter_hints : false ,
610617 chaining_hints : false ,
618+ hide_named_constructor_hints : true ,
611619 max_length : None ,
612620 } ,
613621 r#"
@@ -1353,6 +1361,60 @@ fn fallible() -> ControlFlow<()> {
13531361 ) ;
13541362 }
13551363
1364+ #[ test]
1365+ fn shows_constructor_type_hints_when_enabled ( ) {
1366+ check_with_config (
1367+ InlayHintsConfig {
1368+ type_hints : true ,
1369+ parameter_hints : true ,
1370+ chaining_hints : true ,
1371+ hide_named_constructor_hints : false ,
1372+ max_length : None ,
1373+ } ,
1374+ r#"
1375+ //- minicore: try
1376+ use core::ops::ControlFlow;
1377+
1378+ struct Struct;
1379+ struct TupleStruct();
1380+
1381+ impl Struct {
1382+ fn new() -> Self {
1383+ Struct
1384+ }
1385+ fn try_new() -> ControlFlow<(), Self> {
1386+ ControlFlow::Continue(Struct)
1387+ }
1388+ }
1389+
1390+ struct Generic<T>(T);
1391+ impl Generic<i32> {
1392+ fn new() -> Self {
1393+ Generic(0)
1394+ }
1395+ }
1396+
1397+ fn main() {
1398+ let strukt = Struct::new();
1399+ // ^^^^^^ Struct
1400+ let tuple_struct = TupleStruct();
1401+ // ^^^^^^^^^^^^ TupleStruct
1402+ let generic0 = Generic::new();
1403+ // ^^^^^^^^ Generic<i32>
1404+ let generic1 = Generic::<i32>::new();
1405+ // ^^^^^^^^ Generic<i32>
1406+ let generic2 = <Generic<i32>>::new();
1407+ // ^^^^^^^^ Generic<i32>
1408+ }
1409+
1410+ fn fallible() -> ControlFlow<()> {
1411+ let strukt = Struct::try_new()?;
1412+ // ^^^^^^ Struct
1413+ }
1414+ "# ,
1415+ ) ;
1416+ }
1417+
13561418 #[ test]
13571419 fn closures ( ) {
13581420 check (
@@ -1408,6 +1470,7 @@ fn main() {
14081470 parameter_hints : false ,
14091471 type_hints : false ,
14101472 chaining_hints : true ,
1473+ hide_named_constructor_hints : true ,
14111474 max_length : None ,
14121475 } ,
14131476 r#"
@@ -1464,6 +1527,7 @@ fn main() {
14641527 parameter_hints : false ,
14651528 type_hints : false ,
14661529 chaining_hints : true ,
1530+ hide_named_constructor_hints : true ,
14671531 max_length : None ,
14681532 } ,
14691533 r#"
@@ -1508,6 +1572,7 @@ fn main() {
15081572 parameter_hints : false ,
15091573 type_hints : false ,
15101574 chaining_hints : true ,
1575+ hide_named_constructor_hints : true ,
15111576 max_length : None ,
15121577 } ,
15131578 r#"
@@ -1553,6 +1618,7 @@ fn main() {
15531618 parameter_hints : false ,
15541619 type_hints : false ,
15551620 chaining_hints : true ,
1621+ hide_named_constructor_hints : true ,
15561622 max_length : None ,
15571623 } ,
15581624 r#"
0 commit comments