Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix some overcomputation in the project diff (#57859)
Cole Miller8612c626d9df
diff --git a/crates/git_ui/src/conflict_view.rs b/crates/git_ui/src/conflict_view.rsindex 70e10168adf..5be215a166c 100644--- a/crates/git_ui/src/conflict_view.rs+++ b/crates/git_ui/src/conflict_view.rs@@ -2,7 +2,7 @@ use agent_settings::AgentSettings;use collections::{HashMap, HashSet};use editor::{ConflictsOurs, ConflictsOursMarker, ConflictsOuter, ConflictsTheirs, ConflictsTheirsMarker,- Editor, EditorEvent, MultiBuffer, RowHighlightOptions,+ Editor, MultiBuffer, RowHighlightOptions,display_map::{BlockContext, BlockPlacement, BlockProperties, BlockStyle, CustomBlockId},};use gpui::{@@ -11,13 +11,13 @@ use gpui::{};use language::{Anchor, Buffer, BufferId};use project::{- ConflictRegion, ConflictSet, ConflictSetUpdate, Project, ProjectItem as _,+ ConflictRegion, ConflictSet, ConflictSetUpdate, Project,git_store::{GitStore, GitStoreEvent, RepositoryEvent},};use settings::Settings;use std::{ops::Range, sync::Arc};use ui::{ButtonLike, Divider, Tooltip, prelude::*};-use util::{ResultExt as _, debug_panic, maybe};+use util::{debug_panic, maybe};use workspace::{HideStatusItem, StatusItemView, Workspace, item::ItemHandle};use zed_actions::agent::{ConflictContent, ResolveConflictedFilesWithAgent, ResolveConflictsWithAgent,@@ -27,14 +27,6 @@ pub(crate) struct ConflictAddon {buffers: HashMap<BufferId, BufferConflicts>,}-impl ConflictAddon {- pub(crate) fn conflict_set(&self, buffer_id: BufferId) -> Option<Entity<ConflictSet>> {- self.buffers- .get(&buffer_id)- .map(|entry| entry.conflict_set.clone())- }-}-struct BufferConflicts {block_ids: Vec<(Range<Anchor>, CustomBlockId)>,conflict_set: Entity<ConflictSet>,@@ -52,10 +44,9 @@ impl editor::Addon for ConflictAddon {}pub fn register_editor(editor: &mut Editor, buffer: Entity<MultiBuffer>, cx: &mut Context<Editor>) {- // Only show conflict UI for singletons and in the project diff.+ let is_singleton = editor.buffer().read(cx).is_singleton();if !editor.mode().is_full()- || (!editor.buffer().read(cx).is_singleton()- && !editor.buffer().read(cx).all_diff_hunks_expanded())+ || (!is_singleton && !editor.buffer().read(cx).all_diff_hunks_expanded())|| editor.read_only(cx){return;@@ -65,42 +56,75 @@ pub fn register_editor(editor: &mut Editor, buffer: Entity<MultiBuffer>, cx: &mubuffers: Default::default(),});- let buffers = buffer.read(cx).all_buffers();- for buffer in buffers {- buffer_ranges_updated(editor, buffer, cx);+ if is_singleton {+ let buffers = buffer.read(cx).all_buffers();+ for buffer in buffers {+ open_conflict_set_for_buffer(editor, buffer, cx);+ }}+}- cx.subscribe(&cx.entity(), |editor, _, event, cx| match event {- EditorEvent::BufferRangesUpdated { buffer, .. } => {- buffer_ranges_updated(editor, buffer.clone(), cx)- }- EditorEvent::BuffersRemoved { removed_buffer_ids } => {- buffers_removed(editor, removed_buffer_ids, cx)+fn open_conflict_set_for_buffer(+ _editor: &mut Editor,+ buffer: Entity<Buffer>,+ cx: &mut Context<Editor>,+) {+ let buffer = buffer.downgrade();++ cx.spawn(async move |editor, cx| {+ let buffer_id = buffer.read_with(cx, |buffer, _| buffer.remote_id())?;+ if let Some(conflict_set) = editor.read_with(cx, |editor, _| {+ editor+ .addon::<ConflictAddon>()+ .and_then(|addon| addon.buffers.get(&buffer_id))+ .map(|buffer_conflicts| buffer_conflicts.conflict_set.clone())+ })? {+ editor.update(cx, |editor, cx| {+ buffer_ranges_updated(editor, conflict_set, cx);+ })?;+ return anyhow::Ok(());}- _ => {}++ let Some(project) = editor.read_with(cx, |editor, _| editor.project().cloned())? else {+ return anyhow::Ok(());+ };+ let git_store = project.read_with(cx, |project, _| project.git_store().clone());+ let Some(buffer) = buffer.upgrade() else {+ return Ok(());+ };+ let conflict_set = git_store+ .update(cx, |git_store, cx| {+ git_store.open_conflict_set(buffer.clone(), cx)+ })+ .await;+ editor.update(cx, |editor, cx| {+ buffer_ranges_updated(editor, conflict_set, cx);+ })?;+ Ok(())}).detach();}-fn buffer_ranges_updated(editor: &mut Editor, buffer: Entity<Buffer>, cx: &mut Context<Editor>) {- let Some(project) = editor.project() else {+pub(crate) fn buffer_ranges_updated(+ editor: &mut Editor,+ conflict_set: Entity<ConflictSet>,+ cx: &mut Context<Editor>,+) {+ let buffer_id = conflict_set.read(cx).snapshot.buffer_id;+ if editor.buffer().read(cx).buffer(buffer_id).is_none() {return;- };- let git_store = project.read(cx).git_store().clone();+ }let buffer_conflicts = editor.addon_mut::<ConflictAddon>().unwrap().buffers- .entry(buffer.read(cx).remote_id())+ .entry(buffer_id).or_insert_with(|| {- let conflict_set = git_store.update(cx, |git_store, cx| {- git_store.open_conflict_set(buffer.clone(), cx)- });let subscription = cx.subscribe(&conflict_set, conflicts_updated);BufferConflicts {block_ids: Vec::new(),- conflict_set,+ conflict_set: conflict_set.clone(),_subscription: subscription,}});@@ -120,7 +144,11 @@ fn buffer_ranges_updated(editor: &mut Editor, buffer: Entity<Buffer>, cx: &mut C);}-fn buffers_removed(editor: &mut Editor, removed_buffer_ids: &[BufferId], cx: &mut Context<Editor>) {+pub(crate) fn buffers_removed(+ editor: &mut Editor,+ removed_buffer_ids: &[BufferId],+ cx: &mut Context<Editor>,+) {let mut removed_block_ids = HashSet::default();editor.addon_mut::<ConflictAddon>()@@ -447,10 +475,8 @@ pub(crate) fn resolve_conflict(cx: &mut App,) -> Task<()> {window.spawn(cx, async move |cx| {- let Some((workspace, project, multibuffer, buffer)) = editor+ editor.update(cx, |editor, cx| {- let workspace = editor.workspace()?;- let project = editor.project()?.clone();let multibuffer = editor.buffer().clone();let buffer_id = resolved_conflict.ours.end.buffer_id;let buffer = multibuffer.read(cx).buffer(buffer_id)?;@@ -481,34 +507,9 @@ pub(crate) fn resolve_conflict(editor.remove_highlighted_rows::<ConflictsOursMarker>(vec![range.clone()], cx);editor.remove_highlighted_rows::<ConflictsTheirsMarker>(vec![range], cx);editor.remove_blocks(HashSet::from_iter([block_id]), None, cx);- Some((workspace, project, multibuffer, buffer))+ Some(())})- .ok()- .flatten()- else {- return;- };- let save = project.update(cx, |project, cx| {- if multibuffer.read(cx).all_diff_hunks_expanded() {- project.save_buffer(buffer.clone(), cx)- } else {- Task::ready(Ok(()))- }- });- if save.await.log_err().is_none() {- let open_path = maybe!({- let path = buffer.read_with(cx, |buffer, cx| buffer.project_path(cx))?;- workspace- .update_in(cx, |workspace, window, cx| {- workspace.open_path_preview(path, None, false, false, false, window, cx)- })- .ok()- });-- if let Some(open_path) = open_path {- open_path.await.log_err();- }- }+ .ok();})}diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rsindex 89bb54d0a5e..5627c40a4ca 100644--- a/crates/git_ui/src/project_diff.rs+++ b/crates/git_ui/src/project_diff.rs@@ -1,6 +1,5 @@use crate::{- branch_picker,- conflict_view::ConflictAddon,+ branch_picker, conflict_view,git_panel::{GitPanel, GitPanelAddon, GitStatusEntry},git_panel_settings::GitPanelSettings,};@@ -28,7 +27,7 @@ use gpui::{use language::{Anchor, Buffer, BufferId, Capability, OffsetRangeExt};use multi_buffer::{MultiBuffer, PathKey};use project::{- Project, ProjectPath,+ ConflictSet, Project, ProjectPath,git_store::{Repository,branch_diff::{self, BranchDiffEvent, DiffBase},@@ -36,6 +35,7 @@ use project::{};use settings::{Settings, SettingsStore};use std::any::{Any, TypeId};+use std::collections::BTreeMap;use std::sync::Arc;use theme::ActiveTheme;use ui::{@@ -71,12 +71,19 @@ actions!(]);+struct BufferSubscriptions {+ _diff: Entity<BufferDiff>,+ _diff_subscription: Subscription,+ _conflict_set: Entity<ConflictSet>,+ _conflict_set_subscription: Subscription,+}+pub struct ProjectDiff {project: Entity<Project>,multibuffer: Entity<MultiBuffer>,branch_diff: Entity<branch_diff::BranchDiff>,editor: Entity<SplittableEditor>,- buffer_diff_subscriptions: HashMap<Arc<RelPath>, (Entity<BufferDiff>, Subscription)>,+ buffer_subscriptions: HashMap<Arc<RelPath>, BufferSubscriptions>,workspace: WeakEntity<Workspace>,focus_handle: FocusHandle,pending_scroll: Option<PathKey>,@@ -85,13 +92,6 @@ pub struct ProjectDiff {_subscription: Subscription,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub enum RefreshReason {- DiffChanged,- StatusesChanged,- EditorSaved,-}-const CONFLICT_SORT_PREFIX: u64 = 1;const TRACKED_SORT_PREFIX: u64 = 2;const NEW_SORT_PREFIX: u64 = 3;@@ -562,14 +562,14 @@ impl ProjectDiff {BranchDiffEvent::FileListChanged => {this._task = window.spawn(cx, {let this = cx.weak_entity();- async |cx| Self::refresh(this, RefreshReason::StatusesChanged, cx).await+ async |cx| Self::refresh(this, cx).await})}BranchDiffEvent::DiffBaseChanged => {this.pending_scroll.take();this._task = window.spawn(cx, {let this = cx.weak_entity();- async |cx| Self::refresh(this, RefreshReason::StatusesChanged, cx).await+ async |cx| Self::refresh(this, cx).await})}},@@ -588,7 +588,7 @@ impl ProjectDiff {this._task = {window.spawn(cx, {let this = cx.weak_entity();- async |cx| Self::refresh(this, RefreshReason::StatusesChanged, cx).await+ async |cx| Self::refresh(this, cx).await})}}@@ -599,7 +599,7 @@ impl ProjectDiff {let task = window.spawn(cx, {let this = cx.weak_entity();- async |cx| Self::refresh(this, RefreshReason::StatusesChanged, cx).await+ async |cx| Self::refresh(this, cx).await});Self {@@ -609,7 +609,7 @@ impl ProjectDiff {focus_handle,editor,multibuffer,- buffer_diff_subscriptions: Default::default(),+ buffer_subscriptions: Default::default(),pending_scroll: None,review_comment_count: 0,_task: task,@@ -795,9 +795,8 @@ impl ProjectDiff {.ok();}EditorEvent::Saved => {- self._task = cx.spawn_in(window, async move |this, cx| {- Self::refresh(this, RefreshReason::EditorSaved, cx).await- });+ self._task =+ cx.spawn_in(window, async move |this, cx| Self::refresh(this, cx).await);}_ => {}}@@ -815,26 +814,58 @@ impl ProjectDiff {file_status: FileStatus,buffer: Entity<Buffer>,diff: Entity<BufferDiff>,+ conflict_set: Entity<ConflictSet>,window: &mut Window,cx: &mut Context<Self>,) -> Option<BufferId> {- let subscription = cx.subscribe_in(&diff, window, move |this, _, _, window, cx| {- this._task = window.spawn(cx, {- let this = cx.weak_entity();- async |cx| Self::refresh(this, RefreshReason::DiffChanged, cx).await- })+ let diff_subscription = cx.subscribe_in(&diff, window, {+ let path_key = path_key.clone();+ let buffer = buffer.clone();+ let diff = diff.clone();+ let conflict_set = conflict_set.clone();+ move |this, _, event, window, cx| match event {+ buffer_diff::BufferDiffEvent::DiffChanged(_) => {+ this.buffer_ranges_changed(+ path_key.clone(),+ file_status,+ buffer.clone(),+ diff.clone(),+ conflict_set.clone(),+ window,+ cx,+ );+ }+ buffer_diff::BufferDiffEvent::BaseTextChanged+ | buffer_diff::BufferDiffEvent::LanguageChanged+ | buffer_diff::BufferDiffEvent::HunksStagedOrUnstaged(_) => {}+ }});- self.buffer_diff_subscriptions- .insert(path_key.path.clone(), (diff.clone(), subscription));-- // TODO(split-diff) we shouldn't have a conflict addon when split- let conflict_addon = self- .editor- .read(cx)- .rhs_editor()- .read(cx)- .addon::<ConflictAddon>()- .expect("project diff editor should have a conflict addon");+ let conflict_set_subscription = cx.subscribe_in(&conflict_set, window, {+ let path_key = path_key.clone();+ let buffer = buffer.clone();+ let diff = diff.clone();+ let conflict_set = conflict_set.clone();+ move |this, _, _, window, cx| {+ this.buffer_ranges_changed(+ path_key.clone(),+ file_status,+ buffer.clone(),+ diff.clone(),+ conflict_set.clone(),+ window,+ cx,+ )+ }+ });+ self.buffer_subscriptions.insert(+ path_key.path.clone(),+ BufferSubscriptions {+ _diff: diff.clone(),+ _diff_subscription: diff_subscription,+ _conflict_set: conflict_set.clone(),+ _conflict_set_subscription: conflict_set_subscription,+ },+ );let snapshot = buffer.read(cx).snapshot();let diff_snapshot = diff.read(cx).snapshot(cx);@@ -846,11 +877,9 @@ impl ProjectDiff {&snapshot,).map(|diff_hunk| diff_hunk.buffer_range.to_point(&snapshot));- let conflicts = conflict_addon- .conflict_set(snapshot.remote_id())- .map(|conflict_set| conflict_set.read(cx).snapshot().conflicts)- .unwrap_or_default();+ let conflicts = conflict_set.read(cx).snapshot();let mut conflicts = conflicts+ .conflicts.iter().map(|conflict| conflict.range.to_point(&snapshot)).peekable();@@ -874,6 +903,9 @@ impl ProjectDiff {diff,cx,);+ editor.rhs_editor().update(cx, |editor, cx| {+ conflict_view::buffer_ranges_updated(editor, conflict_set, cx);+ });(was_empty, is_newly_added)});@@ -921,19 +953,38 @@ impl ProjectDiff {needs_fold}+ fn buffer_ranges_changed(+ &mut self,+ path_key: PathKey,+ file_status: FileStatus,+ buffer: Entity<Buffer>,+ diff: Entity<BufferDiff>,+ conflict_set: Entity<ConflictSet>,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ if buffer.read(cx).is_dirty() {+ return;+ }+ self.register_buffer(+ path_key,+ file_status,+ buffer,+ diff,+ conflict_set,+ window,+ cx,+ );+ }+#[instrument(skip(this, cx))]- pub async fn refresh(- this: WeakEntity<Self>,- reason: RefreshReason,- cx: &mut AsyncWindowContext,- ) -> Result<()> {- let mut path_keys = Vec::new();- let buffers_to_load = this.update(cx, |this, cx| {+ pub async fn refresh(this: WeakEntity<Self>, cx: &mut AsyncWindowContext) -> Result<()> {+ let entries = this.update(cx, |this, cx| {let (repo, buffers_to_load) = this.branch_diff.update(cx, |branch_diff, cx| {let load_buffers = branch_diff.load_buffers(cx);(branch_diff.repo().cloned(), load_buffers)});- let mut previous_buffers = this+ let mut previous_paths = this.multibuffer.read(cx).snapshot(cx)@@ -941,73 +992,56 @@ impl ProjectDiff {.map(|(buffer_snapshot, path_key)| (path_key.clone(), buffer_snapshot.remote_id())).collect::<HashMap<_, _>>();+ let mut entries = BTreeMap::new();if let Some(repo) = repo {let repo = repo.read(cx);- path_keys = Vec::with_capacity(buffers_to_load.len());- for entry in buffers_to_load.iter() {- let sort_prefix = sort_prefix(&repo, &entry.repo_path, entry.file_status, cx);- let path_key =- PathKey::with_sort_prefix(sort_prefix, entry.repo_path.as_ref().clone());- previous_buffers.remove(&path_key);- path_keys.push(path_key)+ for diff_buffer in buffers_to_load {+ let sort_prefix =+ sort_prefix(&repo, &diff_buffer.repo_path, diff_buffer.file_status, cx);+ let path_key = PathKey::with_sort_prefix(+ sort_prefix,+ diff_buffer.repo_path.as_ref().clone(),+ );+ previous_paths.remove(&path_key);+ entries.insert(path_key, diff_buffer);}}this.editor.update(cx, |editor, cx| {- for (path, buffer_id) in previous_buffers {- if let Some(buffer) = this.multibuffer.read(cx).buffer(buffer_id) {- let skip = match reason {- RefreshReason::DiffChanged | RefreshReason::EditorSaved => {- buffer.read(cx).is_dirty()- }- RefreshReason::StatusesChanged => false,- };- if skip {- continue;- }- }-- this.buffer_diff_subscriptions.remove(&path.path);+ for (path, buffer_id) in previous_paths {+ this.buffer_subscriptions.remove(&path.path);+ editor.rhs_editor().update(cx, |editor, cx| {+ conflict_view::buffers_removed(editor, &[buffer_id], cx);+ });let _span = ztracing::info_span!("remove_excerpts_for_path");_span.enter();editor.remove_excerpts_for_path(path, cx);}});- buffers_to_load++ entries})?;let mut buffers_to_fold = Vec::new();- for (entry, path_key) in buffers_to_load.into_iter().zip(path_keys) {- if let Some((buffer, diff)) = entry.load.await.log_err() {+ for (path_key, entry) in entries {+ if let Some((buffer, diff, conflict_set)) = entry.load.await.log_err() {// We might be lagging behind enough that all future entry.load futures are no longer pending.// If that is the case, this task will never yield, starving the foreground thread of execution time.yield_now().await;cx.update(|window, cx| {this.update(cx, |this, cx| {- let multibuffer = this.multibuffer.read(cx);- let skip = multibuffer.buffer(buffer.read(cx).remote_id()).is_some()- && multibuffer- .diff_for(buffer.read(cx).remote_id())- .is_some_and(|prev_diff| prev_diff.entity_id() == diff.entity_id())- && match reason {- RefreshReason::DiffChanged | RefreshReason::EditorSaved => {- buffer.read(cx).is_dirty()- }- RefreshReason::StatusesChanged => false,- };- if !skip {- if let Some(buffer_id) = this.register_buffer(- path_key,- entry.file_status,- buffer,- diff,- window,- cx,- ) {- buffers_to_fold.push(buffer_id);- }+ if let Some(buffer_id) = this.register_buffer(+ path_key,+ entry.file_status,+ buffer,+ diff,+ conflict_set,+ window,+ cx,+ ) {+ buffers_to_fold.push(buffer_id);}}).ok();@@ -2242,10 +2276,7 @@ mod tests {);}- use crate::{- conflict_view::resolve_conflict,- project_diff::{self, ProjectDiff},- };+ use crate::project_diff::{self, ProjectDiff};#[gpui::test]async fn test_go_to_prev_hunk_multibuffer(cx: &mut TestAppContext) {@@ -2294,14 +2325,13 @@ mod tests {let mut cx = EditorTestContext::for_editor_in(editor, cx).await;- cx.assert_excerpts_with_selections(indoc!(+ cx.set_selections_state(indoc!("- [EXCERPT]beforereally changed- [EXCERPT]- [FOLDED]- [EXCERPT]++ deleted+ˇcreated"));@@ -2419,89 +2449,6 @@ mod tests {cx.assert_excerpts_with_selections(&format!("[EXCERPT]\nˇ{git_contents}"));}- #[gpui::test]- async fn test_saving_resolved_conflicts(cx: &mut TestAppContext) {- init_test(cx);-- let fs = FakeFs::new(cx.executor());- fs.insert_tree(- path!("/project"),- json!({- ".git": {},- "foo": "<<<<<<< x\nours\n=======\ntheirs\n>>>>>>> y\n",- }),- )- .await;- fs.set_status_for_repo(- Path::new(path!("/project/.git")),- &[(- "foo",- UnmergedStatus {- first_head: UnmergedStatusCode::Updated,- second_head: UnmergedStatusCode::Updated,- }- .into(),- )],- );- let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await;- let (multi_workspace, cx) =- cx.add_window_view(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));- let workspace = multi_workspace.read_with(cx, |mw, _| mw.workspace().clone());- let diff = cx.new_window_entity(|window, cx| {- ProjectDiff::new(project.clone(), workspace, window, cx)- });- cx.run_until_parked();-- cx.update(|window, cx| {- let editor = diff.read(cx).editor.read(cx).rhs_editor().clone();- let excerpts = editor- .read(cx)- .buffer()- .read(cx)- .snapshot(cx)- .excerpts()- .collect::<Vec<_>>();- assert_eq!(excerpts.len(), 1);- let buffer = editor- .read(cx)- .buffer()- .read(cx)- .all_buffers()- .into_iter()- .next()- .unwrap();- let buffer_id = buffer.read(cx).remote_id();- let conflict_set = diff- .read(cx)- .editor- .read(cx)- .rhs_editor()- .read(cx)- .addon::<ConflictAddon>()- .unwrap()- .conflict_set(buffer_id)- .unwrap();- assert!(conflict_set.read(cx).has_conflict);- let snapshot = conflict_set.read(cx).snapshot();- assert_eq!(snapshot.conflicts.len(), 1);-- let ours_range = snapshot.conflicts[0].ours.clone();-- resolve_conflict(- editor.downgrade(),- snapshot.conflicts[0].clone(),- vec![ours_range],- window,- cx,- )- })- .await;-- let contents = fs.read_file_sync(path!("/project/foo")).unwrap();- let contents = String::from_utf8(contents).unwrap();- assert_eq!(contents, "ours\n");- }-#[gpui::test(iterations = 50)]async fn test_split_diff_conflict_path_transition_with_dirty_buffer_invalid_anchor_panics(cx: &mut TestAppContext,diff --git a/crates/multi_buffer/src/path_key.rs b/crates/multi_buffer/src/path_key.rsindex 8545827ef52..53117a05013 100644--- a/crates/multi_buffer/src/path_key.rs+++ b/crates/multi_buffer/src/path_key.rs@@ -599,19 +599,18 @@ impl MultiBuffer {);if !edits.is_empty() {self.subscriptions.publish(edits);+ cx.emit(Event::Edited {+ edited_buffer: None,+ source: BufferEditSource::User,+ });+ cx.emit(Event::BufferRangesUpdated {+ buffer,+ path_key: path_key.clone(),+ ranges: new_ranges,+ });+ cx.notify();}- cx.emit(Event::Edited {- edited_buffer: None,- source: BufferEditSource::User,- });- cx.emit(Event::BufferRangesUpdated {- buffer,- path_key: path_key.clone(),- ranges: new_ranges,- });- cx.notify();-added_new_excerpt}diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rsindex 64353d0fc35..9990c5cb1e0 100644--- a/crates/project/src/git_store.rs+++ b/crates/project/src/git_store.rs@@ -1174,8 +1174,7 @@ impl GitStore {&mut self,buffer: Entity<Buffer>,cx: &mut Context<Self>,- ) -> Entity<ConflictSet> {- log::debug!("open conflict set");+ ) -> Task<Entity<ConflictSet>> {let buffer_id = buffer.read(cx).remote_id();if let Some(git_state) = self.diffs.get(&buffer_id)@@ -1188,11 +1187,14 @@ impl GitStore {let conflict_set = conflict_set;let buffer_snapshot = buffer.read(cx).text_snapshot();- git_state.update(cx, |state, cx| {- let _ = state.reparse_conflict_markers(buffer_snapshot, cx);+ let rx = git_state.update(cx, |state, cx| {+ state.reparse_conflict_markers(buffer_snapshot, cx)});- return conflict_set;+ return cx.spawn(async move |_, _| {+ rx.await.ok();+ conflict_set+ });}let is_unmerged = self@@ -1210,13 +1212,16 @@ impl GitStore {cx.emit(GitStoreEvent::ConflictsUpdated);}));- buffer_git_state.update(cx, |state, cx| {+ let rx = buffer_git_state.update(cx, |state, cx| {state.conflict_set = Some(conflict_set.downgrade());let buffer_snapshot = buffer.read(cx).text_snapshot();- let _ = state.reparse_conflict_markers(buffer_snapshot, cx);+ state.reparse_conflict_markers(buffer_snapshot, cx)});- conflict_set+ cx.spawn(async move |_, _| {+ rx.await.ok();+ conflict_set+ })}pub fn project_path_git_status(@@ -3809,39 +3814,35 @@ impl BufferGitState {return rx;};- let old_snapshot = conflict_set.read_with(cx, |conflict_set, _| {- if conflict_set.has_conflict {- Some(conflict_set.snapshot())- } else {- None- }- });+ let has_conflict = conflict_set.read_with(cx, |conflict_set, _| conflict_set.has_conflict);+ if !has_conflict {+ return rx;+ }- if let Some(old_snapshot) = old_snapshot {- self.conflict_updated_futures.push(tx);- self.reparse_conflict_markers_task = Some(cx.spawn(async move |this, cx| {- let (snapshot, changed_range) = cx- .background_spawn(async move {- let new_snapshot = ConflictSet::parse(&buffer);- let changed_range = old_snapshot.compare(&new_snapshot, &buffer);- (new_snapshot, changed_range)- })- .await;- this.update(cx, |this, cx| {- if let Some(conflict_set) = &this.conflict_set {- conflict_set- .update(cx, |conflict_set, cx| {- conflict_set.set_snapshot(snapshot, changed_range, cx);- })- .ok();- }- let futures = std::mem::take(&mut this.conflict_updated_futures);- for tx in futures {- tx.send(()).ok();- }+ let old_snapshot = conflict_set.read_with(cx, |conflict_set, _| conflict_set.snapshot());+ self.conflict_updated_futures.push(tx);+ self.reparse_conflict_markers_task = Some(cx.spawn(async move |this, cx| {+ let (snapshot, changed_range) = cx+ .background_spawn(async move {+ let new_snapshot = ConflictSet::parse(&buffer);+ let changed_range = old_snapshot.compare(&new_snapshot, &buffer);+ (new_snapshot, changed_range)})- }))- }+ .await;+ this.update(cx, |this, cx| {+ if let Some(conflict_set) = &this.conflict_set {+ conflict_set+ .update(cx, |conflict_set, cx| {+ conflict_set.set_snapshot(snapshot, changed_range, cx);+ })+ .ok();+ }+ let futures = std::mem::take(&mut this.conflict_updated_futures);+ for tx in futures {+ tx.send(()).ok();+ }+ })+ }));rx}diff --git a/crates/project/src/git_store/branch_diff.rs b/crates/project/src/git_store/branch_diff.rsindex 60c93abd0a1..67aa198945d 100644--- a/crates/project/src/git_store/branch_diff.rs+++ b/crates/project/src/git_store/branch_diff.rs@@ -17,7 +17,7 @@ use util::ResultExt;use ztracing::instrument;use crate::{- Project,+ ConflictSet, Project,git_store::{GitStoreEvent, Repository, RepositoryEvent},};@@ -79,7 +79,6 @@ impl BranchDiff {.repo.as_ref().is_some_and(|r| r.read(cx).snapshot().id == *event_repo_id),- GitStoreEvent::ConflictsUpdated => this.repo.is_some(),_ => false,};@@ -405,7 +404,7 @@ impl BranchDiff {project_path: crate::ProjectPath,repo: Entity<Repository>,cx: &Context<'_, Project>,- ) -> Task<Result<(Entity<Buffer>, Entity<BufferDiff>)>> {+ ) -> Task<Result<(Entity<Buffer>, Entity<BufferDiff>, Entity<ConflictSet>)>> {let task = cx.spawn(async move |project, cx| {let buffer = project.update(cx, |project, cx| project.open_buffer(project_path, cx))?@@ -431,7 +430,14 @@ impl BranchDiff {})?.await?};- Ok((buffer, changes))+ let conflict_set = project+ .update(cx, |project, cx| {+ project.git_store().update(cx, |git_store, cx| {+ git_store.open_conflict_set(buffer.clone(), cx)+ })+ })?+ .await;+ Ok((buffer, changes, conflict_set))});task}@@ -459,5 +465,5 @@ fn diff_status_to_file_status(branch_diff: &git::status::TreeDiffStatus) -> Filepub struct DiffBuffer {pub repo_path: RepoPath,pub file_status: FileStatus,- pub load: Task<Result<(Entity<Buffer>, Entity<BufferDiff>)>>,+ pub load: Task<Result<(Entity<Buffer>, Entity<BufferDiff>, Entity<ConflictSet>)>>,}diff --git a/crates/project/tests/integration/git_store.rs b/crates/project/tests/integration/git_store.rsindex 05d3843f018..0c58c7adf23 100644--- a/crates/project/tests/integration/git_store.rs+++ b/crates/project/tests/integration/git_store.rs@@ -299,9 +299,11 @@ mod conflict_set_tests {)});let buffer = buffer.await.unwrap();- let conflict_set = git_store.update(cx, |git_store, cx| {- git_store.open_conflict_set(buffer.clone(), cx)- });+ let conflict_set = git_store+ .update(cx, |git_store, cx| {+ git_store.open_conflict_set(buffer.clone(), cx)+ })+ .await;let (events_tx, events_rx) = mpsc::channel::<ConflictSetUpdate>();let _conflict_set_subscription = cx.update(|cx| {cx.subscribe(&conflict_set, move |_, event, _| {@@ -417,9 +419,11 @@ mod conflict_set_tests {let buffer = buffer.await.unwrap();// Open the conflict set for a file that currently has conflicts.- let conflict_set = git_store.update(cx, |git_store, cx| {- git_store.open_conflict_set(buffer.clone(), cx)- });+ let conflict_set = git_store+ .update(cx, |git_store, cx| {+ git_store.open_conflict_set(buffer.clone(), cx)+ })+ .await;cx.run_until_parked();conflict_set.update(cx, |conflict_set, cx| {@@ -518,9 +522,11 @@ mod conflict_set_tests {)});let buffer = buffer.await.unwrap();- let conflict_set = git_store.update(cx, |git_store, cx| {- git_store.open_conflict_set(buffer.clone(), cx)- });+ let conflict_set = git_store+ .update(cx, |git_store, cx| {+ git_store.open_conflict_set(buffer.clone(), cx)+ })+ .await;let (events_tx, events_rx) = mpsc::channel::<ConflictSetUpdate>();let _conflict_set_subscription = cx.update(|cx| {