From 8244a5c6edcbed0a30a2f65af28003a838373528 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 18 Feb 2026 10:32:36 +0100 Subject: [PATCH] multi_buffer: Remove unnecessary reference in `as_singleton` return type (#49447) Allows cleaning up `open_tool_call_location` slightly Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/agent_ui/src/acp/message_editor.rs | 4 ++-- .../src/acp/thread_view/active_thread.rs | 17 +++++++++++------ crates/agent_ui/src/mention_set.rs | 4 ++-- crates/agent_ui/src/text_thread_editor.rs | 16 +++++++--------- crates/editor/src/editor.rs | 3 +-- crates/editor/src/items.rs | 2 +- crates/multi_buffer/src/multi_buffer.rs | 14 +++++++------- crates/outline/src/outline.rs | 1 - 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 4a04446b6a80ca2f8fbf41586cb2b70d66d6b4e8..702be48ae4aab28f23531bb92392844ca9509498 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.rs index b7655c51fad0ba5821dcb154cd166dc93b8f959c..839b58b07e92b7878a6ec5207840cfeb6ccb0b1f 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.rs index 707e7b45343363b9db440998190e319df1da5b80..7d752eadae558cad5ae36b0d7924e5e96f3e54ff 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.rs index 2d4ada96e9fa6107b9f77c55b03948e4a00f1013..9e8f7e2a439f6e743618b8669bb35d9a170ac8ea 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 { 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.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_thread diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a223949c59dd58cc11aab9e90caf95b985c79d8e..e723419283c1103c9c773150837fdcc9b2835b51 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.rs index 3de25131508cc39edc6cefc500c05fbcc9bb33fb..b20d73a2895d1acbe6df00ed87452b9027992dc3 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.rs index 274e6771e49a7677b804437c70fae384fbd03ce9..211474904bb022f08292e9080b356ddc88e2eca1 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 { 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.rs index bfe62863fbc2a0d5fb7d3974c241f0ad5d934ec1..454f6f0b578ce25785f0a356251c8af64776772f 100644 --- a/crates/outline/src/outline.rs +++ b/crates/outline/src/outline.rs @@ -82,7 +82,6 @@ fn outline_for_editor( ) -> Option>>> { 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));