Skip to content

Commit

Permalink
zeta: Add action to clear edit history (#21813)
Browse files Browse the repository at this point in the history
Co-Authored-by: Antonio <antonio@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: Antonio <antonio@zed.dev>
  • Loading branch information
bennetbo and as-cii authored Dec 10, 2024
1 parent 03efd0d commit c6932d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions crates/zed/src/zed/inline_completion_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion crates/zeta/src/zeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c6932d1

Please sign in to comment.