editor: Fix panic in inlay hint while padding (#36405)
Closes #36247 Fix a panic when padding inlay hints if the last character is a multi-byte character. Regressed in https://github.com/zed-industries/zed/pull/35786. Release Notes: - Fixed a crash that could occur when an inlay hint ended with `...`.
This commit is contained in:
parent
7703cdb70b
commit
1adbbfc6f4
1 changed files with 24 additions and 1 deletions
|
@ -48,7 +48,7 @@ pub struct Inlay {
|
||||||
impl Inlay {
|
impl Inlay {
|
||||||
pub fn hint(id: usize, position: Anchor, hint: &project::InlayHint) -> Self {
|
pub fn hint(id: usize, position: Anchor, hint: &project::InlayHint) -> Self {
|
||||||
let mut text = hint.text();
|
let mut text = hint.text();
|
||||||
if hint.padding_right && text.chars_at(text.len().saturating_sub(1)).next() != Some(' ') {
|
if hint.padding_right && text.reversed_chars_at(text.len()).next() != Some(' ') {
|
||||||
text.push(" ");
|
text.push(" ");
|
||||||
}
|
}
|
||||||
if hint.padding_left && text.chars_at(0).next() != Some(' ') {
|
if hint.padding_left && text.chars_at(0).next() != Some(' ') {
|
||||||
|
@ -1305,6 +1305,29 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_inlay_hint_padding_with_multibyte_chars() {
|
||||||
|
assert_eq!(
|
||||||
|
Inlay::hint(
|
||||||
|
0,
|
||||||
|
Anchor::min(),
|
||||||
|
&InlayHint {
|
||||||
|
label: InlayHintLabel::String("🎨".to_string()),
|
||||||
|
position: text::Anchor::default(),
|
||||||
|
padding_left: true,
|
||||||
|
padding_right: true,
|
||||||
|
tooltip: None,
|
||||||
|
kind: None,
|
||||||
|
resolve_state: ResolveState::Resolved,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.text
|
||||||
|
.to_string(),
|
||||||
|
" 🎨 ",
|
||||||
|
"Should pad single emoji correctly"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_basic_inlays(cx: &mut App) {
|
fn test_basic_inlays(cx: &mut App) {
|
||||||
let buffer = MultiBuffer::build_simple("abcdefghi", cx);
|
let buffer = MultiBuffer::build_simple("abcdefghi", cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue