Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add Sign Out link for Supermaven (#14834)
Kevin Wang46b7fa9bcbee
diff --git a/crates/inline_completion_button/src/inline_completion_button.rs b/crates/inline_completion_button/src/inline_completion_button.rsindex 1918481e41f..19e4fe2545b 100644--- a/crates/inline_completion_button/src/inline_completion_button.rs+++ b/crates/inline_completion_button/src/inline_completion_button.rs@@ -298,7 +298,9 @@ impl InlineCompletionButton {fn build_supermaven_context_menu(&self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {ContextMenu::build(cx, |menu, cx| {- self.build_language_settings_menu(menu, cx).separator()+ self.build_language_settings_menu(menu, cx)+ .separator()+ .action("Sign Out", supermaven::SignOut.boxed_clone())})}diff --git a/crates/supermaven/src/messages.rs b/crates/supermaven/src/messages.rsindex 9082e00d60f..f515d6353b1 100644--- a/crates/supermaven/src/messages.rs+++ b/crates/supermaven/src/messages.rs@@ -14,6 +14,7 @@ pub enum OutboundMessage {StateUpdate(StateUpdateMessage),#[allow(dead_code)]UseFreeVersion,+ Logout,}#[derive(Debug, Serialize, Deserialize)]diff --git a/crates/supermaven/src/supermaven.rs b/crates/supermaven/src/supermaven.rsindex cac2fc050b5..e0ebb31cf63 100644--- a/crates/supermaven/src/supermaven.rs+++ b/crates/supermaven/src/supermaven.rs@@ -9,7 +9,9 @@ use client::{proto, Client};use collections::BTreeMap;use futures::{channel::mpsc, io::BufReader, AsyncBufReadExt, StreamExt};-use gpui::{AppContext, AsyncAppContext, EntityId, Global, Model, ModelContext, Task, WeakModel};+use gpui::{+ actions, AppContext, AsyncAppContext, EntityId, Global, Model, ModelContext, Task, WeakModel,+};use language::{language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot, ToOffset,};@@ -25,6 +27,8 @@ use std::{path::PathBuf, process::Stdio, sync::Arc};use ui::prelude::*;use util::ResultExt;+actions!(supermaven, [SignOut]);+pub fn init(client: Arc<Client>, cx: &mut AppContext) {let supermaven = cx.new_model(|_| Supermaven::Starting);Supermaven::set_global(supermaven.clone(), cx);@@ -46,6 +50,12 @@ pub fn init(client: Arc<Client>, cx: &mut AppContext) {}}).detach();++ cx.on_action(|_: &SignOut, cx| {+ if let Some(supermaven) = Supermaven::global(cx) {+ supermaven.update(cx, |supermaven, _cx| supermaven.sign_out());+ }+ });}pub enum Supermaven {@@ -175,6 +185,19 @@ impl Supermaven {None}}++ pub fn sign_out(&mut self) {+ if let Self::Spawned(agent) = self {+ agent+ .outgoing_tx+ .unbounded_send(OutboundMessage::Logout)+ .ok();+ // The account status will get set to RequiresActivation or Ready when the next+ // message from the agent comes in. Until that happens, set the status to Unknown+ // to disable the button.+ agent.account_status = AccountStatus::Unknown;+ }+ }}fn find_relevant_completion<'a>(