Remove hover inlay tooltips, replace them with location links

This commit is contained in:
Lukas Wirth 2023-01-14 12:19:29 +01:00
parent aafb0f1f8d
commit 60075a6625
15 changed files with 187 additions and 380 deletions

View file

@ -44,27 +44,12 @@ pub(super) fn hints(
mode_and_needs_parens_for_adjustment_hints(expr, config.adjustment_hints_mode);
if needs_outer_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
}
if postfix && needs_inner_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
}
let (mut tmp0, mut tmp1);
@ -118,30 +103,14 @@ pub(super) fn hints(
InlayKind::AdjustmentHint
},
label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() },
tooltip: None,
});
}
if !postfix && needs_inner_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
}
if needs_outer_parens {
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
}
Some(())
}

View file

@ -12,9 +12,7 @@ use syntax::{
match_ast,
};
use crate::{
inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip,
};
use crate::{inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind};
use super::label_of_ty;
@ -22,7 +20,7 @@ pub(super) fn hints(
acc: &mut Vec<InlayHint>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
_file_id: FileId,
pat: &ast::IdentPat,
) -> Option<()> {
if !config.type_hints {
@ -52,10 +50,6 @@ pub(super) fn hints(
},
kind: InlayKind::TypeHint,
label,
tooltip: pat
.name()
.map(|it| it.syntax().text_range())
.map(|it| InlayTooltip::HoverRanged(file_id, it)),
});
Some(())
@ -326,14 +320,6 @@ fn main(a: SliceIter<'_, Container>) {
label: [
"impl Iterator<Item = impl Iterator<Item = &&str>>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
484..554,
),
),
},
InlayHint {
range: 484..485,
@ -350,6 +336,7 @@ fn main(a: SliceIter<'_, Container>) {
range: 289..298,
},
),
tooltip: "",
},
"<",
InlayHintLabelPart {
@ -362,17 +349,10 @@ fn main(a: SliceIter<'_, Container>) {
range: 238..247,
},
),
tooltip: "",
},
">",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
484..485,
),
),
},
]
"#]],

View file

@ -7,7 +7,7 @@ use ide_db::RootDatabase;
use syntax::ast::{self, AstNode};
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
use crate::{InlayHint, InlayHintsConfig, InlayKind};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -44,7 +44,6 @@ pub(super) fn hints(
range,
kind: InlayKind::BindingModeHint,
label: r.to_string().into(),
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
});
});
match pat {
@ -59,22 +58,11 @@ pub(super) fn hints(
range: pat.syntax().text_range(),
kind: InlayKind::BindingModeHint,
label: bm.to_string().into(),
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
});
}
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::OpeningParenthesis,
label: "(".into(),
tooltip: None,
});
acc.push(InlayHint {
range: pat.syntax().text_range(),
kind: InlayKind::ClosingParenthesis,
label: ")".into(),
tooltip: None,
});
acc.push(InlayHint::opening_paren(pat.syntax().text_range()));
acc.push(InlayHint::closing_paren(pat.syntax().text_range()));
}
_ => (),
}

View file

@ -5,7 +5,7 @@ use syntax::{
Direction, NodeOrToken, SyntaxKind, T,
};
use crate::{FileId, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
use crate::{FileId, InlayHint, InlayHintsConfig, InlayKind};
use super::label_of_ty;
@ -13,7 +13,7 @@ pub(super) fn hints(
acc: &mut Vec<InlayHint>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
_file_id: FileId,
expr: &ast::Expr,
) -> Option<()> {
if !config.chaining_hints {
@ -61,7 +61,6 @@ pub(super) fn hints(
range: expr.syntax().text_range(),
kind: InlayKind::ChainingHint,
label: label_of_ty(famous_defs, config, ty)?,
tooltip: Some(InlayTooltip::HoverRanged(file_id, expr.syntax().text_range())),
});
}
}
@ -124,17 +123,10 @@ fn main() {
range: 63..64,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
147..172,
),
),
},
InlayHint {
range: 147..154,
@ -151,17 +143,10 @@ fn main() {
range: 7..8,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
147..154,
),
),
},
]
"#]],
@ -214,14 +199,6 @@ fn main() {
label: [
"C",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
143..190,
),
),
},
InlayHint {
range: 143..179,
@ -229,14 +206,6 @@ fn main() {
label: [
"B",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
143..179,
),
),
},
]
"#]],
@ -282,17 +251,10 @@ fn main() {
range: 51..52,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
143..190,
),
),
},
InlayHint {
range: 143..179,
@ -309,17 +271,10 @@ fn main() {
range: 29..30,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
143..179,
),
),
},
]
"#]],
@ -366,6 +321,7 @@ fn main() {
range: 23..24,
},
),
tooltip: "",
},
"<",
InlayHintLabelPart {
@ -378,17 +334,10 @@ fn main() {
range: 55..56,
},
),
tooltip: "",
},
"<i32, bool>>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
246..283,
),
),
},
InlayHint {
range: 246..265,
@ -405,6 +354,7 @@ fn main() {
range: 7..8,
},
),
tooltip: "",
},
"<",
InlayHintLabelPart {
@ -417,17 +367,10 @@ fn main() {
range: 55..56,
},
),
tooltip: "",
},
"<i32, bool>>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
246..265,
),
),
},
]
"#]],
@ -467,14 +410,6 @@ fn main() {
label: [
"impl Iterator<Item = ()>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
174..241,
),
),
},
InlayHint {
range: 174..224,
@ -482,14 +417,6 @@ fn main() {
label: [
"impl Iterator<Item = ()>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
174..224,
),
),
},
InlayHint {
range: 174..206,
@ -497,14 +424,6 @@ fn main() {
label: [
"impl Iterator<Item = ()>",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
174..206,
),
),
},
InlayHint {
range: 174..189,
@ -521,17 +440,10 @@ fn main() {
range: 24..30,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
174..189,
),
),
},
]
"#]],
@ -577,17 +489,10 @@ fn main() {
range: 7..13,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
124..130,
),
),
},
InlayHint {
range: 145..185,
@ -604,17 +509,10 @@ fn main() {
range: 7..13,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
145..185,
),
),
},
InlayHint {
range: 145..168,
@ -631,32 +529,28 @@ fn main() {
range: 7..13,
},
),
tooltip: "",
},
"",
],
tooltip: Some(
HoverRanged(
FileId(
0,
),
145..168,
),
),
},
InlayHint {
range: 222..228,
kind: ParameterHint,
label: [
"self",
],
tooltip: Some(
HoverOffset(
FileId(
0,
InlayHintLabelPart {
text: "self",
linked_location: Some(
FileRange {
file_id: FileId(
0,
),
range: 42..46,
},
),
42,
),
),
tooltip: "",
},
],
},
]
"#]],

View file

