Skip to content

Commit

Permalink
Remove replica_id from MultiBuffers (zed-industries#18141)
Browse files Browse the repository at this point in the history
This PR removes the `replica_id` field from the `MultiBuffer` struct.

We were only ever referencing this field to pass when constructing a
`MultiBuffer`, and never used it outside of that.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Sep 20, 2024
1 parent 5f1046b commit ab1d466
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 84 deletions.
5 changes: 2 additions & 3 deletions crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2814,9 +2814,8 @@ impl ContextEditor {
} else {
// If there are multiple buffers or suggestion groups, create a multibuffer
let multibuffer = cx.new_model(|cx| {
let replica_id = project.read(cx).replica_id();
let mut multibuffer = MultiBuffer::new(replica_id, Capability::ReadWrite)
.with_title(resolved_step.title.clone());
let mut multibuffer =
MultiBuffer::new(Capability::ReadWrite).with_title(resolved_step.title.clone());
for (buffer, groups) in &resolved_step.suggestion_groups {
let excerpt_ids = multibuffer.push_excerpts(
buffer.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl InlineAssistant {

let deleted_lines_editor = cx.new_view(|cx| {
let multi_buffer = cx.new_model(|_| {
MultiBuffer::without_headers(0, language::Capability::ReadOnly)
MultiBuffer::without_headers(language::Capability::ReadOnly)
});
multi_buffer.update(cx, |multi_buffer, cx| {
multi_buffer.push_excerpts(
Expand Down
2 changes: 1 addition & 1 deletion crates/collab/src/tests/following_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async fn test_basic_following(
.get_open_buffer(&(worktree_id, "2.txt").into(), cx)
.unwrap()
});
let mut result = MultiBuffer::new(0, Capability::ReadWrite);
let mut result = MultiBuffer::new(Capability::ReadWrite);
result.push_excerpts(
buffer_a1,
[ExcerptRange {
Expand Down
4 changes: 2 additions & 2 deletions crates/copilot/src/copilot_completion_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ mod tests {
let buffer_1 = cx.new_model(|cx| Buffer::local("a = 1\nb = 2\n", cx));
let buffer_2 = cx.new_model(|cx| Buffer::local("c = 3\nd = 4\n", cx));
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, language::Capability::ReadWrite);
let mut multibuffer = MultiBuffer::new(language::Capability::ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[ExcerptRange {
Expand Down Expand Up @@ -1018,7 +1018,7 @@ mod tests {
.unwrap();

let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, language::Capability::ReadWrite);
let mut multibuffer = MultiBuffer::new(language::Capability::ReadWrite);
multibuffer.push_excerpts(
private_buffer.clone(),
[ExcerptRange {
Expand Down
7 changes: 1 addition & 6 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ impl ProjectDiagnosticsEditor {
cx.on_focus_out(&focus_handle, |this, _event, cx| this.focus_out(cx))
.detach();

let excerpts = cx.new_model(|cx| {
MultiBuffer::new(
project_handle.read(cx).replica_id(),
project_handle.read(cx).capability(),
)
});
let excerpts = cx.new_model(|cx| MultiBuffer::new(project_handle.read(cx).capability()));
let editor = cx.new_view(|cx| {
let mut editor =
Editor::for_multibuffer(excerpts.clone(), Some(project_handle.clone()), false, cx);
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ mod tests {

let mut excerpt_ids = Vec::new();
let multi_buffer = cx.new_model(|cx| {
let mut multi_buffer = MultiBuffer::new(0, Capability::ReadWrite);
let mut multi_buffer = MultiBuffer::new(Capability::ReadWrite);
excerpt_ids.extend(multi_buffer.push_excerpts(
buffer1.clone(),
[ExcerptRange {
Expand Down
22 changes: 4 additions & 18 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,10 +2155,6 @@ impl Editor {
});
}

pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
self.buffer.read(cx).replica_id()
}

pub fn leader_peer_id(&self) -> Option<PeerId> {
self.leader_peer_id
}
Expand Down Expand Up @@ -4758,8 +4754,6 @@ impl Editor {
title: String,
mut cx: AsyncWindowContext,
) -> Result<()> {
let replica_id = this.update(&mut cx, |this, cx| this.replica_id(cx))?;

let mut entries = transaction.0.into_iter().collect::<Vec<_>>();
cx.update(|cx| {
entries.sort_unstable_by_key(|(buffer, _)| {
Expand Down Expand Up @@ -4802,8 +4796,7 @@ impl Editor {

let mut ranges_to_highlight = Vec::new();
let excerpt_buffer = cx.new_model(|cx| {
let mut multibuffer =
MultiBuffer::new(replica_id, Capability::ReadWrite).with_title(title);
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite).with_title(title);
for (buffer_handle, transaction) in &entries {
let buffer = buffer_handle.read(cx);
ranges_to_highlight.extend(
Expand Down Expand Up @@ -9610,7 +9603,6 @@ impl Editor {
})
})
} else if !definitions.is_empty() {
let replica_id = self.replica_id(cx);
cx.spawn(|editor, mut cx| async move {
let (title, location_tasks, workspace) = editor
.update(&mut cx, |editor, cx| {
Expand Down Expand Up @@ -9663,9 +9655,7 @@ impl Editor {
};
let opened = workspace
.update(&mut cx, |workspace, cx| {
Self::open_locations_in_multibuffer(
workspace, locations, replica_id, title, split, cx,
)
Self::open_locations_in_multibuffer(workspace, locations, title, split, cx)
})
.ok();

Expand Down Expand Up @@ -9762,7 +9752,6 @@ impl Editor {
}

let (buffer, head) = multi_buffer.text_anchor_for_position(head, cx)?;
let replica_id = self.replica_id(cx);
let workspace = self.workspace()?;
let project = workspace.read(cx).project().clone();
let references = project.update(cx, |project, cx| project.references(&buffer, head, cx));
Expand Down Expand Up @@ -9803,9 +9792,7 @@ impl Editor {
)
})
.unwrap();
Self::open_locations_in_multibuffer(
workspace, locations, replica_id, title, false, cx,
);
Self::open_locations_in_multibuffer(workspace, locations, title, false, cx);
Navigated::Yes
})
}))
Expand All @@ -9815,7 +9802,6 @@ impl Editor {
pub fn open_locations_in_multibuffer(
workspace: &mut Workspace,
mut locations: Vec<Location>,
replica_id: ReplicaId,
title: String,
split: bool,
cx: &mut ViewContext<Workspace>,
Expand All @@ -9827,7 +9813,7 @@ impl Editor {
let capability = workspace.project().read(cx).capability();

let excerpt_buffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(replica_id, capability);
let mut multibuffer = MultiBuffer::new(capability);
while let Some(location) = locations.next() {
let buffer = location.buffer.read(cx);
let mut ranges_for_buffer = Vec::new();
Expand Down
20 changes: 10 additions & 10 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ fn test_indent_outdent_with_excerpts(cx: &mut TestAppContext) {
Buffer::local("const c: usize = 3;\n", cx).with_language(rust_language, cx)
});
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
toml_buffer.clone(),
[ExcerptRange {
Expand Down Expand Up @@ -6671,7 +6671,7 @@ async fn test_multibuffer_format_during_save(cx: &mut gpui::TestAppContext) {
.unwrap();

let multi_buffer = cx.new_model(|cx| {
let mut multi_buffer = MultiBuffer::new(0, ReadWrite);
let mut multi_buffer = MultiBuffer::new(ReadWrite);
multi_buffer.push_excerpts(
buffer_1.clone(),
[
Expand Down Expand Up @@ -8614,7 +8614,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {

let buffer = cx.new_model(|cx| Buffer::local(sample_text(3, 4, 'a'), cx));
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
buffer.clone(),
[
Expand Down Expand Up @@ -8698,7 +8698,7 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
});
let buffer = cx.new_model(|cx| Buffer::local(initial_text, cx));
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(buffer, excerpt_ranges, cx);
multibuffer
});
Expand Down Expand Up @@ -8757,7 +8757,7 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
let buffer = cx.new_model(|cx| Buffer::local(sample_text(3, 4, 'a'), cx));
let mut excerpt1_id = None;
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
excerpt1_id = multibuffer
.push_excerpts(
buffer.clone(),
Expand Down Expand Up @@ -8842,7 +8842,7 @@ fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) {
let buffer = cx.new_model(|cx| Buffer::local(sample_text(3, 4, 'a'), cx));
let mut excerpt1_id = None;
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
excerpt1_id = multibuffer
.push_excerpts(
buffer.clone(),
Expand Down Expand Up @@ -9230,7 +9230,7 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
let cx = &mut VisualTestContext::from_window(*workspace.deref(), cx);

let leader = pane.update(cx, |_, cx| {
let multibuffer = cx.new_model(|_| MultiBuffer::new(0, ReadWrite));
let multibuffer = cx.new_model(|_| MultiBuffer::new(ReadWrite));
cx.new_view(|cx| build_editor(multibuffer.clone(), cx))
});

Expand Down Expand Up @@ -10685,7 +10685,7 @@ async fn test_multibuffer_reverts(cx: &mut gpui::TestAppContext) {
diff_every_buffer_row(&buffer_3, sample_text_3.clone(), cols, cx);

let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
Expand Down Expand Up @@ -10825,7 +10825,7 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut gpui::TestAppContext) {
let buffer_3 = cx.new_model(|cx| Buffer::local(sample_text_3.clone(), cx));

let multi_buffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
Expand Down Expand Up @@ -11764,7 +11764,7 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
});

let multi_buffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod tests {
cx.background_executor.run_until_parked();

let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/hunk_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ fn editor_with_deleted_text(
let parent_editor = cx.view().downgrade();
let editor = cx.new_view(|cx| {
let multi_buffer =
cx.new_model(|_| MultiBuffer::without_headers(0, language::Capability::ReadOnly));
cx.new_model(|_| MultiBuffer::without_headers(language::Capability::ReadOnly));
multi_buffer.update(cx, |multi_buffer, cx| {
multi_buffer.push_excerpts(
diff_base_buffer,
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/inlay_hint_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,7 @@ pub mod tests {
.await
.unwrap();
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, Capability::ReadWrite);
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
Expand Down Expand Up @@ -2957,7 +2957,7 @@ pub mod tests {
})
.await
.unwrap();
let multibuffer = cx.new_model(|_| MultiBuffer::new(0, Capability::ReadWrite));
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
let (buffer_1_excerpts, buffer_2_excerpts) = multibuffer.update(cx, |multibuffer, cx| {
let buffer_1_excerpts = multibuffer.push_excerpts(
buffer_1.clone(),
Expand Down
3 changes: 1 addition & 2 deletions crates/editor/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl FollowableItem for Editor {
unreachable!()
};

let replica_id = project.read(cx).replica_id();
let buffer_ids = state
.excerpts
.iter()
Expand All @@ -92,7 +91,7 @@ impl FollowableItem for Editor {
if state.singleton && buffers.len() == 1 {
multibuffer = MultiBuffer::singleton(buffers.pop().unwrap(), cx)
} else {
multibuffer = MultiBuffer::new(replica_id, project.read(cx).capability());
multibuffer = MultiBuffer::new(project.read(cx).capability());
let mut excerpts = state.excerpts.into_iter().peekable();
while let Some(excerpt) = excerpts.peek() {
let Ok(buffer_id) = BufferId::new(excerpt.buffer_id) else {
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ mod tests {

let buffer = cx.new_model(|cx| Buffer::local("abc\ndefg\nhijkl\nmn", cx));
let multibuffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, Capability::ReadWrite);
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite);
multibuffer.push_excerpts(
buffer.clone(),
[
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/test/editor_test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl EditorTestContext {
cx: &mut gpui::TestAppContext,
excerpts: [&str; COUNT],
) -> EditorTestContext {
let mut multibuffer = MultiBuffer::new(0, language::Capability::ReadWrite);
let mut multibuffer = MultiBuffer::new(language::Capability::ReadWrite);
let buffer = cx.new_model(|cx| {
for excerpt in excerpts.into_iter() {
let (text, ranges) = marked_text_ranges(excerpt, false);
Expand Down
Loading

0 comments on commit ab1d466

Please sign in to comment.