Skip to content

Commit 3e510eb

Browse files
committed
Don't render multi-line literal values
1 parent 60ed071 commit 3e510eb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/tools/rust-analyzer/crates/ide/src/hover/render.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,13 @@ pub(super) fn literal(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) ->
564564

565565
let mut s = format!("```rust\n{ty}\n```\n___\n\n");
566566
match value {
567-
Ok(value) => format_to!(s, "value of literal: {value}"),
567+
Ok(value) => {
568+
if let Some(newline) = value.find('\n') {
569+
format_to!(s, "value of literal (truncated up to newline): {}", &value[..newline])
570+
} else {
571+
format_to!(s, "value of literal: {value}")
572+
}
573+
}
568574
Err(error) => format_to!(s, "invalid literal: {error}"),
569575
}
570576
Some(s.into())

src/tools/rust-analyzer/crates/ide/src/hover/tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7814,6 +7814,28 @@ fn main() {
78147814
value of literal: 🦀\u{1f980}\\\x41
78157815
"#]],
78167816
);
7817+
check(
7818+
r#"
7819+
fn main() {
7820+
$0r"🦀\u{1f980}\\\x41
7821+
7822+
7823+
fsdghs";
7824+
}
7825+
"#,
7826+
expect![[r#"
7827+
*r"🦀\u{1f980}\\\x41
7828+
7829+
7830+
fsdghs"*
7831+
```rust
7832+
&str
7833+
```
7834+
___
7835+
7836+
value of literal (truncated up to newline): 🦀\u{1f980}\\\x41
7837+
"#]],
7838+
);
78177839
}
78187840

78197841
#[test]

0 commit comments

Comments
 (0)