Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Init copilot with client instead of http client
Joseph Lyonsa7fc07a8cd62
diff --git a/Cargo.lock b/Cargo.lockindex e009cfd3426..2af1a4aa368 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.tomlindex bac335f7b7f..1a6ec7968d0 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.rsindex 07c54c77857..f1b547a182f 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<dyn HttpClient>, node_runtime: Arc<NodeRuntime>, cx: &mut AppContext) {+pub fn init(client: &Client, node_runtime: Arc<NodeRuntime>, 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())- }- Event::CompletionsDiscarded { uuids, file_type } => {- for uuid in uuids {- // Build event object and pass it in- // telemetry.report_clickhouse_event(event, settings.telemetry())- }+ let telemetry_settings = cx.global::<Settings>().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);}- };+ }}).detach();diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex f498078b520..434234f7f64 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::<Settings>().telemetry(),);+ copilot::init(&client, node_runtime, cx);+let app_state = Arc::new(AppState {languages,themes,