@ -5,15 +5,12 @@
//! ```
use hir::{HirDisplay, Semantics};
use ide_db::{base_db::FileRange, RootDatabase};
use smallvec::smallvec;
use syntax::{
ast::{self, AstNode, HasName},
match_ast, SyntaxKind, SyntaxNode, T,
};
use crate::{
inlay_hints::InlayHintLabelPart, FileId, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind,
};
use crate::{FileId, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -117,10 +114,7 @@ pub(super) fn hints(
acc.push(InlayHint {
range: closing_token.text_range(),
kind: InlayKind::ClosingBraceHint,
label: InlayHintLabel {
parts: smallvec![InlayHintLabelPart { text: label, linked_location }],
},
tooltip: None, // provided by label part location
label: InlayHintLabel::simple(label, None, linked_location),
});
None

View file

@ -4,7 +4,7 @@ use syntax::ast::{self, AstNode};
use crate::{
inlay_hints::closure_has_block_body, ClosureReturnTypeHints, InlayHint, InlayHintsConfig,
InlayKind, InlayTooltip,
InlayKind,
};
use super::label_of_ty;
@ -13,7 +13,7 @@ pub(super) fn hints(
acc: &mut Vec<InlayHint>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
_file_id: FileId,
closure: ast::ClosureExpr,
) -> Option<()> {
if config.closure_return_type_hints == ClosureReturnTypeHints::Never {
@ -43,7 +43,6 @@ pub(super) fn hints(
range: param_list.syntax().text_range(),
kind: InlayKind::ClosureReturnTypeHint,
label: label_of_ty(famous_defs, config, ty)?,
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
});
Some(())
}

View file

@ -7,7 +7,9 @@
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
use syntax::ast::{self, AstNode, HasName};
use crate::{DiscriminantHints, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
use crate::{
DiscriminantHints, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind, InlayTooltip,
};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -42,14 +44,17 @@ pub(super) fn hints(
None => name.syntax().text_range(),
},
kind: InlayKind::DiscriminantHint,
label: match &d {
Ok(v) => format!("{}", v).into(),
Err(_) => "?".into(),
},
tooltip: Some(InlayTooltip::String(match &d {
Ok(_) => "enum variant discriminant".into(),
Err(e) => format!("{e:?}").into(),
})),
label: InlayHintLabel::simple(
match &d {
Ok(v) => format!("{}", v),
Err(_) => "?".into(),
},
Some(InlayTooltip::String(match &d {
Ok(_) => "enum variant discriminant".into(),
Err(e) => format!("{e:?}").into(),
})),
None,
),
});
Some(())

View file

@ -10,7 +10,7 @@ use syntax::{
SyntaxToken,
};
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints};
use crate::{InlayHint, InlayHintsConfig, InlayKind, LifetimeElisionHints};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -25,7 +25,6 @@ pub(super) fn hints(
range: t.text_range(),
kind: InlayKind::LifetimeHint,
label: label.into(),
tooltip: Some(InlayTooltip::String("Elided lifetime".into())),
};
let param_list = func.param_list()?;
@ -190,14 +189,12 @@ pub(super) fn hints(
if is_empty { "" } else { ", " }
)
.into(),
tooltip: Some(InlayTooltip::String("Elided lifetimes".into())),
});
}
(None, allocated_lifetimes) => acc.push(InlayHint {
range: func.name()?.syntax().text_range(),
kind: InlayKind::GenericParamListHint,
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
tooltip: Some(InlayTooltip::String("Elided lifetimes".into())),
}),
}
Some(())

View file

@ -8,7 +8,7 @@ use syntax::{
SyntaxKind,
};
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints};
use crate::{InlayHint, InlayHintsConfig, InlayKind, LifetimeElisionHints};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -34,7 +34,6 @@ pub(super) fn hints(
range: t.text_range(),
kind: InlayKind::LifetimeHint,
label: "'static".to_owned().into(),
tooltip: Some(InlayTooltip::String("Elided static lifetime".into())),
});
}
}

View file

@ -10,7 +10,7 @@ use ide_db::{base_db::FileRange, RootDatabase};
use stdx::to_lower_snake_case;
use syntax::ast::{self, AstNode, HasArgList, HasName, UnaryOp};
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
use crate::{InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind};
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
@ -43,12 +43,12 @@ pub(super) fn hints(
!should_hide_param_name_hint(sema, &callable, param_name, arg)
})
.map(|(param, param_name, _, FileRange { range, .. })| {
let mut tooltip = None;
let mut linked_location = None;
if let Some(name) = param {
if let hir::CallableKind::Function(f) = callable.kind() {
// assert the file is cached so we can map out of macros
if let Some(_) = sema.source(f) {
tooltip = sema.original_range_opt(name.syntax());
linked_location = sema.original_range_opt(name.syntax());
}
}
}
@ -56,8 +56,7 @@ pub(super) fn hints(
InlayHint {
range,
kind: InlayKind::ParameterHint,
label: param_name.into(),
tooltip: tooltip.map(|it| InlayTooltip::HoverOffset(it.file_id, it.range.start())),
label: InlayHintLabel::simple(param_name, None, linked_location),
}
});