Init copilot with client instead of http client
This commit is contained in:
parent
f50afefed3
commit
a7fc07a8cd
4 changed files with 28 additions and 15 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1338,6 +1338,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"async-compression",
|
||||
"async-tar",
|
||||
"client",
|
||||
"clock",
|
||||
"collections",
|
||||
"context_menu",
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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 {
|
||||
let telemetry_settings = cx.global::<Settings>().telemetry();
|
||||
let telemetry = client.telemetry();
|
||||
|
||||
cx.subscribe(&copilot, move |_, event, _| match event {
|
||||
Event::CompletionAccepted { uuid, file_type } => {
|
||||
// Build event object and pass it in
|
||||
// telemetry.report_clickhouse_event(event, settings.telemetry())
|
||||
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 {
|
||||
// Build event object and pass it in
|
||||
// telemetry.report_clickhouse_event(event, settings.telemetry())
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue