diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index 9d55827fe2..d72acad09f 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -716,16 +716,21 @@ pub(super) fn literal( match value { Ok(value) => { let backtick_len = value.chars().filter(|c| *c == '`').count(); + let spaces_len = value.chars().filter(|c| *c == ' ').count(); let backticks = "`".repeat(backtick_len + 1); + let space_char = if spaces_len == value.len() { "" } else { " " }; if let Some(newline) = value.find('\n') { format_to!( s, - "value of literal (truncated up to newline): {backticks} {} {backticks}", + "value of literal (truncated up to newline): {backticks}{space_char}{}{space_char}{backticks}", &value[..newline] ) } else { - format_to!(s, "value of literal: {backticks} {value} {backticks}") + format_to!( + s, + "value of literal: {backticks}{space_char}{value}{space_char}{backticks}" + ) } } Err(error) => format_to!(s, "invalid literal: {error}"), diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 8ea305ed8e..2e7637e467 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -8303,6 +8303,37 @@ fn main() { value of literal: `` ` `` "#]], ); + check( + r#" +fn main() { + $0r" "; +}"#, + expect![[r#" + *r" "* + ```rust + &str + ``` + ___ + + value of literal: ` ` + "#]], + ); + check( + r#" +fn main() { + $0r" Hello World "; + +}"#, + expect![[r#" + *r" Hello World "* + ```rust + &str + ``` + ___ + + value of literal: ` Hello World ` +"#]], + ) } #[test]