mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
Merge pull request #18820 from dfireBird/fix-space-char-on-literal-render
Fix no space insert before and after if value is only spaces
This commit is contained in:
commit
d3dd40f636
2 changed files with 38 additions and 2 deletions
|
@ -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}"),
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue