language_model: Remove dependency on inline_completion_button
(#20930)
This PR removes a dependency on the `inline_completion_button` crate from the `language_model` crate. We were taking on this dependency solely to call `initiate_sign_in`, which can easily be moved to the `copilot` crate. This allows `language_model` to move up in the crate dependency graph. Release Notes: - N/A
This commit is contained in:
parent
e31f44450e
commit
e076f55d78
9 changed files with 78 additions and 83 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -6076,7 +6076,6 @@ dependencies = [
|
||||||
"supermaven",
|
"supermaven",
|
||||||
"theme",
|
"theme",
|
||||||
"ui",
|
"ui",
|
||||||
"util",
|
|
||||||
"workspace",
|
"workspace",
|
||||||
"zed_actions",
|
"zed_actions",
|
||||||
]
|
]
|
||||||
|
@ -6521,7 +6520,6 @@ dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
"http_client",
|
"http_client",
|
||||||
"image",
|
"image",
|
||||||
"inline_completion_button",
|
|
||||||
"language",
|
"language",
|
||||||
"log",
|
"log",
|
||||||
"menu",
|
"menu",
|
||||||
|
@ -14356,11 +14354,11 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"client",
|
"client",
|
||||||
|
"copilot",
|
||||||
"db",
|
"db",
|
||||||
"editor",
|
"editor",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
"inline_completion_button",
|
|
||||||
"install_cli",
|
"install_cli",
|
||||||
"picker",
|
"picker",
|
||||||
"project",
|
"project",
|
||||||
|
|
|
@ -38,8 +38,8 @@ use std::{
|
||||||
};
|
};
|
||||||
use util::{fs::remove_matching, maybe, ResultExt};
|
use util::{fs::remove_matching, maybe, ResultExt};
|
||||||
|
|
||||||
pub use copilot_completion_provider::CopilotCompletionProvider;
|
pub use crate::copilot_completion_provider::CopilotCompletionProvider;
|
||||||
pub use sign_in::CopilotCodeVerification;
|
pub use crate::sign_in::{initiate_sign_in, CopilotCodeVerification};
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
copilot,
|
copilot,
|
||||||
|
|
|
@ -5,10 +5,79 @@ use gpui::{
|
||||||
Styled, Subscription, ViewContext,
|
Styled, Subscription, ViewContext,
|
||||||
};
|
};
|
||||||
use ui::{prelude::*, Button, Label, Vector, VectorName};
|
use ui::{prelude::*, Button, Label, Vector, VectorName};
|
||||||
use workspace::ModalView;
|
use util::ResultExt as _;
|
||||||
|
use workspace::notifications::NotificationId;
|
||||||
|
use workspace::{ModalView, Toast, Workspace};
|
||||||
|
|
||||||
const COPILOT_SIGN_UP_URL: &str = "https://github.com/features/copilot";
|
const COPILOT_SIGN_UP_URL: &str = "https://github.com/features/copilot";
|
||||||
|
|
||||||
|
struct CopilotStartingToast;
|
||||||
|
|
||||||
|
pub fn initiate_sign_in(cx: &mut WindowContext) {
|
||||||
|
let Some(copilot) = Copilot::global(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let status = copilot.read(cx).status();
|
||||||
|
let Some(workspace) = cx.window_handle().downcast::<Workspace>() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
match status {
|
||||||
|
Status::Starting { task } => {
|
||||||
|
let Some(workspace) = cx.window_handle().downcast::<Workspace>() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(workspace) = workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.show_toast(
|
||||||
|
Toast::new(
|
||||||
|
NotificationId::unique::<CopilotStartingToast>(),
|
||||||
|
"Copilot is starting...",
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
workspace.weak_handle()
|
||||||
|
}) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
cx.spawn(|mut cx| async move {
|
||||||
|
task.await;
|
||||||
|
if let Some(copilot) = cx.update(|cx| Copilot::global(cx)).ok().flatten() {
|
||||||
|
workspace
|
||||||
|
.update(&mut cx, |workspace, cx| match copilot.read(cx).status() {
|
||||||
|
Status::Authorized => workspace.show_toast(
|
||||||
|
Toast::new(
|
||||||
|
NotificationId::unique::<CopilotStartingToast>(),
|
||||||
|
"Copilot has started!",
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
),
|
||||||
|
_ => {
|
||||||
|
workspace.dismiss_toast(
|
||||||
|
&NotificationId::unique::<CopilotStartingToast>(),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
copilot
|
||||||
|
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
copilot.update(cx, |this, cx| this.sign_in(cx)).detach();
|
||||||
|
workspace
|
||||||
|
.update(cx, |this, cx| {
|
||||||
|
this.toggle_modal(cx, |cx| CopilotCodeVerification::new(&copilot, cx));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CopilotCodeVerification {
|
pub struct CopilotCodeVerification {
|
||||||
status: Status,
|
status: Status,
|
||||||
connect_clicked: bool,
|
connect_clicked: bool,
|
||||||
|
|
|
@ -23,7 +23,6 @@ paths.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
supermaven.workspace = true
|
supermaven.workspace = true
|
||||||
ui.workspace = true
|
ui.workspace = true
|
||||||
util.workspace = true
|
|
||||||
workspace.workspace = true
|
workspace.workspace = true
|
||||||
zed_actions.workspace = true
|
zed_actions.workspace = true
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use copilot::{Copilot, CopilotCodeVerification, Status};
|
use copilot::{Copilot, Status};
|
||||||
use editor::{scroll::Autoscroll, Editor};
|
use editor::{scroll::Autoscroll, Editor};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -15,7 +15,6 @@ use language::{
|
||||||
use settings::{update_settings_file, Settings, SettingsStore};
|
use settings::{update_settings_file, Settings, SettingsStore};
|
||||||
use std::{path::Path, sync::Arc};
|
use std::{path::Path, sync::Arc};
|
||||||
use supermaven::{AccountStatus, Supermaven};
|
use supermaven::{AccountStatus, Supermaven};
|
||||||
use util::ResultExt;
|
|
||||||
use workspace::{
|
use workspace::{
|
||||||
create_and_open_local_file,
|
create_and_open_local_file,
|
||||||
item::ItemHandle,
|
item::ItemHandle,
|
||||||
|
@ -29,8 +28,6 @@ use zed_actions::OpenBrowser;
|
||||||
|
|
||||||
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
|
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
|
||||||
|
|
||||||
struct CopilotStartingToast;
|
|
||||||
|
|
||||||
struct CopilotErrorToast;
|
struct CopilotErrorToast;
|
||||||
|
|
||||||
pub struct InlineCompletionButton {
|
pub struct InlineCompletionButton {
|
||||||
|
@ -221,7 +218,7 @@ impl InlineCompletionButton {
|
||||||
pub fn build_copilot_start_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
pub fn build_copilot_start_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
ContextMenu::build(cx, |menu, _| {
|
ContextMenu::build(cx, |menu, _| {
|
||||||
menu.entry("Sign In", None, initiate_sign_in)
|
menu.entry("Sign In", None, copilot::initiate_sign_in)
|
||||||
.entry("Disable Copilot", None, {
|
.entry("Disable Copilot", None, {
|
||||||
let fs = fs.clone();
|
let fs = fs.clone();
|
||||||
move |cx| hide_copilot(fs.clone(), cx)
|
move |cx| hide_copilot(fs.clone(), cx)
|
||||||
|
@ -484,68 +481,3 @@ fn hide_copilot(fs: Arc<dyn Fs>, cx: &mut AppContext) {
|
||||||
.inline_completion_provider = Some(InlineCompletionProvider::None);
|
.inline_completion_provider = Some(InlineCompletionProvider::None);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initiate_sign_in(cx: &mut WindowContext) {
|
|
||||||
let Some(copilot) = Copilot::global(cx) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let status = copilot.read(cx).status();
|
|
||||||
let Some(workspace) = cx.window_handle().downcast::<Workspace>() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
match status {
|
|
||||||
Status::Starting { task } => {
|
|
||||||
let Some(workspace) = cx.window_handle().downcast::<Workspace>() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let Ok(workspace) = workspace.update(cx, |workspace, cx| {
|
|
||||||
workspace.show_toast(
|
|
||||||
Toast::new(
|
|
||||||
NotificationId::unique::<CopilotStartingToast>(),
|
|
||||||
"Copilot is starting...",
|
|
||||||
),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
workspace.weak_handle()
|
|
||||||
}) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
cx.spawn(|mut cx| async move {
|
|
||||||
task.await;
|
|
||||||
if let Some(copilot) = cx.update(|cx| Copilot::global(cx)).ok().flatten() {
|
|
||||||
workspace
|
|
||||||
.update(&mut cx, |workspace, cx| match copilot.read(cx).status() {
|
|
||||||
Status::Authorized => workspace.show_toast(
|
|
||||||
Toast::new(
|
|
||||||
NotificationId::unique::<CopilotStartingToast>(),
|
|
||||||
"Copilot has started!",
|
|
||||||
),
|
|
||||||
cx,
|
|
||||||
),
|
|
||||||
_ => {
|
|
||||||
workspace.dismiss_toast(
|
|
||||||
&NotificationId::unique::<CopilotStartingToast>(),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
copilot
|
|
||||||
.update(cx, |copilot, cx| copilot.sign_in(cx))
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.log_err();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
copilot.update(cx, |this, cx| this.sign_in(cx)).detach();
|
|
||||||
workspace
|
|
||||||
.update(cx, |this, cx| {
|
|
||||||
this.toggle_modal(cx, |cx| CopilotCodeVerification::new(&copilot, cx));
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ futures.workspace = true
|
||||||
google_ai = { workspace = true, features = ["schemars"] }
|
google_ai = { workspace = true, features = ["schemars"] }
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
http_client.workspace = true
|
http_client.workspace = true
|
||||||
inline_completion_button.workspace = true
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
menu.workspace = true
|
menu.workspace = true
|
||||||
ollama = { workspace = true, features = ["schemars"] }
|
ollama = { workspace = true, features = ["schemars"] }
|
||||||
|
|
|
@ -383,9 +383,7 @@ impl Render for ConfigurationView {
|
||||||
.icon_size(IconSize::Medium)
|
.icon_size(IconSize::Medium)
|
||||||
.style(ui::ButtonStyle::Filled)
|
.style(ui::ButtonStyle::Filled)
|
||||||
.full_width()
|
.full_width()
|
||||||
.on_click(|_, cx| {
|
.on_click(|_, cx| copilot::initiate_sign_in(cx)),
|
||||||
inline_completion_button::initiate_sign_in(cx)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div().flex().w_full().items_center().child(
|
div().flex().w_full().items_center().child(
|
||||||
|
|
|
@ -17,10 +17,10 @@ test-support = []
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
client.workspace = true
|
client.workspace = true
|
||||||
|
copilot.workspace = true
|
||||||
db.workspace = true
|
db.workspace = true
|
||||||
fuzzy.workspace = true
|
fuzzy.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
inline_completion_button.workspace = true
|
|
||||||
install_cli.workspace = true
|
install_cli.workspace = true
|
||||||
picker.workspace = true
|
picker.workspace = true
|
||||||
project.workspace = true
|
project.workspace = true
|
||||||
|
|
|
@ -177,7 +177,7 @@ impl Render for WelcomePage {
|
||||||
this.telemetry.report_app_event(
|
this.telemetry.report_app_event(
|
||||||
"welcome page: sign in to copilot".to_string(),
|
"welcome page: sign in to copilot".to_string(),
|
||||||
);
|
);
|
||||||
inline_completion_button::initiate_sign_in(cx);
|
copilot::initiate_sign_in(cx);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue