diff --git a/assets/settings/default.json b/assets/settings/default.json index fc1b1906fcb8dc3e144177fb1c511dc0d39d6f22..fddac662a5be681b9e6785ac9a93f4712bcb9bd3 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -76,18 +76,12 @@ "tab_size": 4, // Git gutter behavior configuration. "git": { - "git_gutter": { - // Which files to show the git gutter on. This setting can take - // three values: - // 1. All files, files not tracked in git will be diffed against - // their contents when the file was last opened in Zed: - // "files_included": "all", - // 2. Only show for files tracked in git: - // "files_included": "only_tracked", - // 3. Disable git gutters entirely: - // "files_included": "none", - "files_included": "all" - } + // Control whether the git gutter is shown. May take 2 values: + // 1. Show the gutter + // "git_gutter": "tracked_files" + // 2. Hide the gutter + // "git_gutter": "hide" + "git_gutter": "tracked_files" }, // Settings specific to the terminal "terminal": { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 5d83051567b097092e9cd45804eba50c69fddce6..56887f4b45600a8b5c50feb97bff3f94170b2cfb 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -37,7 +37,7 @@ use gpui::{ use json::json; use language::{Bias, DiagnosticSeverity, OffsetUtf16, Selection}; use project::ProjectPath; -use settings::Settings; +use settings::{GitGutter, Settings}; use smallvec::SmallVec; use std::{ cmp::{self, Ordering}, @@ -607,13 +607,16 @@ impl EditorElement { }; let diff_style = &cx.global::().theme.editor.diff.clone(); - // dbg!("***************"); - // dbg!(&layout.diff_hunks); - // dbg!("***************"); + let show_gutter = matches!( + &cx.global::() + .git_overrides + .git_gutter + .unwrap_or_default(), + GitGutter::TrackedFiles + ); // line is `None` when there's a line wrap for (ix, line) in layout.line_number_layouts.iter().enumerate() { - // dbg!(ix); if let Some(line) = line { let line_origin = bounds.origin() + vec2f( @@ -624,39 +627,39 @@ impl EditorElement { line.paint(line_origin, visible_bounds, gutter_layout.line_height, cx); - //This line starts a buffer line, so let's do the diff calculation - let new_hunk = get_hunk(diff_layout.buffer_line, &layout.diff_hunks); - - // This + the unwraps are annoying, but at least it's legible - let (is_ending, is_starting) = match (diff_layout.last_diff, new_hunk) { - (None, None) => (false, false), - (None, Some(_)) => (false, true), - (Some(_), None) => (true, false), - (Some((old_hunk, _)), Some(new_hunk)) if new_hunk == old_hunk => (false, false), - (Some(_), Some(_)) => (true, true), - }; - - // dbg!(diff_layout.buffer_line, is_starting); - - if is_ending { - let (last_hunk, start_line) = diff_layout.last_diff.take().unwrap(); - // dbg!("ending"); - // dbg!(start_line..ix); - cx.scene.push_quad(diff_quad( - last_hunk.status(), - start_line..ix, - &gutter_layout, - diff_style, - )); - } + if show_gutter { + //This line starts a buffer line, so let's do the diff calculation + let new_hunk = get_hunk(diff_layout.buffer_line, &layout.diff_hunks); + + // This + the unwraps are annoying, but at least it's legible + let (is_ending, is_starting) = match (diff_layout.last_diff, new_hunk) { + (None, None) => (false, false), + (None, Some(_)) => (false, true), + (Some(_), None) => (true, false), + (Some((old_hunk, _)), Some(new_hunk)) if new_hunk == old_hunk => { + (false, false) + } + (Some(_), Some(_)) => (true, true), + }; - if is_starting { - let new_hunk = new_hunk.unwrap(); + if is_ending { + let (last_hunk, start_line) = diff_layout.last_diff.take().unwrap(); + cx.scene.push_quad(diff_quad( + last_hunk.status(), + start_line..ix, + &gutter_layout, + diff_style, + )); + } + + if is_starting { + let new_hunk = new_hunk.unwrap(); - diff_layout.last_diff = Some((new_hunk, ix)); - }; + diff_layout.last_diff = Some((new_hunk, ix)); + }; - diff_layout.buffer_line += 1; + diff_layout.buffer_line += 1; + } } } diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 38393dc8a8c4b143e87dc27d68e3e87811696f04..67e93416aebb2caa8b3b3d6611a8a5637b0e7ba5 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -19,7 +19,6 @@ impl GitRepository for LibGitRepository { fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result> { const STAGE_NORMAL: i32 = 0; let index = repo.index()?; - dbg!(relative_file_path); let oid = match index.get_path(relative_file_path, STAGE_NORMAL) { Some(entry) => entry.id, None => return Ok(None), diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index fb07bd837f3ed1ce1e8a2a8cc30c7bf7fa9f537a..6880ec4ff11c1ac4df4ffb7e0c163626e0fc11a8 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -32,7 +32,7 @@ use postage::{ prelude::{Sink as _, Stream as _}, watch, }; -use settings::Settings; + use smol::channel::{self, Sender}; use std::{ any::Any, @@ -664,40 +664,18 @@ impl LocalWorktree { let fs = self.fs.clone(); let snapshot = self.snapshot(); - let settings = cx.global::(); - - // Cut files included because we want to ship! - // TODO: - // - Rename / etc. setting to be show/hide git gutters - // - Unconditionally load index text for all files, - // - then choose at rendering time based on settings - - let files_included = settings.git_gutter().files_included(settings); - cx.spawn(|this, mut cx| async move { let text = fs.load(&abs_path).await?; - let diff_base = match files_included { - settings::GitFilesIncluded::All | settings::GitFilesIncluded::OnlyTracked => { - let results = if let Some(repo) = snapshot.repo_for(&abs_path) { - cx.background() - .spawn({ - let path = path.clone(); - async move { repo.repo.lock().load_index(&path) } - }) - .await - } else { - None - }; - - if files_included == settings::GitFilesIncluded::All { - results.or_else(|| Some(text.clone())) - } else { - results - } - } - - settings::GitFilesIncluded::None => None, + let diff_base = if let Some(repo) = snapshot.repo_for(&abs_path) { + cx.background() + .spawn({ + let path = path.clone(); + async move { repo.repo.lock().load_index(&path) } + }) + .await + } else { + None }; // Eagerly populate the snapshot with an updated entry for the loaded file @@ -1387,7 +1365,6 @@ impl LocalSnapshot { // Gives the most specific git repository for a given path pub(crate) fn repo_for(&self, path: &Path) -> Option { - dbg!(&self.git_repositories); self.git_repositories .iter() .rev() //git_repository is ordered lexicographically @@ -1725,7 +1702,6 @@ impl LocalSnapshot { impl GitRepositoryEntry { // Note that these paths should be relative to the worktree root. pub(crate) fn manages(&self, path: &Path) -> bool { - dbg!(path, &self.content_path); path.starts_with(self.content_path.as_ref()) } diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 3bf09436edd81ed5bf83affd0a81ab0ff9ff359c..fd04fc0aa66ad7741b598aa84f5c9d66e7d45800 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -57,34 +57,19 @@ impl FeatureFlags { #[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)] pub struct GitSettings { pub git_gutter: Option, + pub gutter_debounce: Option, } #[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)] -pub struct GitGutter { - pub files_included: Option, - pub debounce_delay_millis: Option, -} - -impl GitGutter { - pub fn files_included(&self, settings: &Settings) -> GitFilesIncluded { - self.files_included.unwrap_or_else(|| { - settings - .git.git_gutter.expect("git_gutter must be some in defaults.json") - .files_included - .expect("Should be some in defaults.json") - }) - } -} - -#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema, PartialEq, Eq)] #[serde(rename_all = "snake_case")] -pub enum GitFilesIncluded { +pub enum GitGutter { #[default] - All, - OnlyTracked, - None, + TrackedFiles, + Hide, } +pub struct GitGutterConfig {} + #[derive(Clone, Debug, Default, Deserialize, JsonSchema)] pub struct EditorSettings { pub tab_size: Option, @@ -428,12 +413,7 @@ impl Settings { editor_overrides: Default::default(), terminal_defaults: Default::default(), terminal_overrides: Default::default(), - git: GitSettings { - git_gutter: Some(GitGutter { - files_included: Some(GitFilesIncluded::All), - debounce_delay_millis: None, - }), - }, + git: Default::default(), git_overrides: Default::default(), language_defaults: Default::default(), language_overrides: Default::default(), diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 44c9b19f1bbd419b6e6eceb3b3c39c31fc587bec..2ae498d7015053652497bcfce07b11ae750117fd 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -735,16 +735,7 @@ impl ItemHandle for ViewHandle { } let settings = cx.global::(); - let debounce_delay = settings - .git_overrides - .git_gutter - .unwrap_or_else(|| { - settings - .git - .git_gutter - .expect("This should be Some by setting setup") - }) - .debounce_delay_millis; + let debounce_delay = settings.git_overrides.gutter_debounce; let item = item.clone();