mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-19 11:35:16 +00:00
fix no space insert before and after if value is only spaces
This commit is contained in:
parent
a611d8eb4e
commit
83fcdbf3f6
2 changed files with 38 additions and 2 deletions
|
|
@ -716,16 +716,21 @@ pub(super) fn literal(
|
||||||
match value {
|
match value {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let backtick_len = value.chars().filter(|c| *c == '`').count();
|
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 backticks = "`".repeat(backtick_len + 1);
|
||||||
|
let space_char = if spaces_len == value.len() { "" } else { " " };
|
||||||
|
|
||||||
if let Some(newline) = value.find('\n') {
|
if let Some(newline) = value.find('\n') {
|
||||||
format_to!(
|
format_to!(
|
||||||
s,
|
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]
|
&value[..newline]
|
||||||
)
|
)
|
||||||
} else {
|
} 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}"),
|
Err(error) => format_to!(s, "invalid literal: {error}"),
|
||||||
|
|
|
||||||
|
|
@ -8303,6 +8303,37 @@ fn main() {
|
||||||
value of literal: `` ` ``
|
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]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue