mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
fix(lsp): slice strings by byte index in code actions (#23387)
Fixes #23361.
This commit is contained in:
parent
9905ff9514
commit
e7d005f95a
@ -1126,9 +1126,11 @@ impl CodeActionCollection {
|
|||||||
/// Prepend the whitespace characters found at the start of line_content to content.
|
/// Prepend the whitespace characters found at the start of line_content to content.
|
||||||
fn prepend_whitespace(content: String, line_content: Option<String>) -> String {
|
fn prepend_whitespace(content: String, line_content: Option<String>) -> String {
|
||||||
if let Some(line) = line_content {
|
if let Some(line) = line_content {
|
||||||
let whitespaces =
|
let whitespace_end = line
|
||||||
line.chars().position(|c| !c.is_whitespace()).unwrap_or(0);
|
.char_indices()
|
||||||
let whitespace = &line[0..whitespaces];
|
.find_map(|(i, c)| (!c.is_whitespace()).then_some(i))
|
||||||
|
.unwrap_or(0);
|
||||||
|
let whitespace = &line[0..whitespace_end];
|
||||||
format!("{}{}", &whitespace, content)
|
format!("{}{}", &whitespace, content)
|
||||||
} else {
|
} else {
|
||||||
content
|
content
|
||||||
@ -1271,4 +1273,13 @@ mod tests {
|
|||||||
"utils/sub_utils"
|
"utils/sub_utils"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_prepend_whitespace() {
|
||||||
|
// Regression test for https://github.com/denoland/deno/issues/23361.
|
||||||
|
assert_eq!(
|
||||||
|
&prepend_whitespace("foo".to_string(), Some("\u{a0}bar".to_string())),
|
||||||
|
"\u{a0}foo"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user