Remove concept of git diff refresh from Item trait

This commit is contained in:
Julia 2023-05-25 14:29:28 -04:00
parent cede296b04
commit 8d662edb6c
11 changed files with 109 additions and 127 deletions

View file

@ -1,9 +1,8 @@
use crate::{
pane, persistence::model::ItemId, searchable::SearchableItemHandle, DelayedDebouncedEditAction,
FollowableItemBuilders, ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace,
WorkspaceId,
pane, persistence::model::ItemId, searchable::SearchableItemHandle, FollowableItemBuilders,
ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace, WorkspaceId,
};
use crate::{AutosaveSetting, WorkspaceSettings};
use crate::{AutosaveSetting, DelayedDebouncedEditAction, WorkspaceSettings};
use anyhow::Result;
use client::{proto, Client};
use gpui::{
@ -102,13 +101,6 @@ pub trait Item: View {
) -> Task<Result<()>> {
unimplemented!("reload() must be implemented if can_save() returns true")
}
fn git_diff_recalc(
&mut self,
_project: ModelHandle<Project>,
_cx: &mut ViewContext<Self>,
) -> Task<Result<()>> {
Task::ready(Ok(()))
}
fn to_item_events(_event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
SmallVec::new()
}
@ -221,11 +213,6 @@ pub trait ItemHandle: 'static + fmt::Debug {
cx: &mut WindowContext,
) -> Task<Result<()>>;
fn reload(&self, project: ModelHandle<Project>, cx: &mut WindowContext) -> Task<Result<()>>;
fn git_diff_recalc(
&self,
project: ModelHandle<Project>,
cx: &mut WindowContext,
) -> Task<Result<()>>;
fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle>;
fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>>;
fn on_release(
@ -381,7 +368,6 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
.is_none()
{
let mut pending_autosave = DelayedDebouncedEditAction::new();
let mut pending_git_update = DelayedDebouncedEditAction::new();
let pending_update = Rc::new(RefCell::new(None));
let pending_update_scheduled = Rc::new(AtomicBool::new(false));
@ -450,48 +436,14 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
}
ItemEvent::Edit => {
let settings = settings::get::<WorkspaceSettings>(cx);
let debounce_delay = settings.git.gutter_debounce;
if let AutosaveSetting::AfterDelay { milliseconds } =
settings.autosave
{
let autosave = settings::get::<WorkspaceSettings>(cx).autosave;
if let AutosaveSetting::AfterDelay { milliseconds } = autosave {
let delay = Duration::from_millis(milliseconds);
let item = item.clone();
pending_autosave.fire_new(delay, cx, move |workspace, cx| {
Pane::autosave_item(&item, workspace.project().clone(), cx)
});
}
let item = item.clone();
if let Some(delay) = debounce_delay {
const MIN_GIT_DELAY: u64 = 50;
let delay = delay.max(MIN_GIT_DELAY);
let duration = Duration::from_millis(delay);
pending_git_update.fire_new(
duration,
cx,
move |workspace, cx| {
item.git_diff_recalc(workspace.project().clone(), cx)
},
);
} else {
cx.spawn(|workspace, mut cx| async move {
workspace
.update(&mut cx, |workspace, cx| {
item.git_diff_recalc(
workspace.project().clone(),
cx,
)
})?
.await?;
anyhow::Ok(())
})
.detach_and_log_err(cx);
}
}
_ => {}
@ -576,14 +528,6 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
self.update(cx, |item, cx| item.reload(project, cx))
}
fn git_diff_recalc(
&self,
project: ModelHandle<Project>,
cx: &mut WindowContext,
) -> Task<Result<()>> {
self.update(cx, |item, cx| item.git_diff_recalc(project, cx))
}
fn act_as_type<'a>(&'a self, type_id: TypeId, cx: &'a AppContext) -> Option<&'a AnyViewHandle> {
self.read(cx).act_as_type(type_id, self, cx)
}

View file

@ -442,7 +442,7 @@ impl DelayedDebouncedEditAction {
}
}
fn fire_new<F>(&mut self, delay: Duration, cx: &mut ViewContext<Workspace>, f: F)
fn fire_new<F>(&mut self, delay: Duration, cx: &mut ViewContext<Workspace>, func: F)
where
F: 'static + FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> Task<Result<()>>,
{
@ -466,7 +466,7 @@ impl DelayedDebouncedEditAction {
}
if let Some(result) = workspace
.update(&mut cx, |workspace, cx| (f)(workspace, cx))
.update(&mut cx, |workspace, cx| (func)(workspace, cx))
.log_err()
{
result.await.log_err();

View file

@ -8,7 +8,6 @@ pub struct WorkspaceSettings {
pub confirm_quit: bool,
pub show_call_status_icon: bool,
pub autosave: AutosaveSetting,
pub git: GitSettings,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
@ -17,7 +16,6 @@ pub struct WorkspaceSettingsContent {
pub confirm_quit: Option<bool>,
pub show_call_status_icon: Option<bool>,
pub autosave: Option<AutosaveSetting>,
pub git: Option<GitSettings>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]