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