Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add copilot theme, start sketching out the auth modal
Mikayla Makib57d5174aac0
diff --git a/crates/copilot/src/auth_modal.rs b/crates/copilot/src/auth_modal.rsnew file mode 100644index 00000000000..4786f1d470f--- /dev/null+++ b/crates/copilot/src/auth_modal.rs@@ -0,0 +1,20 @@+use gpui::{elements::Label, Element, Entity, View};+use settings::Settings;++pub struct AuthModal {}++impl Entity for AuthModal {+ type Event = ();+}++impl View for AuthModal {+ fn ui_name() -> &'static str {+ "AuthModal"+ }++ fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {+ let style = &cx.global::<Settings>().theme.copilot;++ Label::new("[COPILOT AUTH INFO]", style.auth_modal.clone()).boxed()+ }+}diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rsindex 9a24139ad66..2bdcedb2cc0 100644--- a/crates/copilot/src/copilot.rs+++ b/crates/copilot/src/copilot.rs@@ -1,7 +1,9 @@+mod auth_modal;mod request;use anyhow::{anyhow, Result};use async_compression::futures::bufread::GzipDecoder;+use auth_modal::AuthModal;use client::Client;use gpui::{actions, AppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};use language::{point_from_lsp, point_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, ToPointUtf16};@@ -16,26 +18,36 @@ use std::{use util::{fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt,};+use workspace::Workspace;-actions!(copilot, [SignIn, SignOut]);+actions!(copilot, [SignIn, SignOut, ToggleAuthStatus]);pub fn init(client: Arc<Client>, cx: &mut MutableAppContext) {let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), cx));- cx.set_global(copilot);- cx.add_global_action(|_: &SignIn, cx: &mut MutableAppContext| {+ cx.set_global(copilot.clone());+ cx.add_action(|workspace: &mut Workspace, _: &SignIn, cx| {if let Some(copilot) = Copilot::global(cx) {+ if copilot.read(cx).status() == Status::Authorized {+ return;+ }+copilot.update(cx, |copilot, cx| copilot.sign_in(cx)).detach_and_log_err(cx);++ workspace.toggle_modal(cx, |_workspace, cx| cx.add_view(|_cx| AuthModal {}));}});- cx.add_global_action(|_: &SignOut, cx: &mut MutableAppContext| {+ cx.add_action(|_: &mut Workspace, _: &SignOut, cx| {if let Some(copilot) = Copilot::global(cx) {copilot.update(cx, |copilot, cx| copilot.sign_out(cx)).detach_and_log_err(cx);}});+ cx.add_action(|workspace: &mut Workspace, _: &ToggleAuthStatus, cx| {+ workspace.toggle_modal(cx, |_workspace, cx| cx.add_view(|_cx| AuthModal {}))+ })}enum CopilotServer {@@ -62,7 +74,7 @@ pub enum Event {},}-#[derive(Debug)]+#[derive(Debug, PartialEq, Eq)]pub enum Status {Downloading,Error(Arc<str>),@@ -138,6 +150,7 @@ impl Copilot {})}).detach();+Self {server: CopilotServer::Downloading,}diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rsindex d64a1d2499a..98419d1f4cf 100644--- a/crates/theme/src/theme.rs+++ b/crates/theme/src/theme.rs@@ -23,6 +23,7 @@ pub struct Theme {pub context_menu: ContextMenu,pub contacts_popover: ContactsPopover,pub contact_list: ContactList,+ pub copilot: Copilot,pub contact_finder: ContactFinder,pub project_panel: ProjectPanel,pub command_palette: CommandPalette,@@ -115,6 +116,11 @@ pub struct AvatarStyle {pub outer_corner_radius: f32,}+#[derive(Deserialize, Default)]+pub struct Copilot {+ pub auth_modal: TextStyle,+}+#[derive(Deserialize, Default)]pub struct ContactsPopover {#[serde(flatten)]diff --git a/styles/src/styleTree/app.ts b/styles/src/styleTree/app.tsindex 423ce37d481..f3315aa7cd9 100644--- a/styles/src/styleTree/app.ts+++ b/styles/src/styleTree/app.ts@@ -21,6 +21,7 @@ import incomingCallNotification from "./incomingCallNotification"import { ColorScheme } from "../themes/common/colorScheme"import feedback from "./feedback"import welcome from "./welcome"+import copilot from "./copilot"export default function app(colorScheme: ColorScheme): Object {return {@@ -34,6 +35,7 @@ export default function app(colorScheme: ColorScheme): Object {incomingCallNotification: incomingCallNotification(colorScheme),picker: picker(colorScheme),workspace: workspace(colorScheme),+ copilot: copilot(colorScheme),welcome: welcome(colorScheme),contextMenu: contextMenu(colorScheme),editor: editor(colorScheme),diff --git a/styles/src/styleTree/copilot.ts b/styles/src/styleTree/copilot.tsnew file mode 100644index 00000000000..2c087da5a08--- /dev/null+++ b/styles/src/styleTree/copilot.ts@@ -0,0 +1,11 @@+import { ColorScheme } from "../themes/common/colorScheme"+import { text } from "./components";+++export default function copilot(colorScheme: ColorScheme) {+ let layer = colorScheme.highest;++ return {+ authModal: text(layer, "sans")+ }+}