Init copilot with client instead of http client

This commit is contained in:
Joseph Lyons 2023-05-16 03:12:39 -04:00
parent f50afefed3
commit a7fc07a8cd
4 changed files with 28 additions and 15 deletions

1
Cargo.lock generated
View file

@ -1338,6 +1338,7 @@ dependencies = [
"anyhow", "anyhow",
"async-compression", "async-compression",
"async-tar", "async-tar",
"client",
"clock", "clock",
"collections", "collections",
"context_menu", "context_menu",

View file

@ -22,6 +22,7 @@ test-support = [
collections = { path = "../collections" } collections = { path = "../collections" }
context_menu = { path = "../context_menu" } context_menu = { path = "../context_menu" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
client = { path = "../client" }
language = { path = "../language" } language = { path = "../language" }
settings = { path = "../settings" } settings = { path = "../settings" }
theme = { path = "../theme" } theme = { path = "../theme" }

View file

@ -4,6 +4,7 @@ mod sign_in;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use async_compression::futures::bufread::GzipDecoder; use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive; use async_tar::Archive;
use client::{ClickhouseEvent, Client};
use collections::HashMap; use collections::HashMap;
use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt}; use futures::{channel::oneshot, future::Shared, Future, FutureExt, TryFutureExt};
use gpui::{ use gpui::{
@ -40,26 +41,35 @@ actions!(
[Suggest, NextSuggestion, PreviousSuggestion, Reinstall] [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 copilot = cx.add_model({
let node_runtime = node_runtime.clone(); 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.set_global(copilot.clone());
cx.subscribe(&copilot, |_, event, _| { let telemetry_settings = cx.global::<Settings>().telemetry();
match event { let telemetry = client.telemetry();
cx.subscribe(&copilot, move |_, event, _| match event {
Event::CompletionAccepted { uuid, file_type } => { Event::CompletionAccepted { uuid, file_type } => {
// Build event object and pass it in let event = ClickhouseEvent::Copilot {
// telemetry.report_clickhouse_event(event, settings.telemetry()) 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 } => { Event::CompletionsDiscarded { uuids, file_type } => {
for uuid in uuids { for uuid in uuids {
// Build event object and pass it in let event = ClickhouseEvent::Copilot {
// telemetry.report_clickhouse_event(event, settings.telemetry()) 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(); .detach();

View file

@ -178,7 +178,6 @@ fn main() {
vim::init(cx); vim::init(cx);
terminal_view::init(cx); terminal_view::init(cx);
theme_testbench::init(cx); theme_testbench::init(cx);
copilot::init(http.clone(), node_runtime, cx);
cx.spawn(|cx| watch_themes(fs.clone(), themes.clone(), cx)) cx.spawn(|cx| watch_themes(fs.clone(), themes.clone(), cx))
.detach(); .detach();
@ -197,6 +196,8 @@ fn main() {
cx.global::<Settings>().telemetry(), cx.global::<Settings>().telemetry(),
); );
copilot::init(&client, node_runtime, cx);
let app_state = Arc::new(AppState { let app_state = Arc::new(AppState {
languages, languages,
themes, themes,