sum_tree: Replace rayon with futures (#41586)

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Co-authored by: Kate <kate@zed.dev>
This commit is contained in:
Lukas Wirth
2025-10-31 10:39:01 +00:00
committed by GitHub
parent 7c29c6d7a6
commit f2ce06c7b0
67 changed files with 1271 additions and 640 deletions
+2 -1
View File
@@ -1569,6 +1569,7 @@ pub mod tests {
use lsp::LanguageServerId;
use project::Project;
use rand::{Rng, prelude::*};
use rope::Rope;
use settings::{SettingsContent, SettingsStore};
use smol::stream::StreamExt;
use std::{env, sync::Arc};
@@ -2074,7 +2075,7 @@ pub mod tests {
vec![Inlay::edit_prediction(
0,
buffer_snapshot.anchor_after(0),
"\n",
Rope::from_str_small("\n"),
)],
cx,
);
+24 -12
View File
@@ -700,16 +700,20 @@ impl InlayMap {
.collect::<String>();
let next_inlay = if i % 2 == 0 {
use rope::Rope;
Inlay::mock_hint(
post_inc(next_inlay_id),
snapshot.buffer.anchor_at(position, bias),
&text,
Rope::from_str_small(&text),
)
} else {
use rope::Rope;
Inlay::edit_prediction(
post_inc(next_inlay_id),
snapshot.buffer.anchor_at(position, bias),
&text,
Rope::from_str_small(&text),
)
};
let inlay_id = next_inlay.id;
@@ -1301,7 +1305,7 @@ mod tests {
vec![Inlay::mock_hint(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_after(3),
"|123|",
Rope::from_str_small("|123|"),
)],
);
assert_eq!(inlay_snapshot.text(), "abc|123|defghi");
@@ -1378,12 +1382,12 @@ mod tests {
Inlay::mock_hint(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_before(3),
"|123|",
Rope::from_str_small("|123|"),
),
Inlay::edit_prediction(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_after(3),
"|456|",
Rope::from_str_small("|456|"),
),
],
);
@@ -1593,17 +1597,17 @@ mod tests {
Inlay::mock_hint(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_before(0),
"|123|\n",
Rope::from_str_small("|123|\n"),
),
Inlay::mock_hint(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_before(4),
"|456|",
Rope::from_str_small("|456|"),
),
Inlay::edit_prediction(
post_inc(&mut next_inlay_id),
buffer.read(cx).snapshot(cx).anchor_before(7),
"\n|567|\n",
Rope::from_str_small("\n|567|\n"),
),
],
);
@@ -1677,9 +1681,14 @@ mod tests {
(offset, inlay.clone())
})
.collect::<Vec<_>>();
let mut expected_text = Rope::from(&buffer_snapshot.text());
let mut expected_text =
Rope::from_str(&buffer_snapshot.text(), cx.background_executor());
for (offset, inlay) in inlays.iter().rev() {
expected_text.replace(*offset..*offset, &inlay.text().to_string());
expected_text.replace(
*offset..*offset,
&inlay.text().to_string(),
cx.background_executor(),
);
}
assert_eq!(inlay_snapshot.text(), expected_text.to_string());
@@ -2067,7 +2076,7 @@ mod tests {
let inlay = Inlay {
id: InlayId::Hint(0),
position,
content: InlayContent::Text(text::Rope::from(inlay_text)),
content: InlayContent::Text(text::Rope::from_str(inlay_text, cx.background_executor())),
};
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
@@ -2181,7 +2190,10 @@ mod tests {
let inlay = Inlay {
id: InlayId::Hint(0),
position,
content: InlayContent::Text(text::Rope::from(test_case.inlay_text)),
content: InlayContent::Text(text::Rope::from_str(
test_case.inlay_text,
cx.background_executor(),
)),
};
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
+1 -1
View File
@@ -1042,7 +1042,7 @@ mod tests {
let (mut tab_map, _) = TabMap::new(fold_snapshot, tab_size);
let tabs_snapshot = tab_map.set_max_expansion_column(32);
let text = text::Rope::from(tabs_snapshot.text().as_str());
let text = text::Rope::from_str(tabs_snapshot.text().as_str(), cx.background_executor());
log::info!(
"TabMap text (tab size: {}): {:?}",
tab_size,
+5 -4
View File
@@ -863,7 +863,7 @@ impl WrapSnapshot {
}
}
let text = language::Rope::from(self.text().as_str());
let text = language::Rope::from_str_small(self.text().as_str());
let mut input_buffer_rows = self.tab_snapshot.rows(0);
let mut expected_buffer_rows = Vec::new();
let mut prev_tab_row = 0;
@@ -1413,9 +1413,10 @@ mod tests {
}
}
let mut initial_text = Rope::from(initial_snapshot.text().as_str());
let mut initial_text =
Rope::from_str(initial_snapshot.text().as_str(), cx.background_executor());
for (snapshot, patch) in edits {
let snapshot_text = Rope::from(snapshot.text().as_str());
let snapshot_text = Rope::from_str(snapshot.text().as_str(), cx.background_executor());
for edit in &patch {
let old_start = initial_text.point_to_offset(Point::new(edit.new.start, 0));
let old_end = initial_text.point_to_offset(cmp::min(
@@ -1431,7 +1432,7 @@ mod tests {
.chunks_in_range(new_start..new_end)
.collect::<String>();
initial_text.replace(old_start..old_end, &new_text);
initial_text.replace(old_start..old_end, &new_text, cx.background_executor());
}
assert_eq!(initial_text.to_string(), snapshot_text.to_string());
}
+1 -1
View File
@@ -7852,7 +7852,7 @@ impl Editor {
let inlay = Inlay::edit_prediction(
post_inc(&mut self.next_inlay_id),
range.start,
new_text.as_str(),
Rope::from_str_small(new_text.as_str()),
);
inlay_ids.push(inlay.id);
inlays.push(inlay);
+3 -2
View File
@@ -1115,18 +1115,19 @@ mod tests {
let fs = FakeFs::new(cx.executor());
let buffer_initial_text_len = rng.random_range(5..15);
let mut buffer_initial_text = Rope::from(
let mut buffer_initial_text = Rope::from_str(
RandomCharIter::new(&mut rng)
.take(buffer_initial_text_len)
.collect::<String>()
.as_str(),
cx.background_executor(),
);
let mut newline_ixs = (0..buffer_initial_text_len).choose_multiple(&mut rng, 5);
newline_ixs.sort_unstable();
for newline_ix in newline_ixs.into_iter().rev() {
let newline_ix = buffer_initial_text.clip_offset(newline_ix, Bias::Right);
buffer_initial_text.replace(newline_ix..newline_ix, "\n");
buffer_initial_text.replace(newline_ix..newline_ix, "\n", cx.background_executor());
}
log::info!("initial buffer text: {:?}", buffer_initial_text);
+9 -9
View File
@@ -59,10 +59,10 @@ impl Inlay {
pub fn hint(id: InlayId, position: Anchor, hint: &InlayHint) -> Self {
let mut text = hint.text();
if hint.padding_right && text.reversed_chars_at(text.len()).next() != Some(' ') {
text.push(" ");
text.push_small(" ");
}
if hint.padding_left && text.chars_at(0).next() != Some(' ') {
text.push_front(" ");
text.push_front_small(" ");
}
Self {
id,
@@ -72,11 +72,11 @@ impl Inlay {
}
#[cfg(any(test, feature = "test-support"))]
pub fn mock_hint(id: usize, position: Anchor, text: impl Into<Rope>) -> Self {
pub fn mock_hint(id: usize, position: Anchor, text: Rope) -> Self {
Self {
id: InlayId::Hint(id),
position,
content: InlayContent::Text(text.into()),
content: InlayContent::Text(text),
}
}
@@ -88,19 +88,19 @@ impl Inlay {
}
}
pub fn edit_prediction<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self {
pub fn edit_prediction(id: usize, position: Anchor, text: Rope) -> Self {
Self {
id: InlayId::EditPrediction(id),
position,
content: InlayContent::Text(text.into()),
content: InlayContent::Text(text),
}
}
pub fn debugger<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self {
pub fn debugger(id: usize, position: Anchor, text: Rope) -> Self {
Self {
id: InlayId::DebuggerValue(id),
position,
content: InlayContent::Text(text.into()),
content: InlayContent::Text(text),
}
}
@@ -108,7 +108,7 @@ impl Inlay {
static COLOR_TEXT: OnceLock<Rope> = OnceLock::new();
match &self.content {
InlayContent::Text(text) => text,
InlayContent::Color(_) => COLOR_TEXT.get_or_init(|| Rope::from("")),
InlayContent::Color(_) => COLOR_TEXT.get_or_init(|| Rope::from_str_small("")),
}
}
+5 -4
View File
@@ -878,6 +878,7 @@ mod tests {
use gpui::{AppContext as _, font, px};
use language::Capability;
use project::{Project, project_settings::DiagnosticSeverity};
use rope::Rope;
use settings::SettingsStore;
use util::post_inc;
@@ -1024,22 +1025,22 @@ mod tests {
Inlay::edit_prediction(
post_inc(&mut id),
buffer_snapshot.anchor_before(offset),
"test",
Rope::from_str_small("test"),
),
Inlay::edit_prediction(
post_inc(&mut id),
buffer_snapshot.anchor_after(offset),
"test",
Rope::from_str_small("test"),
),
Inlay::mock_hint(
post_inc(&mut id),
buffer_snapshot.anchor_before(offset),
"test",
Rope::from_str_small("test"),
),
Inlay::mock_hint(
post_inc(&mut id),
buffer_snapshot.anchor_after(offset),
"test",
Rope::from_str_small("test"),
),
]
})
+1 -1
View File
@@ -193,7 +193,7 @@ impl Editor {
if let Some(language) = language {
for signature in &mut signature_help.signatures {
let text = Rope::from(signature.label.as_ref());
let text = Rope::from_str_small(signature.label.as_ref());
let highlights = language
.highlight_text(&text, 0..signature.label.len())
.into_iter()