zeta: Add action to clear edit history (#21813)

Co-Authored-by: Antonio <antonio@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
Bennet Bo Fenner
2024-12-10 16:57:24 +01:00
committed by GitHub
co-authored by Antonio
parent 03efd0d1d9
commit c6932d1f51
2 changed files with 22 additions and 3 deletions
@@ -49,12 +49,19 @@ pub fn init(client: Arc<Client>, cx: &mut AppContext) {
});
}
if cx.has_flag::<ZetaFeatureFlag>() {
cx.on_action(clear_zeta_edit_history);
}
cx.observe_flag::<ZetaFeatureFlag, _>({
let editors = editors.clone();
let client = client.clone();
move |_flag, cx| {
move |active, cx| {
let provider = all_language_settings(None, cx).inline_completions.provider;
assign_inline_completion_providers(&editors, provider, &client, cx)
assign_inline_completion_providers(&editors, provider, &client, cx);
if active && !cx.is_action_available(&zeta::ClearHistory) {
cx.on_action(clear_zeta_edit_history);
}
}
})
.detach();
@@ -73,6 +80,12 @@ pub fn init(client: Arc<Client>, cx: &mut AppContext) {
.detach();
}
fn clear_zeta_edit_history(_: &zeta::ClearHistory, cx: &mut AppContext) {
if let Some(zeta) = zeta::Zeta::global(cx) {
zeta.update(cx, |zeta, _| zeta.clear_history());
}
}
fn assign_inline_completion_providers(
editors: &Rc<RefCell<HashMap<WeakView<Editor>, AnyWindowHandle>>>,
provider: InlineCompletionProvider,
+7 -1
View File
@@ -6,7 +6,7 @@ use anyhow::{anyhow, Context as _, Result};
use client::Client;
use collections::{HashMap, HashSet, VecDeque};
use futures::AsyncReadExt;
use gpui::{AppContext, Context, Global, Model, ModelContext, Subscription, Task};
use gpui::{actions, AppContext, Context, Global, Model, ModelContext, Subscription, Task};
use http_client::{HttpClient, Method};
use language::{
language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot, OffsetRangeExt,
@@ -34,6 +34,8 @@ const EDITABLE_REGION_START_MARKER: &'static str = "<|editable_region_start|>";
const EDITABLE_REGION_END_MARKER: &'static str = "<|editable_region_end|>";
const BUFFER_CHANGE_GROUPING_INTERVAL: Duration = Duration::from_secs(1);
actions!(zeta, [ClearHistory]);
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, Hash)]
pub struct InlineCompletionId(Uuid);
@@ -155,6 +157,10 @@ impl Zeta {
})
}
pub fn clear_history(&mut self) {
self.events.clear();
}
fn new(client: Arc<Client>, cx: &mut ModelContext<Self>) -> Self {
let refresh_llm_token_listener = language_models::RefreshLlmTokenListener::global(cx);