mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Auto merge of #18107 - Veykril:push-oopkquknxqxs, r=Veykril
fix: Don't emit empty inlay hint parts
This commit is contained in:
commit
27fb6d69ea
4 changed files with 24 additions and 38 deletions
|
@ -577,11 +577,14 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
|
||||||
|
|
||||||
impl InlayHintLabelBuilder<'_> {
|
impl InlayHintLabelBuilder<'_> {
|
||||||
fn make_new_part(&mut self) {
|
fn make_new_part(&mut self) {
|
||||||
self.result.parts.push(InlayHintLabelPart {
|
let text = take(&mut self.last_part);
|
||||||
text: take(&mut self.last_part),
|
if !text.is_empty() {
|
||||||
linked_location: self.location.take(),
|
self.result.parts.push(InlayHintLabelPart {
|
||||||
tooltip: None,
|
text,
|
||||||
});
|
linked_location: self.location.take(),
|
||||||
|
tooltip: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish(mut self) -> InlayHintLabel {
|
fn finish(mut self) -> InlayHintLabel {
|
||||||
|
|
|
@ -140,7 +140,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
147..172,
|
147..172,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "B",
|
text: "B",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -153,13 +152,11 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
147..154,
|
147..154,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "A",
|
text: "A",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -172,7 +169,6 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -223,7 +219,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
143..190,
|
143..190,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "C",
|
text: "C",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -236,13 +231,11 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
143..179,
|
143..179,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "B",
|
text: "B",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -255,7 +248,6 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -290,7 +282,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
143..190,
|
143..190,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "C",
|
text: "C",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -303,13 +294,11 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
143..179,
|
143..179,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "B",
|
text: "B",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -322,7 +311,6 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -358,7 +346,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
246..283,
|
246..283,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "B",
|
text: "B",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -390,7 +377,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
246..265,
|
246..265,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "A",
|
text: "A",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -563,7 +549,6 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -598,7 +583,6 @@ fn main() {
|
||||||
(
|
(
|
||||||
124..130,
|
124..130,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "Struct",
|
text: "Struct",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -611,13 +595,11 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
145..185,
|
145..185,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "Struct",
|
text: "Struct",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -630,13 +612,11 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
145..168,
|
145..168,
|
||||||
[
|
[
|
||||||
"",
|
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
text: "Struct",
|
text: "Struct",
|
||||||
linked_location: Some(
|
linked_location: Some(
|
||||||
|
@ -649,7 +629,6 @@ fn main() {
|
||||||
),
|
),
|
||||||
tooltip: "",
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub(super) fn hints(
|
||||||
}
|
}
|
||||||
closing_token = block.r_curly_token()?;
|
closing_token = block.r_curly_token()?;
|
||||||
|
|
||||||
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
|
let lifetime = label.lifetime()?.to_string();
|
||||||
|
|
||||||
(lifetime, Some(label.syntax().text_range()))
|
(lifetime, Some(label.syntax().text_range()))
|
||||||
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
|
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//! Tests live in [`bind_pat`][super::bind_pat] module.
|
//! Tests live in [`bind_pat`][super::bind_pat] module.
|
||||||
use ide_db::famous_defs::FamousDefs;
|
use ide_db::famous_defs::FamousDefs;
|
||||||
use span::EditionedFileId;
|
use span::EditionedFileId;
|
||||||
use stdx::TupleExt;
|
use stdx::{never, TupleExt};
|
||||||
use syntax::ast::{self, AstNode};
|
use syntax::ast::{self, AstNode};
|
||||||
use text_edit::{TextRange, TextSize};
|
use text_edit::{TextRange, TextSize};
|
||||||
|
|
||||||
|
@ -63,17 +63,21 @@ pub(super) fn hints(
|
||||||
// force cache the source file, otherwise sema lookup will potentially panic
|
// force cache the source file, otherwise sema lookup will potentially panic
|
||||||
_ = sema.parse_or_expand(source.file());
|
_ = sema.parse_or_expand(source.file());
|
||||||
|
|
||||||
|
let label = format!(
|
||||||
|
"{}{}",
|
||||||
|
match capture.kind() {
|
||||||
|
hir::CaptureKind::SharedRef => "&",
|
||||||
|
hir::CaptureKind::UniqueSharedRef => "&unique ",
|
||||||
|
hir::CaptureKind::MutableRef => "&mut ",
|
||||||
|
hir::CaptureKind::Move => "",
|
||||||
|
},
|
||||||
|
capture.display_place(sema.db)
|
||||||
|
);
|
||||||
|
if never!(label.is_empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let label = InlayHintLabel::simple(
|
let label = InlayHintLabel::simple(
|
||||||
format!(
|
label,
|
||||||
"{}{}",
|
|
||||||
match capture.kind() {
|
|
||||||
hir::CaptureKind::SharedRef => "&",
|
|
||||||
hir::CaptureKind::UniqueSharedRef => "&unique ",
|
|
||||||
hir::CaptureKind::MutableRef => "&mut ",
|
|
||||||
hir::CaptureKind::Move => "",
|
|
||||||
},
|
|
||||||
capture.display_place(sema.db)
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
source.name().and_then(|name| {
|
source.name().and_then(|name| {
|
||||||
name.syntax().original_file_range_opt(sema.db).map(TupleExt::head).map(Into::into)
|
name.syntax().original_file_range_opt(sema.db).map(TupleExt::head).map(Into::into)
|
||||||
|
|
Loading…
Reference in a new issue