Skip to content

Commit d7dfe93

Browse files
committed
hide type inlay hints for enum variant constructors and tuple struct constructors
1 parent 4ea1f58 commit d7dfe93

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,26 +257,20 @@ fn is_named_constructor(
257257
}?;
258258
let expr = match expr {
259259
ast::Expr::CallExpr(call) => match call.expr()? {
260-
ast::Expr::PathExpr(p) => p,
260+
ast::Expr::PathExpr(path) => path,
261261
_ => return None,
262262
},
263+
ast::Expr::PathExpr(path) => path,
263264
_ => return None,
264265
};
265266
let path = expr.path()?;
266267

267-
// Check for tuple-struct or tuple-variant in which case we can check the last segment
268-
let callable = sema.type_of_expr(&ast::Expr::PathExpr(expr))?.original.as_callable(sema.db);
269-
let callable_kind = callable.map(|it| it.kind());
270-
if let Some(hir::CallableKind::TupleStruct(_) | hir::CallableKind::TupleEnumVariant(_)) =
271-
callable_kind
272-
{
273-
if let Some(ctor) = path.segment() {
274-
return (ctor.to_string() == ty_name).then(|| ());
275-
}
276-
}
277-
278-
// otherwise use the qualifying segment as the constructor name
279-
let qual_seg = path.qualifier()?.segment()?;
268+
// If it exists, use qualifying segment as the constructor name.
269+
// If not, use the last segment.
270+
let qual_seg = match path.qualifier() {
271+
Some(qual) => qual.segment(),
272+
None => path.segment(),
273+
}?;
280274
let ctor_name = match qual_seg.kind()? {
281275
ast::PathSegmentKind::Name(name_ref) => {
282276
match qual_seg.generic_arg_list().map(|it| it.generic_args()) {
@@ -1341,7 +1335,7 @@ fn main() {
13411335
}
13421336

13431337
#[test]
1344-
fn skip_constructor_type_hints() {
1338+
fn skip_constructor_and_enum_type_hints() {
13451339
check_with_config(
13461340
InlayHintsConfig {
13471341
type_hints: true,
@@ -1351,7 +1345,7 @@ fn main() {
13511345
max_length: None,
13521346
},
13531347
r#"
1354-
//- minicore: try
1348+
//- minicore: try, option
13551349
use core::ops::ControlFlow;
13561350
13571351
struct Struct;
@@ -1373,13 +1367,37 @@ impl Generic<i32> {
13731367
}
13741368
}
13751369
1370+
enum Enum {
1371+
Variant(u32)
1372+
}
1373+
1374+
fn times2(value: i32) -> i32 {
1375+
2 * value
1376+
}
1377+
13761378
fn main() {
1379+
let enumb = Enum::Variant(0);
1380+
1381+
let strukt = Struct;
13771382
let strukt = Struct::new();
1383+
13781384
let tuple_struct = TupleStruct();
1385+
13791386
let generic0 = Generic::new();
1380-
// ^^^^^^^^ Generic<i32>
1381-
let generic1 = Generic::<i32>::new();
1382-
let generic2 = <Generic<i32>>::new();
1387+
// ^^^^^^^^ Generic<i32>
1388+
let generic1 = Generic(0);
1389+
// ^^^^^^^^ Generic<i32>
1390+
let generic2 = Generic::<i32>::new();
1391+
let generic3 = <Generic<i32>>::new();
1392+
let generic4 = Generic::<i32>(0);
1393+
1394+
1395+
let option = Some(0);
1396+
// ^^^^^^ Option<i32>
1397+
let func = times2;
1398+
// ^^^^ fn times2(i32) -> i32
1399+
let closure = |x: i32| x * 2;
1400+
// ^^^^^^^ |i32| -> i32
13831401
}
13841402
13851403
fn fallible() -> ControlFlow<()> {

0 commit comments

Comments
 (0)