Merge pull request #2395 from zed-industries/remove-stable-hiding-copilot

Remove stable guard for copilot
This commit is contained in:
Mikayla Maki 2023-04-21 04:04:04 +12:00 committed by GitHub
commit ad71020990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 51 deletions

View file

@ -27,8 +27,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use util::{ use util::{
channel::ReleaseChannel, fs::remove_matching, github::latest_github_release, http::HttpClient, fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt,
paths, ResultExt,
}; };
const COPILOT_AUTH_NAMESPACE: &'static str = "copilot_auth"; 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) { 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 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(http, node_runtime, cx)

View file

@ -23,51 +23,51 @@ struct OpenGithub;
const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot"; const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
pub fn init(cx: &mut AppContext) { 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; match &status {
cx.observe(&copilot, move |copilot, cx| { crate::Status::SigningIn { prompt } => {
let status = copilot.read(cx).status(); if let Some(code_verification_handle) = code_verification.as_mut() {
if cx.has_window(code_verification_handle.window_id()) {
match &status { code_verification_handle.update(cx, |code_verification_view, cx| {
crate::Status::SigningIn { prompt } => { code_verification_view.set_status(status, cx)
if let Some(code_verification_handle) = code_verification.as_mut() { });
if cx.has_window(code_verification_handle.window_id()) { cx.activate_window(code_verification_handle.window_id());
code_verification_handle.update(cx, |code_verification_view, cx| { } else {
code_verification_view.set_status(status, cx) create_copilot_auth_window(cx, &status, &mut code_verification);
}); }
cx.activate_window(code_verification_handle.window_id()); } else if let Some(_prompt) = prompt {
} else {
create_copilot_auth_window(cx, &status, &mut code_verification); create_copilot_auth_window(cx, &status, &mut code_verification);
} }
} else if let Some(_prompt) = prompt {
create_copilot_auth_window(cx, &status, &mut code_verification);
} }
} Status::Authorized | Status::Unauthorized => {
Status::Authorized | Status::Unauthorized => { if let Some(code_verification) = code_verification.as_ref() {
if let Some(code_verification) = code_verification.as_ref() { code_verification.update(cx, |code_verification, cx| {
code_verification.update(cx, |code_verification, cx| { code_verification.set_status(status, cx)
code_verification.set_status(status, cx) });
});
cx.platform().activate(true); cx.platform().activate(true);
cx.activate_window(code_verification.window_id()); cx.activate_window(code_verification.window_id());
}
}
_ => {
if let Some(code_verification) = code_verification.take() {
cx.remove_window(code_verification.window_id());
}
} }
} }
_ => { })
if let Some(code_verification) = code_verification.take() { .detach();
cx.remove_window(code_verification.window_id());
}
}
}
})
.detach();
cx.add_action( cx.add_action(
|code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| { |code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| {
code_verification.connect_clicked = true; code_verification.connect_clicked = true;
}, },
); );
}
} }
fn create_copilot_auth_window( fn create_copilot_auth_window(

View file

@ -4371,7 +4371,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
cx.set_state( cx.set_state(
&[ &[
"one ", // "one ", //
"twoˇ", // "twoˇ", //
"three ", // "three ", //
"four", // "four", //
] ]
@ -4446,7 +4446,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
&[ &[
"one", // "one", //
"", // "", //
"twoˇ", // "twoˇ", //
"", // "", //
"three", // "three", //
"four", // "four", //
@ -4461,7 +4461,7 @@ async fn test_strip_whitespace_and_format_via_lsp(cx: &mut gpui::TestAppContext)
cx.assert_editor_state( cx.assert_editor_state(
&[ &[
"one ", // "one ", //
"twoˇ", // "twoˇ", //
"three ", // "three ", //
"four", // "four", //
] ]