🎨
This commit is contained in:
parent
59d9277a74
commit
8ba9e63ab8
1 changed files with 49 additions and 69 deletions
|
@ -18,29 +18,22 @@ use util::{
|
||||||
actions!(copilot, [SignIn, SignOut]);
|
actions!(copilot, [SignIn, SignOut]);
|
||||||
|
|
||||||
pub fn init(client: Arc<Client>, cx: &mut MutableAppContext) {
|
pub fn init(client: Arc<Client>, cx: &mut MutableAppContext) {
|
||||||
let (copilot, task) = Copilot::start(client.http_client(), cx);
|
let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), cx));
|
||||||
cx.set_global(copilot);
|
cx.set_global(copilot);
|
||||||
cx.spawn(|mut cx| async move {
|
cx.add_global_action(|_: &SignIn, cx: &mut MutableAppContext| {
|
||||||
task.await?;
|
if let Some(copilot) = Copilot::global(cx) {
|
||||||
cx.update(|cx| {
|
copilot
|
||||||
cx.add_global_action(|_: &SignIn, cx: &mut MutableAppContext| {
|
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
||||||
if let Some(copilot) = Copilot::global(cx) {
|
.detach_and_log_err(cx);
|
||||||
copilot
|
}
|
||||||
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
});
|
||||||
.detach_and_log_err(cx);
|
cx.add_global_action(|_: &SignOut, cx: &mut MutableAppContext| {
|
||||||
}
|
if let Some(copilot) = Copilot::global(cx) {
|
||||||
});
|
copilot
|
||||||
cx.add_global_action(|_: &SignOut, cx: &mut MutableAppContext| {
|
.update(cx, |copilot, cx| copilot.sign_out(cx))
|
||||||
if let Some(copilot) = Copilot::global(cx) {
|
.detach_and_log_err(cx);
|
||||||
copilot
|
}
|
||||||
.update(cx, |copilot, cx| copilot.sign_out(cx))
|
});
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
anyhow::Ok(())
|
|
||||||
})
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CopilotServer {
|
enum CopilotServer {
|
||||||
|
@ -83,55 +76,42 @@ impl Copilot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(
|
fn start(http: Arc<dyn HttpClient>, cx: &mut ModelContext<Self>) -> Self {
|
||||||
http: Arc<dyn HttpClient>,
|
cx.spawn(|this, mut cx| async move {
|
||||||
cx: &mut MutableAppContext,
|
let start_language_server = async {
|
||||||
) -> (ModelHandle<Self>, Task<Result<()>>) {
|
let server_path = get_lsp_binary(http).await?;
|
||||||
let this = cx.add_model(|_| Self {
|
let server =
|
||||||
server: CopilotServer::Downloading,
|
LanguageServer::new(0, &server_path, &["--stdio"], Path::new("/"), cx.clone())?;
|
||||||
});
|
let server = server.initialize(Default::default()).await?;
|
||||||
let task = cx.spawn({
|
let status = server
|
||||||
let this = this.clone();
|
.request::<request::CheckStatus>(request::CheckStatusParams {
|
||||||
|mut cx| async move {
|
local_checks_only: false,
|
||||||
let start_language_server = async {
|
})
|
||||||
let server_path = get_lsp_binary(http).await?;
|
.await?;
|
||||||
let server = LanguageServer::new(
|
anyhow::Ok((server, status))
|
||||||
0,
|
};
|
||||||
&server_path,
|
|
||||||
&["--stdio"],
|
|
||||||
Path::new("/"),
|
|
||||||
cx.clone(),
|
|
||||||
)?;
|
|
||||||
let server = server.initialize(Default::default()).await?;
|
|
||||||
let status = server
|
|
||||||
.request::<request::CheckStatus>(request::CheckStatusParams {
|
|
||||||
local_checks_only: false,
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
anyhow::Ok((server, status))
|
|
||||||
};
|
|
||||||
|
|
||||||
let server = start_language_server.await;
|
let server = start_language_server.await;
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
match server {
|
match server {
|
||||||
Ok((server, status)) => {
|
Ok((server, status)) => {
|
||||||
this.server = CopilotServer::Started {
|
this.server = CopilotServer::Started {
|
||||||
server,
|
server,
|
||||||
status: SignInStatus::SignedOut,
|
status: SignInStatus::SignedOut,
|
||||||
};
|
};
|
||||||
this.update_sign_in_status(status, cx);
|
this.update_sign_in_status(status, cx);
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
this.server = CopilotServer::Error(error.to_string());
|
|
||||||
Err(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
Err(error) => {
|
||||||
}
|
this.server = CopilotServer::Error(error.to_string());
|
||||||
});
|
}
|
||||||
(this, task)
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
Self {
|
||||||
|
server: CopilotServer::Downloading,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign_in(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
fn sign_in(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue