diff options
Diffstat (limited to 'crates/ra_ide/src/inlay_hints.rs')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 263 |
1 files changed, 145 insertions, 118 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index a484dfdeb..35e3f782d 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -1,12 +1,11 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{HirDisplay, SourceAnalyzer, SourceBinder}; | 3 | use hir::{Adt, HirDisplay, Semantics, Type}; |
4 | use once_cell::unsync::Lazy; | ||
5 | use ra_ide_db::RootDatabase; | 4 | use ra_ide_db::RootDatabase; |
6 | use ra_prof::profile; | 5 | use ra_prof::profile; |
7 | use ra_syntax::{ | 6 | use ra_syntax::{ |
8 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, | 7 | ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, |
9 | match_ast, SmolStr, SourceFile, SyntaxNode, TextRange, | 8 | match_ast, SmolStr, SyntaxNode, TextRange, |
10 | }; | 9 | }; |
11 | 10 | ||
12 | use crate::{FileId, FunctionSignature}; | 11 | use crate::{FileId, FunctionSignature}; |
@@ -27,42 +26,38 @@ pub struct InlayHint { | |||
27 | pub(crate) fn inlay_hints( | 26 | pub(crate) fn inlay_hints( |
28 | db: &RootDatabase, | 27 | db: &RootDatabase, |
29 | file_id: FileId, | 28 | file_id: FileId, |
30 | file: &SourceFile, | ||
31 | max_inlay_hint_length: Option<usize>, | 29 | max_inlay_hint_length: Option<usize>, |
32 | ) -> Vec<InlayHint> { | 30 | ) -> Vec<InlayHint> { |
33 | let mut sb = SourceBinder::new(db); | 31 | let sema = Semantics::new(db); |
32 | let file = sema.parse(file_id); | ||
34 | let mut res = Vec::new(); | 33 | let mut res = Vec::new(); |
35 | for node in file.syntax().descendants() { | 34 | for node in file.syntax().descendants() { |
36 | get_inlay_hints(&mut res, &mut sb, file_id, &node, max_inlay_hint_length); | 35 | get_inlay_hints(&mut res, &sema, &node, max_inlay_hint_length); |
37 | } | 36 | } |
38 | res | 37 | res |
39 | } | 38 | } |
40 | 39 | ||
41 | fn get_inlay_hints( | 40 | fn get_inlay_hints( |
42 | acc: &mut Vec<InlayHint>, | 41 | acc: &mut Vec<InlayHint>, |
43 | sb: &mut SourceBinder<RootDatabase>, | 42 | sema: &Semantics<RootDatabase>, |
44 | file_id: FileId, | ||
45 | node: &SyntaxNode, | 43 | node: &SyntaxNode, |
46 | max_inlay_hint_length: Option<usize>, | 44 | max_inlay_hint_length: Option<usize>, |
47 | ) -> Option<()> { | 45 | ) -> Option<()> { |
48 | let _p = profile("get_inlay_hints"); | 46 | let _p = profile("get_inlay_hints"); |
49 | let db = sb.db; | 47 | let db = sema.db; |
50 | let analyzer = Lazy::new(move || sb.analyze(hir::InFile::new(file_id.into(), node), None)); | ||
51 | match_ast! { | 48 | match_ast! { |
52 | match node { | 49 | match node { |
53 | ast::CallExpr(it) => { | 50 | ast::CallExpr(it) => { |
54 | get_param_name_hints(acc, db, &analyzer, ast::Expr::from(it)); | 51 | get_param_name_hints(acc, sema, ast::Expr::from(it)); |
55 | }, | 52 | }, |
56 | ast::MethodCallExpr(it) => { | 53 | ast::MethodCallExpr(it) => { |
57 | get_param_name_hints(acc, db, &analyzer, ast::Expr::from(it)); | 54 | get_param_name_hints(acc, sema, ast::Expr::from(it)); |
58 | }, | 55 | }, |
59 | ast::BindPat(it) => { | 56 | ast::BindPat(it) => { |
60 | if should_not_display_type_hint(&it) { | 57 | let pat = ast::Pat::from(it.clone()); |
61 | return None; | 58 | let ty = sema.type_of_pat(&pat)?; |
62 | } | 59 | |
63 | let pat = ast::Pat::from(it); | 60 | if should_not_display_type_hint(db, &it, &ty) { |
64 | let ty = analyzer.type_of_pat(db, &pat)?; | ||
65 | if ty.is_unknown() { | ||
66 | return None; | 61 | return None; |
67 | } | 62 | } |
68 | 63 | ||
@@ -80,7 +75,24 @@ fn get_inlay_hints( | |||
80 | Some(()) | 75 | Some(()) |
81 | } | 76 | } |
82 | 77 | ||
83 | fn should_not_display_type_hint(bind_pat: &ast::BindPat) -> bool { | 78 | fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { |
79 | if let Some(Adt::Enum(enum_data)) = pat_ty.as_adt() { | ||
80 | let pat_text = bind_pat.syntax().to_string(); | ||
81 | enum_data | ||
82 | .variants(db) | ||
83 | .into_iter() | ||
84 | .map(|variant| variant.name(db).to_string()) | ||
85 | .any(|enum_name| enum_name == pat_text) | ||
86 | } else { | ||
87 | false | ||
88 | } | ||
89 | } | ||
90 | |||
91 | fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { | ||
92 | if pat_ty.is_unknown() { | ||
93 | return true; | ||
94 | } | ||
95 | |||
84 | for node in bind_pat.syntax().ancestors() { | 96 | for node in bind_pat.syntax().ancestors() { |
85 | match_ast! { | 97 | match_ast! { |
86 | match node { | 98 | match node { |
@@ -90,6 +102,17 @@ fn should_not_display_type_hint(bind_pat: &ast::BindPat) -> bool { | |||
90 | ast::Param(it) => { | 102 | ast::Param(it) => { |
91 | return it.ascribed_type().is_some() | 103 | return it.ascribed_type().is_some() |
92 | }, | 104 | }, |
105 | ast::MatchArm(_it) => { | ||
106 | return pat_is_enum_variant(db, bind_pat, pat_ty); | ||
107 | }, | ||
108 | ast::IfExpr(it) => { | ||
109 | return it.condition().and_then(|condition| condition.pat()).is_some() | ||
110 | && pat_is_enum_variant(db, bind_pat, pat_ty); | ||
111 | }, | ||
112 | ast::WhileExpr(it) => { | ||
113 | return it.condition().and_then(|condition| condition.pat()).is_some() | ||
114 | && pat_is_enum_variant(db, bind_pat, pat_ty); | ||
115 | }, | ||
93 | _ => (), | 116 | _ => (), |
94 | } | 117 | } |
95 | } | 118 | } |
@@ -99,8 +122,7 @@ fn should_not_display_type_hint(bind_pat: &ast::BindPat) -> bool { | |||
99 | 122 | ||
100 | fn get_param_name_hints( | 123 | fn get_param_name_hints( |
101 | acc: &mut Vec<InlayHint>, | 124 | acc: &mut Vec<InlayHint>, |
102 | db: &RootDatabase, | 125 | sema: &Semantics<RootDatabase>, |
103 | analyzer: &SourceAnalyzer, | ||
104 | expr: ast::Expr, | 126 | expr: ast::Expr, |
105 | ) -> Option<()> { | 127 | ) -> Option<()> { |
106 | let args = match &expr { | 128 | let args = match &expr { |
@@ -112,20 +134,19 @@ fn get_param_name_hints( | |||
112 | // we need args len to determine whether to skip or not the &self parameter | 134 | // we need args len to determine whether to skip or not the &self parameter |
113 | .collect::<Vec<_>>(); | 135 | .collect::<Vec<_>>(); |
114 | 136 | ||
115 | let fn_signature = get_fn_signature(db, analyzer, &expr)?; | 137 | let fn_signature = get_fn_signature(sema, &expr)?; |
116 | let n_params_to_skip = | 138 | let n_params_to_skip = |
117 | if fn_signature.has_self_param && fn_signature.parameter_names.len() > args.len() { | 139 | if fn_signature.has_self_param && fn_signature.parameter_names.len() > args.len() { |
118 | 1 | 140 | 1 |
119 | } else { | 141 | } else { |
120 | 0 | 142 | 0 |
121 | }; | 143 | }; |
122 | let parameters = fn_signature.parameter_names.iter().skip(n_params_to_skip); | 144 | let hints = fn_signature |
123 | 145 | .parameter_names | |
124 | let hints = parameters | 146 | .iter() |
147 | .skip(n_params_to_skip) | ||
125 | .zip(args) | 148 | .zip(args) |
126 | .filter(|(param, arg)| { | 149 | .filter(|(param, arg)| should_show_param_hint(&fn_signature, param, &arg)) |
127 | should_show_param_hint(&fn_signature, param, &arg.syntax().to_string()) | ||
128 | }) | ||
129 | .map(|(param_name, arg)| InlayHint { | 150 | .map(|(param_name, arg)| InlayHint { |
130 | range: arg.syntax().text_range(), | 151 | range: arg.syntax().text_range(), |
131 | kind: InlayKind::ParameterHint, | 152 | kind: InlayKind::ParameterHint, |
@@ -139,8 +160,9 @@ fn get_param_name_hints( | |||
139 | fn should_show_param_hint( | 160 | fn should_show_param_hint( |
140 | fn_signature: &FunctionSignature, | 161 | fn_signature: &FunctionSignature, |
141 | param_name: &str, | 162 | param_name: &str, |
142 | argument_string: &str, | 163 | argument: &ast::Expr, |
143 | ) -> bool { | 164 | ) -> bool { |
165 | let argument_string = argument.syntax().to_string(); | ||
144 | if param_name.is_empty() || argument_string.ends_with(param_name) { | 166 | if param_name.is_empty() || argument_string.ends_with(param_name) { |
145 | return false; | 167 | return false; |
146 | } | 168 | } |
@@ -158,28 +180,26 @@ fn should_show_param_hint( | |||
158 | true | 180 | true |
159 | } | 181 | } |
160 | 182 | ||
161 | fn get_fn_signature( | 183 | fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { |
162 | db: &RootDatabase, | ||
163 | analyzer: &SourceAnalyzer, | ||
164 | expr: &ast::Expr, | ||
165 | ) -> Option<FunctionSignature> { | ||
166 | match expr { | 184 | match expr { |
167 | ast::Expr::CallExpr(expr) => { | 185 | ast::Expr::CallExpr(expr) => { |
168 | // FIXME: Type::as_callable is broken for closures | 186 | // FIXME: Type::as_callable is broken for closures |
169 | let callable_def = analyzer.type_of(db, &expr.expr()?)?.as_callable()?; | 187 | let callable_def = sema.type_of_expr(&expr.expr()?)?.as_callable()?; |
170 | match callable_def { | 188 | match callable_def { |
171 | hir::CallableDef::FunctionId(it) => { | 189 | hir::CallableDef::FunctionId(it) => { |
172 | Some(FunctionSignature::from_hir(db, it.into())) | 190 | Some(FunctionSignature::from_hir(sema.db, it.into())) |
191 | } | ||
192 | hir::CallableDef::StructId(it) => { | ||
193 | FunctionSignature::from_struct(sema.db, it.into()) | ||
173 | } | 194 | } |
174 | hir::CallableDef::StructId(it) => FunctionSignature::from_struct(db, it.into()), | ||
175 | hir::CallableDef::EnumVariantId(it) => { | 195 | hir::CallableDef::EnumVariantId(it) => { |
176 | FunctionSignature::from_enum_variant(db, it.into()) | 196 | FunctionSignature::from_enum_variant(sema.db, it.into()) |
177 | } | 197 | } |
178 | } | 198 | } |
179 | } | 199 | } |
180 | ast::Expr::MethodCallExpr(expr) => { | 200 | ast::Expr::MethodCallExpr(expr) => { |
181 | let fn_def = analyzer.resolve_method_call(&expr)?; | 201 | let fn_def = sema.resolve_method_call(&expr)?; |
182 | Some(FunctionSignature::from_hir(db, fn_def)) | 202 | Some(FunctionSignature::from_hir(sema.db, fn_def)) |
183 | } | 203 | } |
184 | _ => None, | 204 | _ => None, |
185 | } | 205 | } |
@@ -440,75 +460,77 @@ struct Test { | |||
440 | b: u8, | 460 | b: u8, |
441 | } | 461 | } |
442 | 462 | ||
463 | use CustomOption::*; | ||
464 | |||
443 | fn main() { | 465 | fn main() { |
444 | let test = CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 }); | 466 | let test = Some(Test { a: Some(3), b: 1 }); |
445 | if let CustomOption::None = &test {}; | 467 | if let None = &test {}; |
446 | if let test = &test {}; | 468 | if let test = &test {}; |
447 | if let CustomOption::Some(test) = &test {}; | 469 | if let Some(test) = &test {}; |
448 | if let CustomOption::Some(Test { a, b }) = &test {}; | 470 | if let Some(Test { a, b }) = &test {}; |
449 | if let CustomOption::Some(Test { a: x, b: y }) = &test {}; | 471 | if let Some(Test { a: x, b: y }) = &test {}; |
450 | if let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; | 472 | if let Some(Test { a: Some(x), b: y }) = &test {}; |
451 | if let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; | 473 | if let Some(Test { a: None, b: y }) = &test {}; |
452 | if let CustomOption::Some(Test { b: y, .. }) = &test {}; | 474 | if let Some(Test { b: y, .. }) = &test {}; |
453 | 475 | ||
454 | if test == CustomOption::None {} | 476 | if test == None {} |
455 | }"#, | 477 | }"#, |
456 | ); | 478 | ); |
457 | 479 | ||
458 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" | 480 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" |
459 | [ | 481 | [ |
460 | InlayHint { | 482 | InlayHint { |
461 | range: [166; 170), | 483 | range: [188; 192), |
462 | kind: TypeHint, | 484 | kind: TypeHint, |
463 | label: "CustomOption<Test>", | 485 | label: "CustomOption<Test>", |
464 | }, | 486 | }, |
465 | InlayHint { | 487 | InlayHint { |
466 | range: [287; 291), | 488 | range: [267; 271), |
467 | kind: TypeHint, | 489 | kind: TypeHint, |
468 | label: "&CustomOption<Test>", | 490 | label: "&CustomOption<Test>", |
469 | }, | 491 | }, |
470 | InlayHint { | 492 | InlayHint { |
471 | range: [334; 338), | 493 | range: [300; 304), |
472 | kind: TypeHint, | 494 | kind: TypeHint, |
473 | label: "&Test", | 495 | label: "&Test", |
474 | }, | 496 | }, |
475 | InlayHint { | 497 | InlayHint { |
476 | range: [389; 390), | 498 | range: [341; 342), |
477 | kind: TypeHint, | 499 | kind: TypeHint, |
478 | label: "&CustomOption<u32>", | 500 | label: "&CustomOption<u32>", |
479 | }, | 501 | }, |
480 | InlayHint { | 502 | InlayHint { |
481 | range: [392; 393), | 503 | range: [344; 345), |
482 | kind: TypeHint, | 504 | kind: TypeHint, |
483 | label: "&u8", | 505 | label: "&u8", |
484 | }, | 506 | }, |
485 | InlayHint { | 507 | InlayHint { |
486 | range: [449; 450), | 508 | range: [387; 388), |
487 | kind: TypeHint, | 509 | kind: TypeHint, |
488 | label: "&CustomOption<u32>", | 510 | label: "&CustomOption<u32>", |
489 | }, | 511 | }, |
490 | InlayHint { | 512 | InlayHint { |
491 | range: [455; 456), | 513 | range: [393; 394), |
492 | kind: TypeHint, | 514 | kind: TypeHint, |
493 | label: "&u8", | 515 | label: "&u8", |
494 | }, | 516 | }, |
495 | InlayHint { | 517 | InlayHint { |
496 | range: [531; 532), | 518 | range: [441; 442), |
497 | kind: TypeHint, | 519 | kind: TypeHint, |
498 | label: "&u32", | 520 | label: "&u32", |
499 | }, | 521 | }, |
500 | InlayHint { | 522 | InlayHint { |
501 | range: [538; 539), | 523 | range: [448; 449), |
502 | kind: TypeHint, | 524 | kind: TypeHint, |
503 | label: "&u8", | 525 | label: "&u8", |
504 | }, | 526 | }, |
505 | InlayHint { | 527 | InlayHint { |
506 | range: [618; 619), | 528 | range: [500; 501), |
507 | kind: TypeHint, | 529 | kind: TypeHint, |
508 | label: "&u8", | 530 | label: "&u8", |
509 | }, | 531 | }, |
510 | InlayHint { | 532 | InlayHint { |
511 | range: [675; 676), | 533 | range: [543; 544), |
512 | kind: TypeHint, | 534 | kind: TypeHint, |
513 | label: "&u8", | 535 | label: "&u8", |
514 | }, | 536 | }, |
@@ -533,75 +555,77 @@ struct Test { | |||
533 | b: u8, | 555 | b: u8, |
534 | } | 556 | } |
535 | 557 | ||
558 | use CustomOption::*; | ||
559 | |||
536 | fn main() { | 560 | fn main() { |
537 | let test = CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 }); | 561 | let test = Some(Test { a: Some(3), b: 1 }); |
538 | while let CustomOption::None = &test {}; | 562 | while let None = &test {}; |
539 | while let test = &test {}; | 563 | while let test = &test {}; |
540 | while let CustomOption::Some(test) = &test {}; | 564 | while let Some(test) = &test {}; |
541 | while let CustomOption::Some(Test { a, b }) = &test {}; | 565 | while let Some(Test { a, b }) = &test {}; |
542 | while let CustomOption::Some(Test { a: x, b: y }) = &test {}; | 566 | while let Some(Test { a: x, b: y }) = &test {}; |
543 | while let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {}; | 567 | while let Some(Test { a: Some(x), b: y }) = &test {}; |
544 | while let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {}; | 568 | while let Some(Test { a: None, b: y }) = &test {}; |
545 | while let CustomOption::Some(Test { b: y, .. }) = &test {}; | 569 | while let Some(Test { b: y, .. }) = &test {}; |
546 | 570 | ||
547 | while test == CustomOption::None {} | 571 | while test == None {} |
548 | }"#, | 572 | }"#, |
549 | ); | 573 | ); |
550 | 574 | ||
551 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" | 575 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" |
552 | [ | 576 | [ |
553 | InlayHint { | 577 | InlayHint { |
554 | range: [166; 170), | 578 | range: [188; 192), |
555 | kind: TypeHint, | 579 | kind: TypeHint, |
556 | label: "CustomOption<Test>", | 580 | label: "CustomOption<Test>", |
557 | }, | 581 | }, |
558 | InlayHint { | 582 | InlayHint { |
559 | range: [293; 297), | 583 | range: [273; 277), |
560 | kind: TypeHint, | 584 | kind: TypeHint, |
561 | label: "&CustomOption<Test>", | 585 | label: "&CustomOption<Test>", |
562 | }, | 586 | }, |
563 | InlayHint { | 587 | InlayHint { |
564 | range: [343; 347), | 588 | range: [309; 313), |
565 | kind: TypeHint, | 589 | kind: TypeHint, |
566 | label: "&Test", | 590 | label: "&Test", |
567 | }, | 591 | }, |
568 | InlayHint { | 592 | InlayHint { |
569 | range: [401; 402), | 593 | range: [353; 354), |
570 | kind: TypeHint, | 594 | kind: TypeHint, |
571 | label: "&CustomOption<u32>", | 595 | label: "&CustomOption<u32>", |
572 | }, | 596 | }, |
573 | InlayHint { | 597 | InlayHint { |
574 | range: [404; 405), | 598 | range: [356; 357), |
575 | kind: TypeHint, | 599 | kind: TypeHint, |
576 | label: "&u8", | 600 | label: "&u8", |
577 | }, | 601 | }, |
578 | InlayHint { | 602 | InlayHint { |
579 | range: [464; 465), | 603 | range: [402; 403), |
580 | kind: TypeHint, | 604 | kind: TypeHint, |
581 | label: "&CustomOption<u32>", | 605 | label: "&CustomOption<u32>", |
582 | }, | 606 | }, |
583 | InlayHint { | 607 | InlayHint { |
584 | range: [470; 471), | 608 | range: [408; 409), |
585 | kind: TypeHint, | 609 | kind: TypeHint, |
586 | label: "&u8", | 610 | label: "&u8", |
587 | }, | 611 | }, |
588 | InlayHint { | 612 | InlayHint { |
589 | range: [549; 550), | 613 | range: [459; 460), |
590 | kind: TypeHint, | 614 | kind: TypeHint, |
591 | label: "&u32", | 615 | label: "&u32", |
592 | }, | 616 | }, |
593 | InlayHint { | 617 | InlayHint { |
594 | range: [556; 557), | 618 | range: [466; 467), |
595 | kind: TypeHint, | 619 | kind: TypeHint, |
596 | label: "&u8", | 620 | label: "&u8", |
597 | }, | 621 | }, |
598 | InlayHint { | 622 | InlayHint { |
599 | range: [639; 640), | 623 | range: [521; 522), |
600 | kind: TypeHint, | 624 | kind: TypeHint, |
601 | label: "&u8", | 625 | label: "&u8", |
602 | }, | 626 | }, |
603 | InlayHint { | 627 | InlayHint { |
604 | range: [699; 700), | 628 | range: [567; 568), |
605 | kind: TypeHint, | 629 | kind: TypeHint, |
606 | label: "&u8", | 630 | label: "&u8", |
607 | }, | 631 | }, |
@@ -626,16 +650,18 @@ struct Test { | |||
626 | b: u8, | 650 | b: u8, |
627 | } | 651 | } |
628 | 652 | ||
653 | use CustomOption::*; | ||
654 | |||
629 | fn main() { | 655 | fn main() { |
630 | match CustomOption::Some(Test { a: CustomOption::Some(3), b: 1 }) { | 656 | match Some(Test { a: Some(3), b: 1 }) { |
631 | CustomOption::None => (), | 657 | None => (), |
632 | test => (), | 658 | test => (), |
633 | CustomOption::Some(test) => (), | 659 | Some(test) => (), |
634 | CustomOption::Some(Test { a, b }) => (), | 660 | Some(Test { a, b }) => (), |
635 | CustomOption::Some(Test { a: x, b: y }) => (), | 661 | Some(Test { a: x, b: y }) => (), |
636 | CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) => (), | 662 | Some(Test { a: Some(x), b: y }) => (), |
637 | CustomOption::Some(Test { a: CustomOption::None, b: y }) => (), | 663 | Some(Test { a: None, b: y }) => (), |
638 | CustomOption::Some(Test { b: y, .. }) => (), | 664 | Some(Test { b: y, .. }) => (), |
639 | _ => {} | 665 | _ => {} |
640 | } | 666 | } |
641 | }"#, | 667 | }"#, |
@@ -644,52 +670,52 @@ fn main() { | |||
644 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" | 670 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" |
645 | [ | 671 | [ |
646 | InlayHint { | 672 | InlayHint { |
647 | range: [272; 276), | 673 | range: [252; 256), |
648 | kind: TypeHint, | 674 | kind: TypeHint, |
649 | label: "CustomOption<Test>", | 675 | label: "CustomOption<Test>", |
650 | }, | 676 | }, |
651 | InlayHint { | 677 | InlayHint { |
652 | range: [311; 315), | 678 | range: [277; 281), |
653 | kind: TypeHint, | 679 | kind: TypeHint, |
654 | label: "Test", | 680 | label: "Test", |
655 | }, | 681 | }, |
656 | InlayHint { | 682 | InlayHint { |
657 | range: [358; 359), | 683 | range: [310; 311), |
658 | kind: TypeHint, | 684 | kind: TypeHint, |
659 | label: "CustomOption<u32>", | 685 | label: "CustomOption<u32>", |
660 | }, | 686 | }, |
661 | InlayHint { | 687 | InlayHint { |
662 | range: [361; 362), | 688 | range: [313; 314), |
663 | kind: TypeHint, | 689 | kind: TypeHint, |
664 | label: "u8", | 690 | label: "u8", |
665 | }, | 691 | }, |
666 | InlayHint { | 692 | InlayHint { |
667 | range: [410; 411), | 693 | range: [348; 349), |
668 | kind: TypeHint, | 694 | kind: TypeHint, |
669 | label: "CustomOption<u32>", | 695 | label: "CustomOption<u32>", |
670 | }, | 696 | }, |
671 | InlayHint { | 697 | InlayHint { |
672 | range: [416; 417), | 698 | range: [354; 355), |
673 | kind: TypeHint, | 699 | kind: TypeHint, |
674 | label: "u8", | 700 | label: "u8", |
675 | }, | 701 | }, |
676 | InlayHint { | 702 | InlayHint { |
677 | range: [484; 485), | 703 | range: [394; 395), |
678 | kind: TypeHint, | 704 | kind: TypeHint, |
679 | label: "u32", | 705 | label: "u32", |
680 | }, | 706 | }, |
681 | InlayHint { | 707 | InlayHint { |
682 | range: [491; 492), | 708 | range: [401; 402), |
683 | kind: TypeHint, | 709 | kind: TypeHint, |
684 | label: "u8", | 710 | label: "u8", |
685 | }, | 711 | }, |
686 | InlayHint { | 712 | InlayHint { |
687 | range: [563; 564), | 713 | range: [445; 446), |
688 | kind: TypeHint, | 714 | kind: TypeHint, |
689 | label: "u8", | 715 | label: "u8", |
690 | }, | 716 | }, |
691 | InlayHint { | 717 | InlayHint { |
692 | range: [612; 613), | 718 | range: [480; 481), |
693 | kind: TypeHint, | 719 | kind: TypeHint, |
694 | label: "u8", | 720 | label: "u8", |
695 | }, | 721 | }, |
@@ -743,6 +769,7 @@ enum CustomOption<T> { | |||
743 | None, | 769 | None, |
744 | Some(T), | 770 | Some(T), |
745 | } | 771 | } |
772 | use CustomOption::*; | ||
746 | 773 | ||
747 | struct FileId {} | 774 | struct FileId {} |
748 | struct SmolStr {} | 775 | struct SmolStr {} |
@@ -791,11 +818,11 @@ fn main() { | |||
791 | Test::from_syntax( | 818 | Test::from_syntax( |
792 | FileId {}, | 819 | FileId {}, |
793 | "impl".into(), | 820 | "impl".into(), |
794 | CustomOption::None, | 821 | None, |
795 | TextRange {}, | 822 | TextRange {}, |
796 | SyntaxKind {}, | 823 | SyntaxKind {}, |
797 | CustomOption::None, | 824 | None, |
798 | CustomOption::None, | 825 | None, |
799 | ); | 826 | ); |
800 | }"#, | 827 | }"#, |
801 | ); | 828 | ); |
@@ -803,77 +830,77 @@ fn main() { | |||
803 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" | 830 | assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" |
804 | [ | 831 | [ |
805 | InlayHint { | 832 | InlayHint { |
806 | range: [777; 788), | 833 | range: [798; 809), |
807 | kind: TypeHint, | 834 | kind: TypeHint, |
808 | label: "i32", | 835 | label: "i32", |
809 | }, | 836 | }, |
810 | InlayHint { | 837 | InlayHint { |
811 | range: [821; 822), | 838 | range: [842; 843), |
812 | kind: ParameterHint, | 839 | kind: ParameterHint, |
813 | label: "foo", | 840 | label: "foo", |
814 | }, | 841 | }, |
815 | InlayHint { | 842 | InlayHint { |
816 | range: [824; 825), | 843 | range: [845; 846), |
817 | kind: ParameterHint, | 844 | kind: ParameterHint, |
818 | label: "bar", | 845 | label: "bar", |
819 | }, | 846 | }, |
820 | InlayHint { | 847 | InlayHint { |
821 | range: [827; 834), | 848 | range: [848; 855), |
822 | kind: ParameterHint, | 849 | kind: ParameterHint, |
823 | label: "msg", | 850 | label: "msg", |
824 | }, | 851 | }, |
825 | InlayHint { | 852 | InlayHint { |
826 | range: [839; 850), | 853 | range: [860; 871), |
827 | kind: ParameterHint, | 854 | kind: ParameterHint, |
828 | label: "last", | 855 | label: "last", |
829 | }, | 856 | }, |
830 | InlayHint { | 857 | InlayHint { |
831 | range: [893; 896), | 858 | range: [914; 917), |
832 | kind: ParameterHint, | 859 | kind: ParameterHint, |
833 | label: "param", | 860 | label: "param", |
834 | }, | 861 | }, |
835 | InlayHint { | 862 | InlayHint { |
836 | range: [916; 918), | 863 | range: [937; 939), |
837 | kind: ParameterHint, | 864 | kind: ParameterHint, |
838 | label: "&self", | 865 | label: "&self", |
839 | }, | 866 | }, |
840 | InlayHint { | 867 | InlayHint { |
841 | range: [920; 924), | 868 | range: [941; 945), |
842 | kind: ParameterHint, | 869 | kind: ParameterHint, |
843 | label: "param", | 870 | label: "param", |
844 | }, | 871 | }, |
845 | InlayHint { | 872 | InlayHint { |
846 | range: [959; 968), | 873 | range: [980; 989), |
847 | kind: ParameterHint, | 874 | kind: ParameterHint, |
848 | label: "file_id", | 875 | label: "file_id", |
849 | }, | 876 | }, |
850 | InlayHint { | 877 | InlayHint { |
851 | range: [978; 991), | 878 | range: [999; 1012), |
852 | kind: ParameterHint, | 879 | kind: ParameterHint, |
853 | label: "name", | 880 | label: "name", |
854 | }, | 881 | }, |
855 | InlayHint { | 882 | InlayHint { |
856 | range: [1001; 1019), | 883 | range: [1022; 1026), |
857 | kind: ParameterHint, | 884 | kind: ParameterHint, |
858 | label: "focus_range", | 885 | label: "focus_range", |
859 | }, | 886 | }, |
860 | InlayHint { | 887 | InlayHint { |
861 | range: [1029; 1041), | 888 | range: [1036; 1048), |
862 | kind: ParameterHint, | 889 | kind: ParameterHint, |
863 | label: "full_range", | 890 | label: "full_range", |
864 | }, | 891 | }, |
865 | InlayHint { | 892 | InlayHint { |
866 | range: [1051; 1064), | 893 | range: [1058; 1071), |
867 | kind: ParameterHint, | 894 | kind: ParameterHint, |
868 | label: "kind", | 895 | label: "kind", |
869 | }, | 896 | }, |
870 | InlayHint { | 897 | InlayHint { |
871 | range: [1074; 1092), | 898 | range: [1081; 1085), |
872 | kind: ParameterHint, | 899 | kind: ParameterHint, |
873 | label: "docs", | 900 | label: "docs", |
874 | }, | 901 | }, |
875 | InlayHint { | 902 | InlayHint { |
876 | range: [1102; 1120), | 903 | range: [1095; 1099), |
877 | kind: ParameterHint, | 904 | kind: ParameterHint, |
878 | label: "description", | 905 | label: "description", |
879 | }, | 906 | }, |