Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
multi_buffer: Remove unnecessary reference in `as_singleton` return type (#49447)
Lukas Wirth8244a5c6edcb
diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rsindex 4a04446b6a8..702be48ae4a 100644--- a/crates/agent_ui/src/acp/message_editor.rs+++ b/crates/agent_ui/src/acp/message_editor.rs@@ -681,7 +681,7 @@ impl MessageEditor {editor.insert(&mention_text, window, cx);editor.insert(" ", window, cx);- (*excerpt_id, text_anchor, mention_text.len())+ (excerpt_id, text_anchor, mention_text.len())});let Some((crease_id, tx)) = insert_crease_for_mention(@@ -951,7 +951,7 @@ impl MessageEditor {editor.insert(&mention_text, window, cx);editor.insert(" ", window, cx);- (*excerpt_id, text_anchor, mention_text.len())+ (excerpt_id, text_anchor, mention_text.len())});let Some((crease_id, tx)) = insert_crease_for_mention(diff --git a/crates/agent_ui/src/acp/thread_view/active_thread.rs b/crates/agent_ui/src/acp/thread_view/active_thread.rsindex b7655c51fad..839b58b07e9 100644--- a/crates/agent_ui/src/acp/thread_view/active_thread.rs+++ b/crates/agent_ui/src/acp/thread_view/active_thread.rs@@ -5634,12 +5634,17 @@ impl AcpThreadView {};active_editor.update_in(cx, |editor, window, cx| {- let multibuffer = editor.buffer().read(cx);- let buffer = multibuffer.as_singleton();- if agent_location.buffer.upgrade() == buffer {- let excerpt_id = multibuffer.excerpt_ids().first().cloned();- let anchor =- editor::Anchor::in_buffer(excerpt_id.unwrap(), agent_location.position);+ let singleton = editor+ .buffer()+ .read(cx)+ .read(cx)+ .as_singleton()+ .map(|(a, b, _)| (a, b));+ if let Some((excerpt_id, buffer_id)) = singleton+ && let Some(agent_buffer) = agent_location.buffer.upgrade()+ && agent_buffer.read(cx).remote_id() == buffer_id+ {+ let anchor = editor::Anchor::in_buffer(excerpt_id, agent_location.position);editor.change_selections(Default::default(), window, cx, |selections| {selections.select_anchor_ranges([anchor..anchor]);})diff --git a/crates/agent_ui/src/mention_set.rs b/crates/agent_ui/src/mention_set.rsindex 707e7b45343..7d752eadae5 100644--- a/crates/agent_ui/src/mention_set.rs+++ b/crates/agent_ui/src/mention_set.rs@@ -665,9 +665,9 @@ pub(crate) async fn insert_images_as_context(let text_anchor = cursor_anchor.bias_left(&buffer_snapshot);let multibuffer_anchor = snapshot.buffer_snapshot()- .anchor_in_excerpt(*excerpt_id, text_anchor);+ .anchor_in_excerpt(excerpt_id, text_anchor);editor.insert(&format!("{replacement_text} "), window, cx);- (*excerpt_id, text_anchor, multibuffer_anchor)+ (excerpt_id, text_anchor, multibuffer_anchor)}).ok()else {diff --git a/crates/agent_ui/src/text_thread_editor.rs b/crates/agent_ui/src/text_thread_editor.rsindex 2d4ada96e9f..9e8f7e2a439 100644--- a/crates/agent_ui/src/text_thread_editor.rs+++ b/crates/agent_ui/src/text_thread_editor.rs@@ -687,7 +687,7 @@ impl TextThreadEditor {TextThreadEvent::ParsedSlashCommandsUpdated { removed, updated } => {self.editor.update(cx, |editor, cx| {let buffer = editor.buffer().read(cx).snapshot(cx);- let (&excerpt_id, _, _) = buffer.as_singleton().unwrap();+ let (excerpt_id, _, _) = buffer.as_singleton().unwrap();editor.remove_creases(removed@@ -810,8 +810,7 @@ impl TextThreadEditor {{if let InvokedSlashCommandStatus::Finished = invoked_slash_command.status {let buffer = editor.buffer().read(cx).snapshot(cx);- let (&excerpt_id, _buffer_id, _buffer_snapshot) =- buffer.as_singleton().unwrap();+ let (excerpt_id, _buffer_id, _buffer_snapshot) = buffer.as_singleton().unwrap();let range = buffer.anchor_range_in_excerpt(excerpt_id, invoked_slash_command.range.clone())@@ -831,8 +830,7 @@ impl TextThreadEditor {self.invoked_slash_command_creases.entry(command_id){let buffer = editor.buffer().read(cx).snapshot(cx);- let (&excerpt_id, _buffer_id, _buffer_snapshot) =- buffer.as_singleton().unwrap();+ let (excerpt_id, _buffer_id, _buffer_snapshot) = buffer.as_singleton().unwrap();let context = self.text_thread.downgrade();let range = buffer.anchor_range_in_excerpt(excerpt_id, invoked_slash_command.range.clone())@@ -872,7 +870,7 @@ impl TextThreadEditor {) -> Vec<CreaseId> {self.editor.update(cx, |editor, cx| {let buffer = editor.buffer().read(cx).snapshot(cx);- let excerpt_id = *buffer.as_singleton().unwrap().0;+ let excerpt_id = buffer.as_singleton().unwrap().0;let mut buffer_rows_to_fold = BTreeSet::new();let mut creases = Vec::new();for (section, status) in sections {@@ -921,7 +919,7 @@ impl TextThreadEditor {) {self.editor.update(cx, |editor, cx| {let buffer = editor.buffer().read(cx).snapshot(cx);- let excerpt_id = *buffer.as_singleton().unwrap().0;+ let excerpt_id = buffer.as_singleton().unwrap().0;let mut buffer_rows_to_fold = BTreeSet::new();let mut creases = Vec::new();for section in sections {@@ -1052,7 +1050,7 @@ impl TextThreadEditor {self.editor.update(cx, |editor, cx| {let buffer = editor.buffer().read(cx).snapshot(cx);- let excerpt_id = *buffer.as_singleton().unwrap().0;+ let excerpt_id = buffer.as_singleton().unwrap().0;let mut old_blocks = std::mem::take(&mut self.blocks);let mut blocks_to_remove: HashMap<_, _> = old_blocks.iter()@@ -2028,7 +2026,7 @@ impl TextThreadEditor {fn update_image_blocks(&mut self, cx: &mut Context<Self>) {self.editor.update(cx, |editor, cx| {let buffer = editor.buffer().read(cx).snapshot(cx);- let excerpt_id = *buffer.as_singleton().unwrap().0;+ let excerpt_id = buffer.as_singleton().unwrap().0;let old_blocks = std::mem::take(&mut self.image_blocks);let new_blocks = self.text_threaddiff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex a223949c59d..e723419283c 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -2000,7 +2000,6 @@ impl Editor {return;};let buffer = buffer.clone();- let &excerpt_id = excerpt_id;let buffer_visible_start = scroll_anchor.text_anchor.to_point(&buffer);let max_row = buffer.max_point().row;@@ -24624,7 +24623,7 @@ impl Editor {};let nav_history = editor.nav_history.take();let multibuffer_snapshot = editor.buffer().read(cx).snapshot(cx);- let Some((&excerpt_id, _, buffer_snapshot)) =+ let Some((excerpt_id, _, buffer_snapshot)) =multibuffer_snapshot.as_singleton()else {return;diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex 3de25131508..b20d73a2895 100644--- a/crates/editor/src/items.rs+++ b/crates/editor/src/items.rs@@ -1421,7 +1421,7 @@ impl ProjectItem for Editor {}let (top_row, offset) = restoration_data.scroll_position;let anchor =- Anchor::in_buffer(*excerpt_id, snapshot.anchor_before(Point::new(top_row, 0)));+ Anchor::in_buffer(excerpt_id, snapshot.anchor_before(Point::new(top_row, 0)));editor.set_scroll_anchor(ScrollAnchor { anchor, offset }, window, cx);}diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rsindex 274e6771e49..211474904bb 100644--- a/crates/multi_buffer/src/multi_buffer.rs+++ b/crates/multi_buffer/src/multi_buffer.rs@@ -4688,12 +4688,12 @@ impl MultiBufferSnapshot {self.singleton}- pub fn as_singleton(&self) -> Option<(&ExcerptId, BufferId, &BufferSnapshot)> {+ pub fn as_singleton(&self) -> Option<(ExcerptId, BufferId, &BufferSnapshot)> {if self.singleton {self.excerpts.iter().next()- .map(|e| (&e.id, e.buffer_id, &*e.buffer))+ .map(|e| (e.id, e.buffer_id, &*e.buffer))} else {None}@@ -5822,7 +5822,7 @@ impl MultiBufferSnapshot {pub fn as_singleton_anchor(&self, text_anchor: text::Anchor) -> Option<Anchor> {let (excerpt, buffer, _) = self.as_singleton()?;if text_anchor.buffer_id.is_none_or(|id| id == buffer) {- Some(Anchor::in_buffer(*excerpt, text_anchor))+ Some(Anchor::in_buffer(excerpt, text_anchor))} else {None}@@ -6750,17 +6750,17 @@ impl MultiBufferSnapshot {.flat_map(|item| {Some(OutlineItem {depth: item.depth,- range: self.anchor_range_in_excerpt(*excerpt_id, item.range)?,+ range: self.anchor_range_in_excerpt(excerpt_id, item.range)?,source_range_for_text: self- .anchor_range_in_excerpt(*excerpt_id, item.source_range_for_text)?,+ .anchor_range_in_excerpt(excerpt_id, item.source_range_for_text)?,text: item.text,highlight_ranges: item.highlight_ranges,name_ranges: item.name_ranges,body_range: item.body_range.and_then(|body_range| {- self.anchor_range_in_excerpt(*excerpt_id, body_range)+ self.anchor_range_in_excerpt(excerpt_id, body_range)}),annotation_range: item.annotation_range.and_then(|annotation_range| {- self.anchor_range_in_excerpt(*excerpt_id, annotation_range)+ self.anchor_range_in_excerpt(excerpt_id, annotation_range)}),})})diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rsindex bfe62863fbc..454f6f0b578 100644--- a/crates/outline/src/outline.rs+++ b/crates/outline/src/outline.rs@@ -82,7 +82,6 @@ fn outline_for_editor() -> Option<Task<Vec<OutlineItem<Anchor>>>> {let multibuffer = editor.read(cx).buffer().read(cx).snapshot(cx);let (excerpt_id, _, buffer_snapshot) = multibuffer.as_singleton()?;- let excerpt_id = *excerpt_id;let buffer_id = buffer_snapshot.remote_id();let task = editor.update(cx, |editor, cx| editor.buffer_outline_items(buffer_id, cx));