Introduce staff-only inline completion provider (#21739)

Release Notes:

- N/A

---------

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Bennet <bennet@zed.dev>
Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-12-09 14:26:36 +01:00 committed by GitHub
parent 39e8944dcc
commit 77b8296fbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 2890 additions and 356 deletions

View file

@ -16,6 +16,7 @@ doctest = false
anyhow.workspace = true
copilot.workspace = true
editor.workspace = true
feature_flags.workspace = true
fs.workspace = true
gpui.workspace = true
language.workspace = true
@ -25,6 +26,7 @@ supermaven.workspace = true
ui.workspace = true
workspace.workspace = true
zed_actions.workspace = true
zeta.workspace = true
[dev-dependencies]
copilot = { workspace = true, features = ["test-support"] }

View file

@ -1,6 +1,7 @@
use anyhow::Result;
use copilot::{Copilot, Status};
use editor::{scroll::Autoscroll, Editor};
use feature_flags::FeatureFlagAppExt;
use fs::Fs;
use gpui::{
div, Action, AnchorCorner, AppContext, AsyncWindowContext, Entity, IntoElement, ParentElement,
@ -15,6 +16,7 @@ use language::{
use settings::{update_settings_file, Settings, SettingsStore};
use std::{path::Path, sync::Arc};
use supermaven::{AccountStatus, Supermaven};
use ui::{Button, LabelSize};
use workspace::{
create_and_open_local_file,
item::ItemHandle,
@ -25,6 +27,7 @@ use workspace::{
StatusItemView, Toast, Workspace,
};
use zed_actions::OpenBrowser;
use zeta::RateCompletionModal;
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
@ -36,6 +39,7 @@ pub struct InlineCompletionButton {
language: Option<Arc<Language>>,
file: Option<Arc<dyn File>>,
fs: Arc<dyn Fs>,
workspace: WeakView<Workspace>,
}
enum SupermavenButtonStatus {
@ -193,12 +197,35 @@ impl Render for InlineCompletionButton {
),
);
}
InlineCompletionProvider::Zeta => {
if !cx.is_staff() {
return div();
}
div().child(
Button::new("zeta", "Zeta")
.label_size(LabelSize::Small)
.on_click(cx.listener(|this, _, cx| {
if let Some(workspace) = this.workspace.upgrade() {
workspace.update(cx, |workspace, cx| {
RateCompletionModal::toggle(workspace, cx)
});
}
}))
.tooltip(|cx| Tooltip::text("Rate Completions", cx)),
)
}
}
}
}
impl InlineCompletionButton {
pub fn new(fs: Arc<dyn Fs>, cx: &mut ViewContext<Self>) -> Self {
pub fn new(
workspace: WeakView<Workspace>,
fs: Arc<dyn Fs>,
cx: &mut ViewContext<Self>,
) -> Self {
if let Some(copilot) = Copilot::global(cx) {
cx.observe(&copilot, |_, _, cx| cx.notify()).detach()
}
@ -211,6 +238,7 @@ impl InlineCompletionButton {
editor_enabled: None,
language: None,
file: None,
workspace,
fs,
}
}