Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add configuration flow for inline assist button (#16369)

Mikayla Maki23d56a1a84c4
diff --git a/crates/assistant/src/assistant.rs b/crates/assistant/src/assistant.rs
index 7b26113ea95..7bb2284b394 100644
--- a/crates/assistant/src/assistant.rs
+++ b/crates/assistant/src/assistant.rs
@@ -59,7 +59,6 @@ actions!(
InsertIntoEditor,
ToggleFocus,
InsertActivePrompt,
- ShowConfiguration,
DeployHistory,
DeployPromptLibrary,
ConfirmCommand,
diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs
index b27f2f2b3a8..fea5e10bd97 100644
--- a/crates/assistant/src/assistant_panel.rs
+++ b/crates/assistant/src/assistant_panel.rs
@@ -16,7 +16,7 @@ use crate::{
QuoteSelection, RemoteContextMetadata, SavedContextMetadata, Split, ToggleFocus,
ToggleModelSelector, WorkflowStepResolution, WorkflowStepView,
};
-use crate::{ContextStoreEvent, ModelPickerDelegate, ShowConfiguration};
+use crate::{ContextStoreEvent, ModelPickerDelegate};
use anyhow::{anyhow, Result};
use assistant_slash_command::{SlashCommand, SlashCommandOutputSection};
use client::{proto, Client, Status};
@@ -77,7 +77,8 @@ use workspace::{
item::{self, FollowableItem, Item, ItemHandle},
pane::{self, SaveIntent},
searchable::{SearchEvent, SearchableItem},
- Pane, Save, ToggleZoom, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
+ Pane, Save, ShowConfiguration, ToggleZoom, ToolbarItemEvent, ToolbarItemLocation,
+ ToolbarItemView, Workspace,
};
use workspace::{searchable::SearchableItemHandle, NewFile};
@@ -704,7 +705,9 @@ impl AssistantPanel {
self.authenticate_provider_task = Some((
provider.id(),
cx.spawn(|this, mut cx| async move {
- let _ = load_credentials.await;
+ if let Some(future) = load_credentials {
+ let _ = future.await;
+ }
this.update(&mut cx, |this, _cx| {
this.authenticate_provider_task = None;
})
@@ -735,6 +738,7 @@ impl AssistantPanel {
};
let initial_prompt = action.prompt.clone();
+
if assistant_panel.update(cx, |assistant, cx| assistant.is_authenticated(cx)) {
match inline_assist_target {
InlineAssistTarget::Editor(active_editor, include_context) => {
@@ -763,9 +767,27 @@ impl AssistantPanel {
} else {
let assistant_panel = assistant_panel.downgrade();
cx.spawn(|workspace, mut cx| async move {
- assistant_panel
- .update(&mut cx, |assistant, cx| assistant.authenticate(cx))?
- .await?;
+ let Some(task) =
+ assistant_panel.update(&mut cx, |assistant, cx| assistant.authenticate(cx))?
+ else {
+ let answer = cx
+ .prompt(
+ gpui::PromptLevel::Warning,
+ "No language model provider configured",
+ None,
+ &["Configure", "Cancel"],
+ )
+ .await
+ .ok();
+ if let Some(answer) = answer {
+ if answer == 0 {
+ cx.update(|cx| cx.dispatch_action(Box::new(ShowConfiguration)))
+ .ok();
+ }
+ }
+ return Ok(());
+ };
+ task.await?;
if assistant_panel.update(&mut cx, |panel, cx| panel.is_authenticated(cx))? {
cx.update(|cx| match inline_assist_target {
InlineAssistTarget::Editor(active_editor, include_context) => {
@@ -1173,13 +1195,10 @@ impl AssistantPanel {
.map_or(false, |provider| provider.is_authenticated(cx))
}
- fn authenticate(&mut self, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
+ fn authenticate(&mut self, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> {
LanguageModelRegistry::read_global(cx)
.active_provider()
- .map_or(
- Task::ready(Err(anyhow!("no active language model provider"))),
- |provider| provider.authenticate(cx),
- )
+ .map_or(None, |provider| Some(provider.authenticate(cx)))
}
}
diff --git a/crates/assistant/src/model_selector.rs b/crates/assistant/src/model_selector.rs
index 957267c5dc4..e6c730685d6 100644
--- a/crates/assistant/src/model_selector.rs
+++ b/crates/assistant/src/model_selector.rs
@@ -1,15 +1,15 @@
use feature_flags::ZedPro;
+use gpui::Action;
use gpui::DismissEvent;
use language_model::{LanguageModel, LanguageModelAvailability, LanguageModelRegistry};
use proto::Plan;
+use workspace::ShowConfiguration;
use std::sync::Arc;
use ui::ListItemSpacing;
use crate::assistant_settings::AssistantSettings;
-use crate::ShowConfiguration;
use fs::Fs;
-use gpui::Action;
use gpui::SharedString;
use gpui::Task;
use picker::{Picker, PickerDelegate};
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 643473f7dcc..8da3ae929d1 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -115,6 +115,8 @@ lazy_static! {
#[derive(Clone, PartialEq)]
pub struct RemoveWorktreeFromProject(pub WorktreeId);
+actions!(assistant, [ShowConfiguration]);
+
actions!(
workspace,
[