Removed debugs, simplified settings
This commit is contained in:
parent
6f7547d28f
commit
499e95d16a
6 changed files with 61 additions and 118 deletions
|
@ -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": {
|
||||
|
|
|
@ -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::<Settings>().theme.editor.diff.clone();
|
||||
// dbg!("***************");
|
||||
// dbg!(&layout.diff_hunks);
|
||||
// dbg!("***************");
|
||||
let show_gutter = matches!(
|
||||
&cx.global::<Settings>()
|
||||
.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);
|
||||
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),
|
||||
};
|
||||
// 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();
|
||||
cx.scene.push_quad(diff_quad(
|
||||
last_hunk.status(),
|
||||
start_line..ix,
|
||||
&gutter_layout,
|
||||
diff_style,
|
||||
));
|
||||
}
|
||||
|
||||
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 is_starting {
|
||||
let new_hunk = new_hunk.unwrap();
|
||||
|
||||
diff_layout.last_diff = Some((new_hunk, ix));
|
||||
};
|
||||
|
||||
diff_layout.buffer_line += 1;
|
||||
}
|
||||
|
||||
if is_starting {
|
||||
let new_hunk = new_hunk.unwrap();
|
||||
|
||||
diff_layout.last_diff = Some((new_hunk, ix));
|
||||
};
|
||||
|
||||
diff_layout.buffer_line += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ impl GitRepository for LibGitRepository {
|
|||
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
||||
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),
|
||||
|
|
|
@ -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::<Settings>();
|
||||
|
||||
// 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<GitRepositoryEntry> {
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
@ -57,34 +57,19 @@ impl FeatureFlags {
|
|||
#[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct GitSettings {
|
||||
pub git_gutter: Option<GitGutter>,
|
||||
pub gutter_debounce: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct GitGutter {
|
||||
pub files_included: Option<GitFilesIncluded>,
|
||||
pub debounce_delay_millis: Option<u64>,
|
||||
}
|
||||
|
||||
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<NonZeroU32>,
|
||||
|
@ -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(),
|
||||
|
|
|
@ -735,16 +735,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
}
|
||||
|
||||
let settings = cx.global::<Settings>();
|
||||
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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue