about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-05-13 12:56:02 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-05-13 12:56:02 +0200
commit3e510eb147fc6289fc9d41aec92479e9e1f9c953 (patch)
tree0c180297e6def304ab628e44d48236379eb05c0d
parent60ed071ecc25ffab6669988d78647b47bc7bbf78 (diff)
downloadrust-3e510eb147fc6289fc9d41aec92479e9e1f9c953.tar.gz
rust-3e510eb147fc6289fc9d41aec92479e9e1f9c953.zip
Don't render multi-line literal values
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/render.rs8
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/tests.rs22
2 files changed, 29 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
index e392a8ec380..a166bab37ca 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
@@ -564,7 +564,13 @@ pub(super) fn literal(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) ->
 
     let mut s = format!("```rust\n{ty}\n```\n___\n\n");
     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}"),
     }
     Some(s.into())
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
index b5547c05148..76d86f8edee 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
@@ -7814,6 +7814,28 @@ fn main() {
             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]