Don't render multi-line literal values

This commit is contained in:
Lukas Wirth 2024-05-13 12:56:02 +02:00
parent a39c0493a1
commit 5b696bac5c
2 changed files with 29 additions and 1 deletions

View File

@ -564,7 +564,13 @@ pub(super) fn literal(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) ->
let mut s = format!("```rust\n{ty}\n```\n___\n\n"); let mut s = format!("```rust\n{ty}\n```\n___\n\n");
match value { match value {
Ok(value) => format_to!(s, "value of literal: {value}"), Ok(value) => {
if let Some(newline) = value.find('\n') {
format_to!(s, "value of literal (truncated up to newline): {}", &value[..newline])
} else {
format_to!(s, "value of literal: {value}")
}
}
Err(error) => format_to!(s, "invalid literal: {error}"), Err(error) => format_to!(s, "invalid literal: {error}"),
} }
Some(s.into()) Some(s.into())

View File

@ -7814,6 +7814,28 @@ fn main() {
value of literal: 🦀\u{1f980}\\\x41 value of literal: 🦀\u{1f980}\\\x41
"#]], "#]],
); );
check(
r#"
fn main() {
$0r"🦀\u{1f980}\\\x41
fsdghs";
}
"#,
expect![[r#"
*r"🦀\u{1f980}\\\x41
fsdghs"*
```rust
&str
```
___
value of literal (truncated up to newline): 🦀\u{1f980}\\\x41
"#]],
);
} }
#[test] #[test]