@@ -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 : false ,
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 : false ,
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 : false ,
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 : false ,
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 : false ,
611619 max_length : None ,
612620 } ,
613621 r#"
@@ -1313,6 +1321,55 @@ fn main() {
13131321
13141322 #[ test]
13151323 fn skip_constructor_type_hints ( ) {
1324+ check_with_config (
1325+ InlayHintsConfig {
1326+ type_hints : true ,
1327+ parameter_hints : true ,
1328+ chaining_hints : true ,
1329+ hide_named_constructor_hints : true ,
1330+ max_length : None ,
1331+ } ,
1332+ r#"
1333+ //- minicore: try
1334+ use core::ops::ControlFlow;
1335+
1336+ struct Struct;
1337+ struct TupleStruct();
1338+
1339+ impl Struct {
1340+ fn new() -> Self {
1341+ Struct
1342+ }
1343+ fn try_new() -> ControlFlow<(), Self> {
1344+ ControlFlow::Continue(Struct)
1345+ }
1346+ }
1347+
1348+ struct Generic<T>(T);
1349+ impl Generic<i32> {
1350+ fn new() -> Self {
1351+ Generic(0)
1352+ }
1353+ }
1354+
1355+ fn main() {
1356+ let strukt = Struct::new();
1357+ let tuple_struct = TupleStruct();
1358+ let generic0 = Generic::new();
1359+ // ^^^^^^^^ Generic<i32>
1360+ let generic1 = Generic::<i32>::new();
1361+ let generic2 = <Generic<i32>>::new();
1362+ }
1363+
1364+ fn fallible() -> ControlFlow<()> {
1365+ let strukt = Struct::try_new()?;
1366+ }
1367+ "# ,
1368+ ) ;
1369+ }
1370+
1371+ #[ test]
1372+ fn shows_constructor_type_hints_when_enabled ( ) {
13161373 check_types (
13171374 r#"
13181375//- minicore: try
@@ -1339,15 +1396,20 @@ impl Generic<i32> {
13391396
13401397fn main() {
13411398 let strukt = Struct::new();
1399+ // ^^^^^^ Struct
13421400 let tuple_struct = TupleStruct();
1401+ // ^^^^^^^^^^^^ TupleStruct
13431402 let generic0 = Generic::new();
13441403 // ^^^^^^^^ Generic<i32>
13451404 let generic1 = Generic::<i32>::new();
1405+ // ^^^^^^^^ Generic<i32>
13461406 let generic2 = <Generic<i32>>::new();
1407+ // ^^^^^^^^ Generic<i32>
13471408}
13481409
13491410fn fallible() -> ControlFlow<()> {
13501411 let strukt = Struct::try_new()?;
1412+ // ^^^^^^ Struct
13511413}
13521414"# ,
13531415 ) ;
@@ -1408,6 +1470,7 @@ fn main() {
14081470 parameter_hints : false ,
14091471 type_hints : false ,
14101472 chaining_hints : true ,
1473+ hide_named_constructor_hints : false ,
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 : false ,
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 : false ,
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 : false ,
15561622 max_length : None ,
15571623 } ,
15581624 r#"
0 commit comments