From e19995431b6fe37f419975aa2573a5227e602381 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Mon, 15 Sep 2025 10:46:10 -0300 Subject: [PATCH 1/2] Create zeta2 crate --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + crates/zeta2/Cargo.toml | 20 ++++++++++++++++++++ crates/zeta2/LICENSE-GPL | 1 + crates/zeta2/src/zeta2.rs | 1 + 5 files changed, 35 insertions(+) create mode 100644 crates/zeta2/Cargo.toml create mode 120000 crates/zeta2/LICENSE-GPL create mode 100644 crates/zeta2/src/zeta2.rs diff --git a/Cargo.lock b/Cargo.lock index 227e4127b6ad25501c0af1161d790caf7db0425e..40d3b2beea98091129ea5c614cde3ae445d1f7b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20919,6 +20919,18 @@ dependencies = [ "zlog", ] +[[package]] +name = "zeta2" +version = "0.1.0" +dependencies = [ + "client", + "edit_prediction", + "gpui", + "language", + "project", + "workspace-hack", +] + [[package]] name = "zeta_cli" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index c8983efc7784a483fd7c5c759c7d9c10f1dab680..c947708564548e5c9d4812619ec4c4924da8b5b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -197,6 +197,7 @@ members = [ "crates/zed_actions", "crates/zed_env_vars", "crates/zeta", + "crates/zeta2", "crates/zeta_cli", "crates/zlog", "crates/zlog_settings", diff --git a/crates/zeta2/Cargo.toml b/crates/zeta2/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..eb8e0272ff46146268f90f397ca33e6b1541cceb --- /dev/null +++ b/crates/zeta2/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "zeta2" +version = "0.1.0" +edition.workspace = true +publish.workspace = true +license = "GPL-3.0-or-later" + +[lints] +workspace = true + +[lib] +path = "src/zeta2.rs" + +[dependencies] +client.workspace = true +edit_prediction.workspace = true +gpui.workspace = true +language.workspace = true +project.workspace = true +workspace-hack.workspace = true \ No newline at end of file diff --git a/crates/zeta2/LICENSE-GPL b/crates/zeta2/LICENSE-GPL new file mode 120000 index 0000000000000000000000000000000000000000..89e542f750cd3860a0598eff0dc34b56d7336dc4 --- /dev/null +++ b/crates/zeta2/LICENSE-GPL @@ -0,0 +1 @@ +../../LICENSE-GPL \ No newline at end of file diff --git a/crates/zeta2/src/zeta2.rs b/crates/zeta2/src/zeta2.rs new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/crates/zeta2/src/zeta2.rs @@ -0,0 +1 @@ + From d8dd2b2977db9acd0f6b9f15a179ddcbc472828f Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Mon, 15 Sep 2025 12:17:01 -0300 Subject: [PATCH 2/2] Add zeta2 to registry --- Cargo.lock | 2 + Cargo.toml | 1 + .../src/edit_prediction_button.rs | 2 +- crates/language/src/language_settings.rs | 3 +- crates/zed/Cargo.toml | 1 + .../zed/src/zed/edit_prediction_registry.rs | 5 + crates/zeta2/Cargo.toml | 3 +- crates/zeta2/src/zeta2.rs | 153 ++++++++++++++++++ 8 files changed, 167 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40d3b2beea98091129ea5c614cde3ae445d1f7b5..c7fa66909366fea330ab6d00705b3495102771d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20643,6 +20643,7 @@ dependencies = [ "zed_actions", "zed_env_vars", "zeta", + "zeta2", "zlog", "zlog_settings", ] @@ -20928,6 +20929,7 @@ dependencies = [ "gpui", "language", "project", + "util", "workspace-hack", ] diff --git a/Cargo.toml b/Cargo.toml index c947708564548e5c9d4812619ec4c4924da8b5b7..680cf293fb2e35e9db08c4845f2b8f403b890554 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -428,6 +428,7 @@ zed = { path = "crates/zed" } zed_actions = { path = "crates/zed_actions" } zed_env_vars = { path = "crates/zed_env_vars" } zeta = { path = "crates/zeta" } +zeta2 = { path = "crates/zeta2" } zlog = { path = "crates/zlog" } zlog_settings = { path = "crates/zlog_settings" } diff --git a/crates/edit_prediction_button/src/edit_prediction_button.rs b/crates/edit_prediction_button/src/edit_prediction_button.rs index 0e3fe8cb1a449e494592d8f517feb26131d89f65..a93e45746f1fcb80d513cb081632fe6463f1245e 100644 --- a/crates/edit_prediction_button/src/edit_prediction_button.rs +++ b/crates/edit_prediction_button/src/edit_prediction_button.rs @@ -233,7 +233,7 @@ impl Render for EditPredictionButton { ) } - EditPredictionProvider::Zed => { + EditPredictionProvider::Zed | EditPredictionProvider::Zed2 => { let enabled = self.editor_enabled.unwrap_or(true); let zeta_icon = if enabled { diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index af9e6edbfa4ed2ef44d7a5789069a83b7db829c7..61c408514e44d19c12b29501523d3184edc7da0f 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -220,12 +220,13 @@ pub enum EditPredictionProvider { Copilot, Supermaven, Zed, + Zed2, } impl EditPredictionProvider { pub fn is_zed(&self) -> bool { match self { - EditPredictionProvider::Zed => true, + EditPredictionProvider::Zed | EditPredictionProvider::Zed2 => true, EditPredictionProvider::None | EditPredictionProvider::Copilot | EditPredictionProvider::Supermaven => false, diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index cc18e50a9c2f81bc6d84e448ee807a792bcd8fe8..810cf317ad0596c25d5165171e198248687d6a93 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -165,6 +165,7 @@ workspace.workspace = true zed_actions.workspace = true zed_env_vars.workspace = true zeta.workspace = true +zeta2.workspace = true zlog.workspace = true zlog_settings.workspace = true diff --git a/crates/zed/src/zed/edit_prediction_registry.rs b/crates/zed/src/zed/edit_prediction_registry.rs index ae26427fc6547079b163235f5d1c3df26a489795..e22151368b4886099cad296ac7bd8d3d40596a03 100644 --- a/crates/zed/src/zed/edit_prediction_registry.rs +++ b/crates/zed/src/zed/edit_prediction_registry.rs @@ -220,5 +220,10 @@ fn assign_edit_prediction_provider( editor.set_edit_prediction_provider(Some(provider), window, cx); } } + EditPredictionProvider::Zed2 => { + let provider = cx.new(|_| zeta2::Zeta2EditPredictionProvider::new()); + + editor.set_edit_prediction_provider(Some(provider), window, cx); + } } } diff --git a/crates/zeta2/Cargo.toml b/crates/zeta2/Cargo.toml index eb8e0272ff46146268f90f397ca33e6b1541cceb..5c975bd84b4a8b9fc660ea39c7cf4887cbb0b46e 100644 --- a/crates/zeta2/Cargo.toml +++ b/crates/zeta2/Cargo.toml @@ -17,4 +17,5 @@ edit_prediction.workspace = true gpui.workspace = true language.workspace = true project.workspace = true -workspace-hack.workspace = true \ No newline at end of file +workspace-hack.workspace = true +util.workspace = true diff --git a/crates/zeta2/src/zeta2.rs b/crates/zeta2/src/zeta2.rs index 8b137891791fe96927ad78e64b0aad7bded08bdc..46de8a1a8ec36d47bb6bcc3cd68ec3492fae98a1 100644 --- a/crates/zeta2/src/zeta2.rs +++ b/crates/zeta2/src/zeta2.rs @@ -1 +1,154 @@ +use std::{ops::Range, sync::Arc}; +use gpui::{App, Entity, EntityId, Task, prelude::*}; + +use edit_prediction::{DataCollectionState, Direction, EditPrediction, EditPredictionProvider}; +use language::{Anchor, ToPoint}; + +pub struct Zeta2EditPredictionProvider { + current: Option, + pending: Option>, +} + +impl Zeta2EditPredictionProvider { + pub fn new() -> Self { + Self { + current: None, + pending: None, + } + } +} + +#[derive(Clone)] +struct CurrentEditPrediction { + buffer_id: EntityId, + prediction: EditPrediction, +} + +impl EditPredictionProvider for Zeta2EditPredictionProvider { + fn name() -> &'static str { + // TODO [zeta2] + "zed-predict2" + } + + fn display_name() -> &'static str { + "Zed's Edit Predictions 2" + } + + fn show_completions_in_menu() -> bool { + true + } + + fn show_tab_accept_marker() -> bool { + true + } + + fn data_collection_state(&self, _cx: &App) -> DataCollectionState { + // TODO [zeta2] + DataCollectionState::Unsupported + } + + fn toggle_data_collection(&mut self, _cx: &mut App) { + // TODO [zeta2] + } + + fn usage(&self, _cx: &App) -> Option { + // TODO [zeta2] + None + } + + fn is_enabled( + &self, + _buffer: &Entity, + _cursor_position: language::Anchor, + _cx: &App, + ) -> bool { + true + } + + fn is_refreshing(&self) -> bool { + self.pending.is_some() + } + + fn refresh( + &mut self, + _project: Option>, + buffer: Entity, + cursor_position: language::Anchor, + _debounce: bool, + cx: &mut Context, + ) { + // TODO [zeta2] check account + // TODO [zeta2] actually request completion / interpolate + + let snapshot = buffer.read(cx).snapshot(); + let point = cursor_position.to_point(&snapshot); + let end_anchor = snapshot.anchor_before(language::Point::new( + point.row, + snapshot.line_len(point.row), + )); + + let edits: Arc<[(Range, String)]> = + vec![(cursor_position..end_anchor, "👻".to_string())].into(); + let edits_preview_task = buffer.read(cx).preview_edits(edits.clone(), cx); + + // TODO [zeta2] throttle + // TODO [zeta2] keep 2 requests + self.pending = Some(cx.spawn(async move |this, cx| { + let edits_preview = edits_preview_task.await; + + this.update(cx, |this, cx| { + this.current = Some(CurrentEditPrediction { + buffer_id: buffer.entity_id(), + prediction: EditPrediction { + // TODO! [zeta2] request id? + id: None, + edits: edits.to_vec(), + edit_preview: Some(edits_preview), + }, + }); + this.pending.take(); + cx.notify(); + }) + .ok(); + })); + cx.notify(); + } + + fn cycle( + &mut self, + _buffer: Entity, + _cursor_position: language::Anchor, + _direction: Direction, + _cx: &mut Context, + ) { + } + + fn accept(&mut self, _cx: &mut Context) { + // TODO [zeta2] report accept + self.current.take(); + self.pending.take(); + } + + fn discard(&mut self, _cx: &mut Context) { + self.current.take(); + self.pending.take(); + } + + fn suggest( + &mut self, + buffer: &Entity, + _cursor_position: language::Anchor, + _cx: &mut Context, + ) -> Option { + let current_prediction = self.current.take()?; + + if current_prediction.buffer_id != buffer.entity_id() { + return None; + } + + // TODO [zeta2] interpolate + + Some(current_prediction.prediction) + } +}