Properly normalize completion labels with multi-byte characters (#25150)
Closes https://github.com/zed-industries/zed/issues/25142 Release Notes: - Fixed panics on completion with multi-byte characters input
This commit is contained in:
parent
d4414efd6f
commit
094430e5a2
1 changed files with 45 additions and 21 deletions
|
@ -8944,7 +8944,7 @@ fn ensure_uniform_list_compatible_label(label: &mut CodeLabel) {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
new_text.push(c);
|
new_text.push(c);
|
||||||
new_idx += 1;
|
new_idx += c.len_utf8();
|
||||||
last_char_was_space = false;
|
last_char_was_space = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9015,27 +9015,16 @@ fn ensure_uniform_list_compatible_label(label: &mut CodeLabel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[test]
|
mod tests {
|
||||||
fn test_glob_literal_prefix() {
|
use language::HighlightId;
|
||||||
assert_eq!(glob_literal_prefix(Path::new("**/*.js")), Path::new(""));
|
|
||||||
assert_eq!(
|
|
||||||
glob_literal_prefix(Path::new("node_modules/**/*.js")),
|
|
||||||
Path::new("node_modules")
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
glob_literal_prefix(Path::new("foo/{bar,baz}.js")),
|
|
||||||
Path::new("foo")
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
glob_literal_prefix(Path::new("foo/bar/baz.js")),
|
|
||||||
Path::new("foo/bar/baz.js")
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
use super::*;
|
||||||
{
|
|
||||||
assert_eq!(glob_literal_prefix(Path::new("**\\*.js")), Path::new(""));
|
#[test]
|
||||||
|
fn test_glob_literal_prefix() {
|
||||||
|
assert_eq!(glob_literal_prefix(Path::new("**/*.js")), Path::new(""));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
glob_literal_prefix(Path::new("node_modules\\**/*.js")),
|
glob_literal_prefix(Path::new("node_modules/**/*.js")),
|
||||||
Path::new("node_modules")
|
Path::new("node_modules")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -9043,8 +9032,43 @@ fn test_glob_literal_prefix() {
|
||||||
Path::new("foo")
|
Path::new("foo")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
glob_literal_prefix(Path::new("foo\\bar\\baz.js")),
|
glob_literal_prefix(Path::new("foo/bar/baz.js")),
|
||||||
Path::new("foo/bar/baz.js")
|
Path::new("foo/bar/baz.js")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
assert_eq!(glob_literal_prefix(Path::new("**\\*.js")), Path::new(""));
|
||||||
|
assert_eq!(
|
||||||
|
glob_literal_prefix(Path::new("node_modules\\**/*.js")),
|
||||||
|
Path::new("node_modules")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
glob_literal_prefix(Path::new("foo/{bar,baz}.js")),
|
||||||
|
Path::new("foo")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
glob_literal_prefix(Path::new("foo\\bar\\baz.js")),
|
||||||
|
Path::new("foo/bar/baz.js")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_multi_len_chars_normalization() {
|
||||||
|
let mut label = CodeLabel {
|
||||||
|
text: "myElˇ (parameter) myElˇ: {\n foo: string;\n}".to_string(),
|
||||||
|
runs: vec![(0..6, HighlightId(1))],
|
||||||
|
filter_range: 0..6,
|
||||||
|
};
|
||||||
|
ensure_uniform_list_compatible_label(&mut label);
|
||||||
|
assert_eq!(
|
||||||
|
label,
|
||||||
|
CodeLabel {
|
||||||
|
text: "myElˇ (parameter) myElˇ: { foo: string; }".to_string(),
|
||||||
|
runs: vec![(0..6, HighlightId(1))],
|
||||||
|
filter_range: 0..6,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue