From 19b6c4444e6cc7de789dee1a73f9bd26f66dca9c Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Mon, 12 May 2025 16:03:50 +0200 Subject: [PATCH] zeta: Do not show usage for copilot/supermaven (#30563) Follow up to #29952 Release Notes: - Fix an issue where zeta usage would show up when using Copilot as an edit prediction provider --- Cargo.lock | 2 - crates/inline_completion_button/Cargo.toml | 2 - .../src/inline_completion_button.rs | 94 +++++++------------ crates/zeta/src/zeta.rs | 30 +++++- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b48065699..4d2d689076 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7225,7 +7225,6 @@ dependencies = [ "lsp", "paths", "project", - "proto", "regex", "serde_json", "settings", @@ -7233,7 +7232,6 @@ dependencies = [ "telemetry", "theme", "ui", - "util", "workspace", "workspace-hack", "zed_actions", diff --git a/crates/inline_completion_button/Cargo.toml b/crates/inline_completion_button/Cargo.toml index ec921574e3..c2a619d500 100644 --- a/crates/inline_completion_button/Cargo.toml +++ b/crates/inline_completion_button/Cargo.toml @@ -24,13 +24,11 @@ indoc.workspace = true inline_completion.workspace = true language.workspace = true paths.workspace = true -proto.workspace = true regex.workspace = true settings.workspace = true supermaven.workspace = true telemetry.workspace = true ui.workspace = true -util.workspace = true workspace-hack.workspace = true workspace.workspace = true zed_actions.workspace = true diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rs index fd25823307..0e0177b138 100644 --- a/crates/inline_completion_button/src/inline_completion_button.rs +++ b/crates/inline_completion_button/src/inline_completion_button.rs @@ -14,7 +14,6 @@ use gpui::{ pulsating_between, }; use indoc::indoc; -use inline_completion::EditPredictionUsage; use language::{ EditPredictionsMode, File, Language, language_settings::{self, AllLanguageSettings, EditPredictionProvider, all_language_settings}, @@ -30,7 +29,6 @@ use ui::{ Clickable, ContextMenu, ContextMenuEntry, DocumentationSide, IconButton, IconButtonShape, Indicator, PopoverMenu, PopoverMenuHandle, ProgressBar, Tooltip, prelude::*, }; -use util::maybe; use workspace::{ StatusItemView, Toast, Workspace, create_and_open_local_file, item::ItemHandle, notifications::NotificationId, @@ -405,64 +403,44 @@ impl InlineCompletionButton { let fs = self.fs.clone(); let line_height = window.line_height(); - if let Some(provider) = self.edit_prediction_provider.as_ref() { - let usage = provider.usage(cx).or_else(|| { - let user_store = self.user_store.read(cx); - - maybe!({ - let amount = user_store.edit_predictions_usage_amount()?; - let limit = user_store.edit_predictions_usage_limit()?.variant?; - - Some(EditPredictionUsage { - amount: amount as i32, - limit: match limit { - proto::usage_limit::Variant::Limited(limited) => { - zed_llm_client::UsageLimit::Limited(limited.limit as i32) + if let Some(usage) = self + .edit_prediction_provider + .as_ref() + .and_then(|provider| provider.usage(cx)) + { + menu = menu.header("Usage"); + menu = menu + .custom_entry( + move |_window, cx| { + let used_percentage = match usage.limit { + UsageLimit::Limited(limit) => { + Some((usage.amount as f32 / limit as f32) * 100.) } - proto::usage_limit::Variant::Unlimited(_) => { - zed_llm_client::UsageLimit::Unlimited - } - }, - }) - }) - }); + UsageLimit::Unlimited => None, + }; - if let Some(usage) = usage { - menu = menu.header("Usage"); - menu = menu - .custom_entry( - move |_window, cx| { - let used_percentage = match usage.limit { - UsageLimit::Limited(limit) => { - Some((usage.amount as f32 / limit as f32) * 100.) - } - UsageLimit::Unlimited => None, - }; - - h_flex() - .flex_1() - .gap_1p5() - .children( - used_percentage.map(|percent| { - ProgressBar::new("usage", percent, 100., cx) - }), - ) - .child( - Label::new(match usage.limit { - UsageLimit::Limited(limit) => { - format!("{} / {limit}", usage.amount) - } - UsageLimit::Unlimited => format!("{} / ∞", usage.amount), - }) - .size(LabelSize::Small) - .color(Color::Muted), - ) - .into_any_element() - }, - move |_, cx| cx.open_url(&zed_urls::account_url(cx)), - ) - .separator(); - } + h_flex() + .flex_1() + .gap_1p5() + .children( + used_percentage + .map(|percent| ProgressBar::new("usage", percent, 100., cx)), + ) + .child( + Label::new(match usage.limit { + UsageLimit::Limited(limit) => { + format!("{} / {limit}", usage.amount) + } + UsageLimit::Unlimited => format!("{} / ∞", usage.amount), + }) + .size(LabelSize::Small) + .color(Color::Muted), + ) + .into_any_element() + }, + move |_, cx| cx.open_url(&zed_urls::account_url(cx)), + ) + .separator(); } menu = menu.header("Show Edit Predictions For"); diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs index eb82e97ec1..e6abc756b5 100644 --- a/crates/zeta/src/zeta.rs +++ b/crates/zeta/src/zeta.rs @@ -48,7 +48,7 @@ use std::{ }; use telemetry_events::InlineCompletionRating; use thiserror::Error; -use util::ResultExt; +use util::{ResultExt, maybe}; use uuid::Uuid; use workspace::Workspace; use workspace::notifications::{ErrorMessagePrompt, NotificationId}; @@ -193,6 +193,7 @@ pub struct Zeta { tos_accepted: bool, /// Whether an update to a newer version of Zed is required to continue using Zeta. update_required: bool, + user_store: Entity, _user_store_subscription: Subscription, license_detection_watchers: HashMap>, } @@ -232,6 +233,28 @@ impl Zeta { self.events.clear(); } + pub fn usage(&self, cx: &App) -> Option { + self.last_usage.or_else(|| { + let user_store = self.user_store.read(cx); + maybe!({ + let amount = user_store.edit_predictions_usage_amount()?; + let limit = user_store.edit_predictions_usage_limit()?.variant?; + + Some(EditPredictionUsage { + amount: amount as i32, + limit: match limit { + proto::usage_limit::Variant::Limited(limited) => { + zed_llm_client::UsageLimit::Limited(limited.limit as i32) + } + proto::usage_limit::Variant::Unlimited(_) => { + zed_llm_client::UsageLimit::Unlimited + } + }, + }) + }) + }) + } + fn new( workspace: Option>, client: Arc, @@ -282,6 +305,7 @@ impl Zeta { } }), license_detection_watchers: HashMap::default(), + user_store, } } @@ -1417,7 +1441,7 @@ impl inline_completion::EditPredictionProvider for ZetaInlineCompletionProvider } fn usage(&self, cx: &App) -> Option { - self.zeta.read(cx).last_usage + self.zeta.read(cx).usage(cx) } fn is_enabled( @@ -1891,6 +1915,7 @@ mod tests { zeta.request_completion(None, &buffer, cursor, false, cx) }); + server.receive::().await.unwrap(); let token_request = server.receive::().await.unwrap(); server.respond( token_request.receipt(), @@ -1945,6 +1970,7 @@ mod tests { zeta.request_completion(None, &buffer, cursor, false, cx) }); + server.receive::().await.unwrap(); let token_request = server.receive::().await.unwrap(); server.respond( token_request.receipt(),