Refactor staff mode into a seperate crate and make copilot initialization wait for the staff mode flag to be flipped
This commit is contained in:
parent
1627cf7eae
commit
6bfecd7f66
14 changed files with 100 additions and 32 deletions
|
@ -15,6 +15,7 @@ gpui = { path = "../gpui" }
|
|||
language = { path = "../language" }
|
||||
settings = { path = "../settings" }
|
||||
theme = { path = "../theme" }
|
||||
staff_mode = { path = "../staff_mode" }
|
||||
lsp = { path = "../lsp" }
|
||||
node_runtime = { path = "../node_runtime"}
|
||||
util = { path = "../util" }
|
||||
|
|
|
@ -18,6 +18,8 @@ use node_runtime::NodeRuntime;
|
|||
use request::{LogMessage, StatusNotification};
|
||||
use settings::Settings;
|
||||
use smol::{fs, io::BufReader, stream::StreamExt};
|
||||
use staff_mode::staff_mode;
|
||||
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
ops::Range,
|
||||
|
@ -35,28 +37,46 @@ const COPILOT_NAMESPACE: &'static str = "copilot";
|
|||
actions!(copilot, [NextSuggestion, PreviousSuggestion, Reinstall]);
|
||||
|
||||
pub fn init(client: Arc<Client>, node_runtime: Arc<NodeRuntime>, cx: &mut MutableAppContext) {
|
||||
let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), node_runtime, cx));
|
||||
cx.set_global(copilot.clone());
|
||||
staff_mode(cx, {
|
||||
move |cx| {
|
||||
let copilot = cx.add_model({
|
||||
let node_runtime = node_runtime.clone();
|
||||
let http = client.http_client().clone();
|
||||
move |cx| Copilot::start(http, node_runtime, cx)
|
||||
});
|
||||
cx.set_global(copilot.clone());
|
||||
|
||||
observe_namespaces(cx, copilot);
|
||||
|
||||
sign_in::init(cx);
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_global_action(|_: &SignIn, cx| {
|
||||
let copilot = Copilot::global(cx).unwrap();
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
||||
.detach_and_log_err(cx);
|
||||
if let Some(copilot) = Copilot::global(cx) {
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
cx.add_global_action(|_: &SignOut, cx| {
|
||||
let copilot = Copilot::global(cx).unwrap();
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.sign_out(cx))
|
||||
.detach_and_log_err(cx);
|
||||
if let Some(copilot) = Copilot::global(cx) {
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.sign_out(cx))
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_global_action(|_: &Reinstall, cx| {
|
||||
let copilot = Copilot::global(cx).unwrap();
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.reinstall(cx))
|
||||
.detach();
|
||||
if let Some(copilot) = Copilot::global(cx) {
|
||||
copilot
|
||||
.update(cx, |copilot, cx| copilot.reinstall(cx))
|
||||
.detach();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn observe_namespaces(cx: &mut MutableAppContext, copilot: ModelHandle<Copilot>) {
|
||||
cx.observe(&copilot, |handle, cx| {
|
||||
let status = handle.read(cx).status();
|
||||
cx.update_global::<collections::CommandPaletteFilter, _, _>(
|
||||
|
@ -77,8 +97,6 @@ pub fn init(client: Arc<Client>, node_runtime: Arc<NodeRuntime>, cx: &mut Mutabl
|
|||
);
|
||||
})
|
||||
.detach();
|
||||
|
||||
sign_in::init(cx);
|
||||
}
|
||||
|
||||
enum CopilotServer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue