Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 60075a6

Browse files
committed
Remove hover inlay tooltips, replace them with location links
1 parent aafb0f1 commit 60075a6

File tree

15 files changed

+187
-380
lines changed

15 files changed

+187
-380
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use smallvec::{smallvec, SmallVec};
1111
use stdx::never;
1212
use syntax::{
1313
ast::{self, AstNode},
14-
match_ast, NodeOrToken, SyntaxNode, TextRange, TextSize,
14+
match_ast, NodeOrToken, SyntaxNode, TextRange,
1515
};
1616

1717
use crate::{navigation_target::TryToNav, FileId};
@@ -110,16 +110,21 @@ pub struct InlayHint {
110110
pub kind: InlayKind,
111111
/// The actual label to show in the inlay hint.
112112
pub label: InlayHintLabel,
113-
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
114-
/// hover requests to show.
115-
pub tooltip: Option<InlayTooltip>,
113+
}
114+
115+
impl InlayHint {
116+
fn closing_paren(range: TextRange) -> InlayHint {
117+
InlayHint { range, kind: InlayKind::ClosingParenthesis, label: InlayHintLabel::from(")") }
118+
}
119+
fn opening_paren(range: TextRange) -> InlayHint {
120+
InlayHint { range, kind: InlayKind::OpeningParenthesis, label: InlayHintLabel::from("(") }
121+
}
116122
}
117123

118124
#[derive(Debug)]
119125
pub enum InlayTooltip {
120126
String(String),
121-
HoverRanged(FileId, TextRange),
122-
HoverOffset(FileId, TextSize),
127+
Markdown(String),
123128
}
124129

125130
#[derive(Default)]
@@ -128,37 +133,59 @@ pub struct InlayHintLabel {
128133
}
129134

130135
impl InlayHintLabel {
131-
pub fn as_simple_str(&self) -> Option<&str> {
132-
match &*self.parts {
133-
[part] => part.as_simple_str(),
134-
_ => None,
136+
pub fn simple(
137+
s: impl Into<String>,
138+
tooltip: Option<InlayTooltip>,
139+
linked_location: Option<FileRange>,
140+
) -> InlayHintLabel {
141+
InlayHintLabel {
142+
parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location, tooltip }],
135143
}
136144
}
137145

138146
pub fn prepend_str(&mut self, s: &str) {
139147
match &mut *self.parts {
140-
[part, ..] if part.as_simple_str().is_some() => part.text = format!("{s}{}", part.text),
141-
_ => self.parts.insert(0, InlayHintLabelPart { text: s.into(), linked_location: None }),
148+
[InlayHintLabelPart { text, linked_location: None, tooltip: None }, ..] => {
149+
text.insert_str(0, s)
150+
}
151+
_ => self.parts.insert(
152+
0,
153+
InlayHintLabelPart { text: s.into(), linked_location: None, tooltip: None },
154+
),
142155
}
143156
}
144157

145158
pub fn append_str(&mut self, s: &str) {
146159
match &mut *self.parts {
147-
[.., part] if part.as_simple_str().is_some() => part.text.push_str(s),
148-
_ => self.parts.push(InlayHintLabelPart { text: s.into(), linked_location: None }),
160+
[.., InlayHintLabelPart { text, linked_location: None, tooltip: None }] => {
161+
text.push_str(s)
162+
}
163+
_ => self.parts.push(InlayHintLabelPart {
164+
text: s.into(),
165+
linked_location: None,
166+
tooltip: None,
167+
}),
149168
}
150169
}
151170
}
152171

153172
impl From<String> for InlayHintLabel {
154173
fn from(s: String) -> Self {
155-
Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None }] }
174+
Self {
175+
parts: smallvec![InlayHintLabelPart { text: s, linked_location: None, tooltip: None }],
176+
}
156177
}
157178
}
158179

159180
impl From<&str> for InlayHintLabel {
160181
fn from(s: &str) -> Self {
161-
Self { parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
182+
Self {
183+
parts: smallvec![InlayHintLabelPart {
184+
text: s.into(),
185+
linked_location: None,
186+
tooltip: None
187+
}],
188+
}
162189
}
163190
}
164191

@@ -182,25 +209,25 @@ pub struct InlayHintLabelPart {
182209
/// When setting this, no tooltip must be set on the containing hint, or VS Code will display
183210
/// them both.
184211
pub linked_location: Option<FileRange>,
185-
}
186-
187-
impl InlayHintLabelPart {
188-
pub fn as_simple_str(&self) -> Option<&str> {
189-
match self {
190-
Self { text, linked_location: None } => Some(text),
191-
_ => None,
192-
}
193-
}
212+
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
213+
/// hover requests to show.
214+
pub tooltip: Option<InlayTooltip>,
194215
}
195216

196217
impl fmt::Debug for InlayHintLabelPart {
197218
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
198-
match self.as_simple_str() {
199-
Some(string) => string.fmt(f),
200-
None => f
219+
match self {
220+
Self { text, linked_location: None, tooltip: None } => text.fmt(f),
221+
Self { text, linked_location, tooltip } => f
201222
.debug_struct("InlayHintLabelPart")
202-
.field("text", &self.text)
203-
.field("linked_location", &self.linked_location)
223+
.field("text", text)
224+
.field("linked_location", linked_location)
225+
.field(
226+
"tooltip",
227+
&tooltip.as_ref().map_or("", |it| match it {
228+
InlayTooltip::String(it) | InlayTooltip::Markdown(it) => it,
229+
}),
230+
)
204231
.finish(),
205232
}
206233
}
@@ -249,6 +276,7 @@ impl InlayHintLabelBuilder<'_> {
249276
self.result.parts.push(InlayHintLabelPart {
250277
text: take(&mut self.last_part),
251278
linked_location: self.location.take(),
279+
tooltip: None,
252280
});
253281
}
254282

crates/ide/src/inlay_hints/adjustment.rs

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,12 @@ pub(super) fn hints(
4444
mode_and_needs_parens_for_adjustment_hints(expr, config.adjustment_hints_mode);
4545

4646
if needs_outer_parens {
47-
acc.push(InlayHint {
48-
range: expr.syntax().text_range(),
49-
kind: InlayKind::OpeningParenthesis,
50-
label: "(".into(),
51-
tooltip: None,
52-
});
47+
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
5348
}
5449

5550
if postfix && needs_inner_parens {
56-
acc.push(InlayHint {
57-
range: expr.syntax().text_range(),
58-
kind: InlayKind::OpeningParenthesis,
59-
label: "(".into(),
60-
tooltip: None,
61-
});
62-
acc.push(InlayHint {
63-
range: expr.syntax().text_range(),
64-
kind: InlayKind::ClosingParenthesis,
65-
label: ")".into(),
66-
tooltip: None,
67-
});
51+
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
52+
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
6853
}
6954

7055
let (mut tmp0, mut tmp1);
@@ -118,30 +103,14 @@ pub(super) fn hints(
118103
InlayKind::AdjustmentHint
119104
},
120105
label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() },
121-
tooltip: None,
122106
});
123107
}
124108
if !postfix && needs_inner_parens {
125-
acc.push(InlayHint {
126-
range: expr.syntax().text_range(),
127-
kind: InlayKind::OpeningParenthesis,
128-
label: "(".into(),
129-
tooltip: None,
130-
});
131-
acc.push(InlayHint {
132-
range: expr.syntax().text_range(),
133-
kind: InlayKind::ClosingParenthesis,
134-
label: ")".into(),
135-
tooltip: None,
136-
});
109+
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
110+
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
137111
}
138112
if needs_outer_parens {
139-
acc.push(InlayHint {
140-
range: expr.syntax().text_range(),
141-
kind: InlayKind::ClosingParenthesis,
142-
label: ")".into(),
143-
tooltip: None,
144-
});
113+
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
145114
}
146115
Some(())
147116
}

crates/ide/src/inlay_hints/bind_pat.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ use syntax::{
1212
match_ast,
1313
};
1414

15-
use crate::{
16-
inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip,
17-
};
15+
use crate::{inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind};
1816

1917
use super::label_of_ty;
2018

2119
pub(super) fn hints(
2220
acc: &mut Vec<InlayHint>,
2321
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
2422
config: &InlayHintsConfig,
25-
file_id: FileId,
23+
_file_id: FileId,
2624
pat: &ast::IdentPat,
2725
) -> Option<()> {
2826
if !config.type_hints {
@@ -52,10 +50,6 @@ pub(super) fn hints(
5250
},
5351
kind: InlayKind::TypeHint,
5452
label,
55-
tooltip: pat
56-
.name()
57-
.map(|it| it.syntax().text_range())
58-
.map(|it| InlayTooltip::HoverRanged(file_id, it)),
5953
});
6054

6155
Some(())
@@ -326,14 +320,6 @@ fn main(a: SliceIter<'_, Container>) {
326320
label: [
327321
"impl Iterator<Item = impl Iterator<Item = &&str>>",
328322
],
329-
tooltip: Some(
330-
HoverRanged(
331-
FileId(
332-
0,
333-
),
334-
484..554,
335-
),
336-
),
337323
},
338324
InlayHint {
339325
range: 484..485,
@@ -350,6 +336,7 @@ fn main(a: SliceIter<'_, Container>) {
350336
range: 289..298,
351337
},
352338
),
339+
tooltip: "",
353340
},
354341
"<",
355342
InlayHintLabelPart {
@@ -362,17 +349,10 @@ fn main(a: SliceIter<'_, Container>) {
362349
range: 238..247,
363350
},
364351
),
352+
tooltip: "",
365353
},
366354
">",
367355
],
368-
tooltip: Some(
369-
HoverRanged(
370-
FileId(
371-
0,
372-
),
373-
484..485,
374-
),
375-
),
376356
},
377357
]
378358
"#]],

crates/ide/src/inlay_hints/binding_mode.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ide_db::RootDatabase;
77

88
use syntax::ast::{self, AstNode};
99

10-
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
10+
use crate::{InlayHint, InlayHintsConfig, InlayKind};
1111

1212
pub(super) fn hints(
1313
acc: &mut Vec<InlayHint>,
@@ -44,7 +44,6 @@ pub(super) fn hints(
4444
range,
4545
kind: InlayKind::BindingModeHint,
4646
label: r.to_string().into(),
47-
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
4847
});
4948
});
5049
match pat {
@@ -59,22 +58,11 @@ pub(super) fn hints(
5958
range: pat.syntax().text_range(),
6059
kind: InlayKind::BindingModeHint,
6160
label: bm.to_string().into(),
62-
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
6361
});
6462
}
6563
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
66-
acc.push(InlayHint {
67-
range: pat.syntax().text_range(),
68-
kind: InlayKind::OpeningParenthesis,
69-
label: "(".into(),
70-
tooltip: None,
71-
});
72-
acc.push(InlayHint {
73-
range: pat.syntax().text_range(),
74-
kind: InlayKind::ClosingParenthesis,
75-
label: ")".into(),
76-
tooltip: None,
77-
});
64+
acc.push(InlayHint::opening_paren(pat.syntax().text_range()));
65+
acc.push(InlayHint::closing_paren(pat.syntax().text_range()));
7866
}
7967
_ => (),
8068
}

0 commit comments

Comments
 (0)