Merge branch 'main' into window_context_2
This commit is contained in:
commit
c76b9794e4
45 changed files with 1760 additions and 882 deletions
|
@ -14,7 +14,7 @@ use language::{
|
|||
ToPointUtf16,
|
||||
};
|
||||
use log::{debug, error};
|
||||
use lsp::LanguageServer;
|
||||
use lsp::{LanguageServer, LanguageServerId};
|
||||
use node_runtime::NodeRuntime;
|
||||
use request::{LogMessage, StatusNotification};
|
||||
use settings::Settings;
|
||||
|
@ -27,8 +27,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
use util::{
|
||||
channel::ReleaseChannel, fs::remove_matching, github::latest_github_release, http::HttpClient,
|
||||
paths, ResultExt,
|
||||
fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt,
|
||||
};
|
||||
|
||||
const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth";
|
||||
|
@ -41,15 +40,6 @@ actions!(
|
|||
);
|
||||
|
||||
pub fn init(http: Arc<dyn HttpClient>, node_runtime: Arc<NodeRuntime>, cx: &mut AppContext) {
|
||||
// Disable Copilot for stable releases.
|
||||
if *cx.global::<ReleaseChannel>() == ReleaseChannel::Stable {
|
||||
cx.update_global::<collections::CommandPaletteFilter, _, _>(|filter, _cx| {
|
||||
filter.filtered_namespaces.insert(COPILOT_NAMESPACE);
|
||||
filter.filtered_namespaces.insert(COPILOT_AUTH_NAMESPACE);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let copilot = cx.add_model({
|
||||
let node_runtime = node_runtime.clone();
|
||||
move |cx| Copilot::start(http, node_runtime, cx)
|
||||
|
@ -380,7 +370,7 @@ impl Copilot {
|
|||
let node_path = node_runtime.binary_path().await?;
|
||||
let arguments: &[OsString] = &[server_path.into(), "--stdio".into()];
|
||||
let server = LanguageServer::new(
|
||||
0,
|
||||
LanguageServerId(0),
|
||||
&node_path,
|
||||
arguments,
|
||||
Path::new("/"),
|
||||
|
|
|
@ -24,55 +24,57 @@ struct OpenGithub;
|
|||
const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
let copilot = Copilot::global(cx).unwrap();
|
||||
if let Some(copilot) = Copilot::global(cx) {
|
||||
let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
|
||||
cx.observe(&copilot, move |copilot, cx| {
|
||||
let status = copilot.read(cx).status();
|
||||
|
||||
let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
|
||||
cx.observe(&copilot, move |copilot, cx| {
|
||||
let status = copilot.read(cx).status();
|
||||
|
||||
match &status {
|
||||
crate::Status::SigningIn { prompt } => {
|
||||
if let Some(code_verification) = code_verification.as_mut() {
|
||||
if cx.has_window(code_verification.window_id()) {
|
||||
cx.update_window(code_verification.window_id(), |cx| {
|
||||
code_verification.update(cx, |code_verification_view, cx| {
|
||||
code_verification_view.set_status(status, cx);
|
||||
match &status {
|
||||
crate::Status::SigningIn { prompt } => {
|
||||
if let Some(code_verification_handle) = code_verification.as_mut() {
|
||||
let window_id = code_verification_handle.window_id();
|
||||
if cx.has_window(window_id) {
|
||||
cx.update_window(window_id, |cx| {
|
||||
code_verification_handle.update(cx, |code_verification, cx| {
|
||||
code_verification.set_status(status, cx)
|
||||
});
|
||||
cx.activate_window();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
*code_verification = create_copilot_auth_window(cx, &status);
|
||||
} else {
|
||||
code_verification = Some(create_copilot_auth_window(cx, &status));
|
||||
}
|
||||
} else if let Some(_prompt) = prompt {
|
||||
code_verification = Some(create_copilot_auth_window(cx, &status));
|
||||
}
|
||||
} else if let Some(_prompt) = prompt {
|
||||
code_verification = Some(create_copilot_auth_window(cx, &status));
|
||||
}
|
||||
}
|
||||
Status::Authorized | Status::Unauthorized => {
|
||||
if let Some(code_verification) = code_verification.as_ref() {
|
||||
cx.update_window(code_verification.window_id(), |cx| {
|
||||
code_verification.update(cx, |code_verification, cx| {
|
||||
code_verification.set_status(status, cx);
|
||||
Status::Authorized | Status::Unauthorized => {
|
||||
if let Some(code_verification) = code_verification.as_ref() {
|
||||
let window_id = code_verification.window_id();
|
||||
cx.update_window(window_id, |cx| {
|
||||
code_verification.update(cx, |code_verification, cx| {
|
||||
code_verification.set_status(status, cx)
|
||||
});
|
||||
|
||||
cx.platform().activate(true);
|
||||
cx.activate_window();
|
||||
});
|
||||
|
||||
cx.platform().activate(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if let Some(code_verification) = code_verification.take() {
|
||||
cx.remove_window(code_verification.window_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if let Some(code_verification) = code_verification.take() {
|
||||
cx.remove_window(code_verification.window_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
.detach();
|
||||
|
||||
cx.add_action(
|
||||
|code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| {
|
||||
code_verification.connect_clicked = true;
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
|code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| {
|
||||
code_verification.connect_clicked = true;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_copilot_auth_window(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue