git: Enable the split diff for everyone (#48912)

Cole Miller created

Release Notes:

- Added support for viewing diffs in split ("side by side") mode

Change summary

Cargo.lock                            |  1 -
assets/settings/default.json          |  4 ++--
crates/editor/src/editor.rs           |  2 +-
crates/editor/src/split.rs            | 15 +--------------
crates/git_ui/src/project_diff.rs     |  7 ++++++-
crates/search/Cargo.toml              |  1 -
crates/search/src/buffer_search.rs    |  7 ++-----
crates/settings_content/src/editor.rs |  4 ++--
crates/settings_ui/src/page_data.rs   | 15 ++++++++++++++-
crates/settings_ui/src/settings_ui.rs |  1 +
10 files changed, 29 insertions(+), 28 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -14867,7 +14867,6 @@ dependencies = [
  "client",
  "collections",
  "editor",
- "feature_flags",
  "fs",
  "futures 0.3.31",
  "gpui",

assets/settings/default.json 🔗

@@ -293,8 +293,8 @@
   "completion_detail_alignment": "left",
   // How to display diffs in the editor.
   //
-  // Default: unified
-  "diff_view_style": "unified",
+  // Default: split
+  "diff_view_style": "split",
   // Show method signatures in the editor, when inside parentheses.
   "auto_signature_help": false,
   // Whether to show the signature help after completion or a bracket pair inserted.

crates/editor/src/editor.rs 🔗

@@ -78,7 +78,7 @@ pub use multi_buffer::{
     MultiBufferOffset, MultiBufferOffsetUtf16, MultiBufferSnapshot, PathKey, RowInfo, ToOffset,
     ToPoint,
 };
-pub use split::{SplitDiffFeatureFlag, SplittableEditor, ToggleSplitDiff};
+pub use split::{SplittableEditor, ToggleSplitDiff};
 pub use split_editor_view::SplitEditorView;
 pub use text::Bias;
 

crates/editor/src/split.rs 🔗

@@ -5,7 +5,7 @@ use std::{
 
 use buffer_diff::{BufferDiff, BufferDiffSnapshot};
 use collections::HashMap;
-use feature_flags::{FeatureFlag, FeatureFlagAppExt as _};
+
 use gpui::{Action, AppContext as _, Entity, EventEmitter, Focusable, Subscription, WeakEntity};
 use itertools::Itertools;
 use language::{Buffer, Capability};
@@ -362,16 +362,6 @@ fn patch_for_excerpt(
     }
 }
 
-pub struct SplitDiffFeatureFlag;
-
-impl FeatureFlag for SplitDiffFeatureFlag {
-    const NAME: &'static str = "split-diff";
-
-    fn enabled_for_staff() -> bool {
-        true
-    }
-}
-
 #[derive(Clone, Copy, PartialEq, Eq, Action, Default)]
 #[action(namespace = editor)]
 pub struct ToggleSplitDiff;
@@ -513,9 +503,6 @@ impl SplittableEditor {
     }
 
     pub fn split(&mut self, window: &mut Window, cx: &mut Context<Self>) {
-        if !cx.has_flag::<SplitDiffFeatureFlag>() {
-            return;
-        }
         if self.lhs.is_some() {
             return;
         }

crates/git_ui/src/project_diff.rs 🔗

@@ -1843,7 +1843,7 @@ mod tests {
     use gpui::TestAppContext;
     use project::FakeFs;
     use serde_json::json;
-    use settings::SettingsStore;
+    use settings::{DiffViewStyle, SettingsStore};
     use std::path::Path;
     use unindent::Unindent as _;
     use util::{
@@ -1862,6 +1862,11 @@ mod tests {
         cx.update(|cx| {
             let store = SettingsStore::test(cx);
             cx.set_global(store);
+            cx.update_global::<SettingsStore, _>(|store, cx| {
+                store.update_user_settings(cx, |settings| {
+                    settings.editor.diff_view_style = Some(DiffViewStyle::Unified);
+                });
+            });
             theme::init(theme::LoadThemes::JustBase, cx);
             editor::init(cx);
             crate::init(cx);

crates/search/Cargo.toml 🔗

@@ -26,7 +26,6 @@ any_vec.workspace = true
 bitflags.workspace = true
 collections.workspace = true
 editor.workspace = true
-feature_flags.workspace = true
 fs.workspace = true
 futures.workspace = true
 gpui.workspace = true

crates/search/src/buffer_search.rs 🔗

@@ -13,11 +13,9 @@ use crate::{
 use any_vec::AnyVec;
 use collections::HashMap;
 use editor::{
-    DisplayPoint, Editor, EditorSettings, MultiBufferOffset, SplitDiffFeatureFlag,
-    SplittableEditor, ToggleSplitDiff,
+    DisplayPoint, Editor, EditorSettings, MultiBufferOffset, SplittableEditor, ToggleSplitDiff,
     actions::{Backtab, FoldAll, Tab, ToggleFoldAll, UnfoldAll},
 };
-use feature_flags::FeatureFlagAppExt as _;
 use futures::channel::oneshot;
 use gpui::{
     Action, App, ClickEvent, Context, Entity, EventEmitter, Focusable, InteractiveElement as _,
@@ -107,8 +105,7 @@ impl Render for BufferSearchBar {
     fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
         let focus_handle = self.focus_handle(cx);
 
-        let has_splittable_editor =
-            self.splittable_editor.is_some() && cx.has_flag::<SplitDiffFeatureFlag>();
+        let has_splittable_editor = self.splittable_editor.is_some();
         let split_buttons = if has_splittable_editor {
             self.splittable_editor
                 .as_ref()

crates/settings_content/src/editor.rs 🔗

@@ -224,7 +224,7 @@ pub struct EditorSettingsContent {
 
     /// How to display diffs in the editor.
     ///
-    /// Default: unified
+    /// Default: split
     pub diff_view_style: Option<DiffViewStyle>,
 }
 
@@ -806,9 +806,9 @@ pub enum SnippetSortOrder {
 #[serde(rename_all = "snake_case")]
 pub enum DiffViewStyle {
     /// Show diffs in a single unified view.
-    #[default]
     Unified,
     /// Show diffs in a split view.
+    #[default]
     Split,
 }
 

crates/settings_ui/src/page_data.rs 🔗

@@ -1466,7 +1466,7 @@ fn editor_page() -> SettingsPage {
         ]
     }
 
-    fn multibuffer_section() -> [SettingsPageItem; 5] {
+    fn multibuffer_section() -> [SettingsPageItem; 6] {
         [
             SettingsPageItem::SectionHeader("Multibuffer"),
             SettingsPageItem::SettingItem(SettingItem {
@@ -1533,6 +1533,19 @@ fn editor_page() -> SettingsPage {
                 metadata: None,
                 files: USER,
             }),
+            SettingsPageItem::SettingItem(SettingItem {
+                title: "Diff View Style",
+                description: "How to display diffs in the editor.",
+                field: Box::new(SettingField {
+                    json_path: Some("diff_view_style"),
+                    pick: |settings_content| settings_content.editor.diff_view_style.as_ref(),
+                    write: |settings_content, value| {
+                        settings_content.editor.diff_view_style = value;
+                    },
+                }),
+                metadata: None,
+                files: USER,
+            }),
         ]
     }
 

crates/settings_ui/src/settings_ui.rs 🔗

@@ -487,6 +487,7 @@ fn init_renderers(cx: &mut App) {
         .add_basic_renderer::<settings::WordsCompletionMode>(render_dropdown)
         .add_basic_renderer::<settings::LspInsertMode>(render_dropdown)
         .add_basic_renderer::<settings::CompletionDetailAlignment>(render_dropdown)
+        .add_basic_renderer::<settings::DiffViewStyle>(render_dropdown)
         .add_basic_renderer::<settings::AlternateScroll>(render_dropdown)
         .add_basic_renderer::<settings::TerminalBlink>(render_dropdown)
         .add_basic_renderer::<settings::CursorShapeContent>(render_dropdown)