Project Diff 2 (#23891)
This adds a new version of the project diff editor to go alongside the new git panel. The basics seem to be working, but still todo: * [ ] Fix untracked files * [ ] Fix deleted files * [ ] Show commit message editor at top * [x] Handle empty state * [x] Fix panic where locator sometimes seeks to wrong excerpt Release Notes: - N/A
This commit is contained in:
parent
27a413a5e3
commit
45708d2680
21 changed files with 1023 additions and 125 deletions
|
@ -1,6 +1,9 @@
|
|||
use futures::channel::oneshot;
|
||||
use futures::{select_biased, FutureExt};
|
||||
use gpui::{App, Context, Global, Subscription, Task, Window};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Duration;
|
||||
use std::{future::Future, pin::Pin, task::Poll};
|
||||
|
||||
|
@ -10,12 +13,21 @@ struct FeatureFlags {
|
|||
staff: bool,
|
||||
}
|
||||
|
||||
pub static ZED_DISABLE_STAFF: LazyLock<bool> = LazyLock::new(|| {
|
||||
std::env::var("ZED_DISABLE_STAFF").map_or(false, |value| !value.is_empty() && value != "0")
|
||||
});
|
||||
|
||||
impl FeatureFlags {
|
||||
fn has_flag<T: FeatureFlag>(&self) -> bool {
|
||||
if self.staff && T::enabled_for_staff() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
if T::enabled_in_development() {
|
||||
return true;
|
||||
}
|
||||
|
||||
self.flags.iter().any(|f| f.as_str() == T::NAME)
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +47,10 @@ pub trait FeatureFlag {
|
|||
fn enabled_for_staff() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn enabled_in_development() -> bool {
|
||||
Self::enabled_for_staff() && !*ZED_DISABLE_STAFF
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Assistant2FeatureFlag;
|
||||
|
@ -97,6 +113,12 @@ pub trait FeatureFlagViewExt<V: 'static> {
|
|||
fn observe_flag<T: FeatureFlag, F>(&mut self, window: &Window, callback: F) -> Subscription
|
||||
where
|
||||
F: Fn(bool, &mut V, &mut Window, &mut Context<V>) + Send + Sync + 'static;
|
||||
|
||||
fn when_flag_enabled<T: FeatureFlag>(
|
||||
&mut self,
|
||||
window: &mut Window,
|
||||
callback: impl Fn(&mut V, &mut Window, &mut Context<V>) + Send + Sync + 'static,
|
||||
);
|
||||
}
|
||||
|
||||
impl<V> FeatureFlagViewExt<V> for Context<'_, V>
|
||||
|
@ -112,6 +134,35 @@ where
|
|||
callback(feature_flags.has_flag::<T>(), v, window, cx);
|
||||
})
|
||||
}
|
||||
|
||||
fn when_flag_enabled<T: FeatureFlag>(
|
||||
&mut self,
|
||||
window: &mut Window,
|
||||
callback: impl Fn(&mut V, &mut Window, &mut Context<V>) + Send + Sync + 'static,
|
||||
) {
|
||||
if self
|
||||
.try_global::<FeatureFlags>()
|
||||
.is_some_and(|f| f.has_flag::<T>())
|
||||
|| cfg!(debug_assertions) && T::enabled_in_development()
|
||||
{
|
||||
self.defer_in(window, move |view, window, cx| {
|
||||
callback(view, window, cx);
|
||||
});
|
||||
return;
|
||||
}
|
||||
let subscription = Rc::new(RefCell::new(None));
|
||||
let inner = self.observe_global_in::<FeatureFlags>(window, {
|
||||
let subscription = subscription.clone();
|
||||
move |v, window, cx| {
|
||||
let feature_flags = cx.global::<FeatureFlags>();
|
||||
if feature_flags.has_flag::<T>() {
|
||||
callback(v, window, cx);
|
||||
subscription.take();
|
||||
}
|
||||
}
|
||||
});
|
||||
subscription.borrow_mut().replace(inner);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FeatureFlagAppExt {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue