Skip to content

Commit b9d0401

Browse files
committed
temp
1 parent ed737b5 commit b9d0401

File tree

2 files changed

+81
-16
lines changed

2 files changed

+81
-16
lines changed

crates/hir-ty/src/display.rs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ use crate::{
6565
pub trait HirWrite: fmt::Write {
6666
fn start_location_link(&mut self, _location: ModuleDefId) {}
6767
fn end_location_link(&mut self) {}
68+
fn start_truncated(&mut self) {}
69+
fn end_truncated(&mut self) {}
6870
}
6971

7072
// String will ignore link metadata
@@ -356,19 +358,26 @@ impl HirFormatter<'_> {
356358
sep: &str,
357359
) -> Result<(), HirDisplayError> {
358360
let mut first = true;
361+
let mut truncated = false;
359362
for e in iter {
360363
if !first {
361364
write!(self, "{sep}")?;
362365
}
363366
first = false;
364367

365368
// Abbreviate multiple omitted types with a single ellipsis.
366-
if self.should_truncate() {
367-
return write!(self, "{TYPE_HINT_TRUNCATION}");
369+
if !truncated && self.should_truncate() {
370+
truncated = true;
371+
self.fmt.start_truncated();
368372
}
369373

370374
e.hir_fmt(self)?;
371375
}
376+
377+
if truncated {
378+
self.fmt.end_truncated();
379+
}
380+
372381
Ok(())
373382
}
374383

@@ -556,9 +565,11 @@ impl<T: HirDisplay + Internable> HirDisplay for Interned<T> {
556565

557566
impl HirDisplay for ProjectionTy {
558567
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
559-
if f.should_truncate() {
560-
return write!(f, "{TYPE_HINT_TRUNCATION}");
568+
let truncated = f.should_truncate();
569+
if truncated {
570+
f.fmt.start_truncated();
561571
}
572+
562573
let trait_ref = self.trait_ref(f.db);
563574
let self_ty = trait_ref.self_type_parameter(Interner);
564575

@@ -624,17 +635,30 @@ impl HirDisplay for ProjectionTy {
624635
let proj_params_count =
625636
self.substitution.len(Interner) - trait_ref.substitution.len(Interner);
626637
let proj_params = &self.substitution.as_slice(Interner)[..proj_params_count];
627-
hir_fmt_generics(f, proj_params, None, None)
638+
hir_fmt_generics(f, proj_params, None, None)?;
639+
640+
if truncated {
641+
f.fmt.end_truncated();
642+
}
643+
644+
Ok(())
628645
}
629646
}
630647

631648
impl HirDisplay for OpaqueTy {
632649
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
633-
if f.should_truncate() {
634-
return write!(f, "{TYPE_HINT_TRUNCATION}");
650+
let truncated = f.should_truncate();
651+
if truncated {
652+
f.fmt.start_truncated();
653+
}
654+
655+
self.substitution.at(Interner, 0).hir_fmt(f)?;
656+
657+
if truncated {
658+
f.fmt.end_truncated();
635659
}
636660

637-
self.substitution.at(Interner, 0).hir_fmt(f)
661+
Ok(())
638662
}
639663
}
640664

@@ -997,8 +1021,9 @@ impl HirDisplay for Ty {
9971021
&self,
9981022
f @ &mut HirFormatter { db, .. }: &mut HirFormatter<'_>,
9991023
) -> Result<(), HirDisplayError> {
1000-
if f.should_truncate() {
1001-
return write!(f, "{TYPE_HINT_TRUNCATION}");
1024+
let truncated = f.should_truncate();
1025+
if truncated {
1026+
f.fmt.start_truncated();
10021027
}
10031028

10041029
match self.kind(Interner) {
@@ -1408,11 +1433,18 @@ impl HirDisplay for Ty {
14081433
_ => unreachable!(),
14091434
}
14101435
if sig.params().is_empty() {
1411-
} else if f.should_truncate() {
1412-
write!(f, "{TYPE_HINT_TRUNCATION}")?;
14131436
} else {
1437+
let truncated = f.should_truncate();
1438+
if truncated {
1439+
f.fmt.start_truncated();
1440+
}
1441+
14141442
f.write_joined(sig.params(), ", ")?;
1415-
};
1443+
1444+
if truncated {
1445+
f.fmt.end_truncated();
1446+
}
1447+
}
14161448
match f.closure_style {
14171449
ClosureStyle::ImplFn => write!(f, ")")?,
14181450
ClosureStyle::RANotation => write!(f, "|")?,
@@ -1576,6 +1608,11 @@ impl HirDisplay for Ty {
15761608
}
15771609
TyKind::CoroutineWitness(..) => write!(f, "{{coroutine witness}}")?,
15781610
}
1611+
1612+
if truncated {
1613+
f.fmt.end_truncated();
1614+
}
1615+
15791616
Ok(())
15801617
}
15811618
}
@@ -1929,8 +1966,9 @@ impl HirDisplay for TraitRef {
19291966

19301967
impl HirDisplay for WhereClause {
19311968
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
1932-
if f.should_truncate() {
1933-
return write!(f, "{TYPE_HINT_TRUNCATION}");
1969+
let truncated = f.should_truncate();
1970+
if truncated {
1971+
f.fmt.start_truncated();
19341972
}
19351973

19361974
match self {
@@ -1963,6 +2001,11 @@ impl HirDisplay for WhereClause {
19632001
WhereClause::TypeOutlives(..) => {}
19642002
WhereClause::LifetimeOutlives(..) => {}
19652003
}
2004+
2005+
if truncated {
2006+
f.fmt.end_truncated();
2007+
}
2008+
19662009
Ok(())
19672010
}
19682011
}

crates/ide/src/inlay_hints.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ struct InlayHintLabelBuilder<'a> {
662662
last_part: String,
663663
resolve: bool,
664664
location: Option<LazyProperty<FileRange>>,
665+
tooltip: Option<LazyProperty<InlayTooltip>>,
665666
}
666667

667668
impl fmt::Write for InlayHintLabelBuilder<'_> {
@@ -673,6 +674,7 @@ impl fmt::Write for InlayHintLabelBuilder<'_> {
673674
impl HirWrite for InlayHintLabelBuilder<'_> {
674675
fn start_location_link(&mut self, def: ModuleDefId) {
675676
never!(self.location.is_some(), "location link is already started");
677+
never!(self.tooltip.is_some(), "tooltip is already started");
676678
self.make_new_part();
677679

678680
self.location = Some(if self.resolve {
@@ -689,6 +691,25 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
689691
fn end_location_link(&mut self) {
690692
self.make_new_part();
691693
}
694+
695+
fn start_truncated(&mut self) {
696+
never!(self.location.is_some(), "location link is already started");
697+
never!(self.tooltip.is_some(), "tooltip is already started");
698+
self.make_new_part();
699+
}
700+
701+
fn end_truncated(&mut self) {
702+
self.tooltip = Some(if self.resolve {
703+
self.last_part = "…".to_owned();
704+
LazyProperty::Lazy
705+
} else {
706+
// TODO: tricky
707+
let tooltip = mem::replace(&mut self.last_part, "…".to_owned());
708+
LazyProperty::Computed(InlayTooltip::String(tooltip))
709+
});
710+
711+
self.make_new_part();
712+
}
692713
}
693714

694715
impl InlayHintLabelBuilder<'_> {
@@ -698,7 +719,7 @@ impl InlayHintLabelBuilder<'_> {
698719
self.result.parts.push(InlayHintLabelPart {
699720
text,
700721
linked_location: self.location.take(),
701-
tooltip: None,
722+
tooltip: self.tooltip.take(),
702723
});
703724
}
704725
}
@@ -768,6 +789,7 @@ fn label_of_ty(
768789
db: sema.db,
769790
last_part: String::new(),
770791
location: None,
792+
tooltip: None,
771793
result: InlayHintLabel::default(),
772794
resolve: config.fields_to_resolve.resolve_label_location,
773795
};

0 commit comments

Comments
 (0)