Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints/bind_pat.rs')
| -rw-r--r-- | crates/ide/src/inlay_hints/bind_pat.rs | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index 754df09df1..c9f787e074 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -3,8 +3,8 @@ //! fn f(a: i32, b: i32) -> i32 { a + b } //! let _x /* i32 */= f(4, 4); //! ``` -use hir::{HirDisplay, Semantics, TypeInfo}; -use ide_db::{base_db::FileId, famous_defs::FamousDefs, RootDatabase}; +use hir::{Semantics, TypeInfo}; +use ide_db::{base_db::FileId, RootDatabase}; use itertools::Itertools; use syntax::{ @@ -13,10 +13,11 @@ use syntax::{ }; use crate::{ - inlay_hints::{closure_has_block_body, hint_iterator}, - InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, + inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, }; +use super::label_of_ty; + pub(super) fn hints( acc: &mut Vec<InlayHint>, sema: &Semantics<'_, RootDatabase>, @@ -36,22 +37,13 @@ pub(super) fn hints( return None; } - let krate = sema.scope(desc_pat.syntax())?.krate(); - let famous_defs = FamousDefs(sema, krate); - let label = hint_iterator(sema, &famous_defs, config, &ty); + let label = label_of_ty(sema, desc_pat, config, ty)?; - let label = match label { - Some(label) => label, - None => { - let ty_name = ty.display_truncated(sema.db, config.max_length).to_string(); - if config.hide_named_constructor_hints - && is_named_constructor(sema, pat, &ty_name).is_some() - { - return None; - } - ty_name - } - }; + if config.hide_named_constructor_hints + && is_named_constructor(sema, pat, &label.to_string()).is_some() + { + return None; + } acc.push(InlayHint { range: match pat.name() { @@ -59,7 +51,7 @@ pub(super) fn hints( None => pat.syntax().text_range(), }, kind: InlayKind::TypeHint, - label: label.into(), + label, tooltip: pat .name() .map(|it| it.syntax().text_range()) @@ -346,7 +338,31 @@ fn main(a: SliceIter<'_, Container>) { range: 484..485, kind: ChainingHint, label: [ - "SliceIter<Container>", + "", + InlayHintLabelPart { + text: "SliceIter", + linked_location: Some( + FileRange { + file_id: FileId( + 0, + ), + range: 289..298, + }, + ), + }, + "<", + InlayHintLabelPart { + text: "Container", + linked_location: Some( + FileRange { + file_id: FileId( + 0, + ), + range: 238..247, + }, + ), + }, + ">", ], tooltip: Some( HoverRanged( |