Reduce amount of allocations in RustLsp label handling (#35786)

There can be a lot of completions after all


Release Notes:

- N/A
This commit is contained in:
Lukas Wirth 2025-08-07 15:24:29 +02:00 committed by GitHub
parent c397027ec2
commit 4dbd24d75f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 40 additions and 65 deletions

View file

@ -48,16 +48,16 @@ pub struct Inlay {
impl Inlay {
pub fn hint(id: usize, position: Anchor, hint: &project::InlayHint) -> Self {
let mut text = hint.text();
if hint.padding_right && !text.ends_with(' ') {
text.push(' ');
if hint.padding_right && text.chars_at(text.len().saturating_sub(1)).next() != Some(' ') {
text.push(" ");
}
if hint.padding_left && !text.starts_with(' ') {
text.insert(0, ' ');
if hint.padding_left && text.chars_at(0).next() != Some(' ') {
text.push_front(" ");
}
Self {
id: InlayId::Hint(id),
position,
text: text.into(),
text,
color: None,
}
}
@ -737,13 +737,13 @@ impl InlayMap {
Inlay::mock_hint(
post_inc(next_inlay_id),
snapshot.buffer.anchor_at(position, bias),
text.clone(),
&text,
)
} else {
Inlay::edit_prediction(
post_inc(next_inlay_id),
snapshot.buffer.anchor_at(position, bias),
text.clone(),
&text,
)
};
let inlay_id = next_inlay.id;
@ -1694,7 +1694,7 @@ mod tests {
(offset, inlay.clone())
})
.collect::<Vec<_>>();
let mut expected_text = Rope::from(buffer_snapshot.text());
let mut expected_text = Rope::from(&buffer_snapshot.text());
for (offset, inlay) in inlays.iter().rev() {
expected_text.replace(*offset..*offset, &inlay.text.to_string());
}

View file

@ -3546,7 +3546,7 @@ pub mod tests {
let excerpt_hints = excerpt_hints.read();
for id in &excerpt_hints.ordered_hints {
let hint = &excerpt_hints.hints_by_id[id];
let mut label = hint.text();
let mut label = hint.text().to_string();
if hint.padding_left {
label.insert(0, ' ');
}

View file

@ -191,7 +191,7 @@ impl Editor {
if let Some(language) = language {
for signature in &mut signature_help.signatures {
let text = Rope::from(signature.label.to_string());
let text = Rope::from(signature.label.as_ref());
let highlights = language
.highlight_text(&text, 0..signature.label.len())
.into_iter()