From a7fc07a8cd62570f9f44bbad1fa4bcaeb97548cf Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 16 May 2023 03:12:39 -0400 Subject: [PATCH] Init copilot with client instead of http client --- Cargo.lock | 1 + crates/copilot/Cargo.toml | 1 + crates/copilot/src/copilot.rs | 38 ++++++++++++++++++++++------------- crates/zed/src/main.rs | 3 ++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e009cfd342..2af1a4aa36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1338,6 +1338,7 @@ dependencies = [ "anyhow", "async-compression", "async-tar", + "client", "clock", "collections", "context_menu", diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index bac335f7b7..1a6ec7968d 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -22,6 +22,7 @@ test-support = [ collections = { path = "../collections" } context_menu = { path = "../context_menu" } gpui = { path = "../gpui" } +client = { path = "../client" } language = { path = "../language" } settings = { path = "../settings" } theme = { path = "../theme" } diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 07c54c7785..f1b547a182 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -4,6 +4,7 @@ mod sign_in; use anyhow::{anyhow, Context, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; +use client::{ClickhouseEvent, Client}; use collections::HashMap; use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt}; use gpui::{ @@ -40,26 +41,35 @@ actions!( [Suggest, NextSuggestion, PreviousSuggestion, Reinstall] ); -pub fn init(http: Arc, node_runtime: Arc, cx: &mut AppContext) { +pub fn init(client: &Client, node_runtime: Arc, cx: &mut AppContext) { let copilot = cx.add_model({ let node_runtime = node_runtime.clone(); - move |cx| Copilot::start(http, node_runtime, cx) + move |cx| Copilot::start(client.http_client(), node_runtime, cx) }); cx.set_global(copilot.clone()); - cx.subscribe(&copilot, |_, event, _| { - match event { - Event::CompletionAccepted { uuid, file_type } => { - // Build event object and pass it in - // telemetry.report_clickhouse_event(event, settings.telemetry()) + let telemetry_settings = cx.global::().telemetry(); + let telemetry = client.telemetry(); + + cx.subscribe(&copilot, move |_, event, _| match event { + Event::CompletionAccepted { uuid, file_type } => { + let event = ClickhouseEvent::Copilot { + suggestion_id: uuid.clone(), + suggestion_accepted: true, + file_extension: file_type.clone().map(|a| a.to_string()), + }; + telemetry.report_clickhouse_event(event, telemetry_settings); + } + Event::CompletionsDiscarded { uuids, file_type } => { + for uuid in uuids { + let event = ClickhouseEvent::Copilot { + suggestion_id: uuid.clone(), + suggestion_accepted: false, + file_extension: file_type.clone().map(|a| a.to_string()), + }; + telemetry.report_clickhouse_event(event, telemetry_settings); } - Event::CompletionsDiscarded { uuids, file_type } => { - for uuid in uuids { - // Build event object and pass it in - // telemetry.report_clickhouse_event(event, settings.telemetry()) - } - } - }; + } }) .detach(); diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index f498078b52..434234f7f6 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -178,7 +178,6 @@ fn main() { vim::init(cx); terminal_view::init(cx); theme_testbench::init(cx); - copilot::init(http.clone(), node_runtime, cx); cx.spawn(|cx| watch_themes(fs.clone(), themes.clone(), cx)) .detach(); @@ -197,6 +196,8 @@ fn main() { cx.global::().telemetry(), ); + copilot::init(&client, node_runtime, cx); + let app_state = Arc::new(AppState { languages, themes,