Extract PromptLibrary to prompt_library (#23285)

This PR extracts the `PromptLibrary` out of the `assistant` crate and
moves it to the `prompt_library` crate.

The `PromptLibrary` is now decoupled from the specifics of the
`AssistantPanel` and `InlineAssistant`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-17 10:28:27 -05:00 committed by GitHub
parent 81dd68d696
commit cb35b73020
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1224 additions and 1148 deletions

11
Cargo.lock generated
View file

@ -413,7 +413,6 @@ dependencies = [
"proto",
"rand 0.8.5",
"regex",
"release_channel",
"rope",
"rpc",
"schemars",
@ -9892,6 +9891,7 @@ dependencies = [
"assets",
"chrono",
"collections",
"editor",
"fs",
"futures 0.3.31",
"fuzzy",
@ -9899,14 +9899,23 @@ dependencies = [
"handlebars 4.5.0",
"heed",
"language",
"language_model",
"log",
"menu",
"parking_lot",
"paths",
"picker",
"release_channel",
"rope",
"serde",
"settings",
"text",
"theme",
"ui",
"util",
"uuid",
"workspace",
"zed_actions",
]
[[package]]

View file

@ -58,7 +58,6 @@ project.workspace = true
prompt_library.workspace = true
proto.workspace = true
regex.workspace = true
release_channel.workspace = true
rope.workspace = true
rpc.workspace = true
schemars.workspace = true

View file

@ -5,7 +5,6 @@ mod context;
pub mod context_store;
mod inline_assistant;
mod patch;
mod prompt_library;
mod slash_command;
pub(crate) mod slash_command_picker;
pub mod slash_command_settings;
@ -14,7 +13,6 @@ mod terminal_inline_assistant;
use std::path::PathBuf;
use std::sync::Arc;
use ::prompt_library::{PromptBuilder, PromptLoadingParams};
use assistant_settings::AssistantSettings;
use assistant_slash_command::SlashCommandRegistry;
use assistant_slash_commands::{ProjectSlashCommandFeatureFlag, SearchSlashCommandFeatureFlag};
@ -27,6 +25,7 @@ use gpui::{actions, AppContext, Global, SharedString, UpdateGlobal};
use language_model::{
LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage,
};
use prompt_library::{PromptBuilder, PromptLoadingParams};
use semantic_index::{CloudEmbeddingProvider, SemanticDb};
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore};
@ -214,7 +213,7 @@ pub fn init(
.detach();
context_store::init(&client.clone().into());
::prompt_library::init(cx);
prompt_library::init(cx);
init_language_model_settings(cx);
assistant_slash_command::init(cx);
assistant_tool::init(cx);

View file

@ -1,6 +1,5 @@
use crate::{
humanize_token_count, prompt_library::open_prompt_library,
slash_command::SlashCommandCompletionProvider, slash_command_picker,
humanize_token_count, slash_command::SlashCommandCompletionProvider, slash_command_picker,
terminal_inline_assistant::TerminalInlineAssistant, Assist, AssistantPatch,
AssistantPatchStatus, CacheStatus, ConfirmCommand, Content, Context, ContextEvent, ContextId,
ContextStore, ContextStoreEvent, CopyCode, CycleMessageRole, DeployHistory,
@ -55,7 +54,7 @@ use multi_buffer::MultiBufferRow;
use picker::{Picker, PickerDelegate};
use project::lsp_store::LocalLspAdapterDelegate;
use project::{Project, Worktree};
use prompt_library::PromptBuilder;
use prompt_library::{open_prompt_library, PromptBuilder, PromptLibrary};
use rope::Point;
use search::{buffer_search::DivRegistrar, BufferSearchBar};
use serde::{Deserialize, Serialize};
@ -1186,7 +1185,19 @@ impl AssistantPanel {
}
fn deploy_prompt_library(&mut self, _: &DeployPromptLibrary, cx: &mut ViewContext<Self>) {
open_prompt_library(self.languages.clone(), cx).detach_and_log_err(cx);
open_prompt_library(
self.languages.clone(),
Box::new(PromptLibraryInlineAssist),
Arc::new(|| {
Box::new(SlashCommandCompletionProvider::new(
Arc::new(SlashCommandWorkingSet::default()),
None,
None,
))
}),
cx,
)
.detach_and_log_err(cx);
}
fn toggle_model_selector(&mut self, _: &ToggleModelSelector, cx: &mut ViewContext<Self>) {
@ -1469,6 +1480,29 @@ impl FocusableView for AssistantPanel {
}
}
struct PromptLibraryInlineAssist;
impl prompt_library::InlineAssistDelegate for PromptLibraryInlineAssist {
fn assist(
&self,
prompt_editor: &View<Editor>,
initial_prompt: Option<String>,
cx: &mut ViewContext<PromptLibrary>,
) {
InlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(&prompt_editor, None, None, initial_prompt, cx)
})
}
fn focus_assistant_panel(
&self,
workspace: &mut Workspace,
cx: &mut ViewContext<Workspace>,
) -> bool {
workspace.focus_panel::<AssistantPanel>(cx).is_some()
}
}
pub enum ContextEditorEvent {
Edited,
TabContentChanged,

File diff suppressed because it is too large Load diff

View file

@ -16,6 +16,7 @@ anyhow.workspace = true
assets.workspace = true
chrono.workspace = true
collections.workspace = true
editor.workspace = true
fs.workspace = true
futures.workspace = true
fuzzy.workspace = true
@ -23,11 +24,20 @@ gpui.workspace = true
handlebars.workspace = true
heed.workspace = true
language.workspace = true
language_model.workspace = true
log.workspace = true
menu.workspace = true
parking_lot.workspace = true
paths.workspace = true
picker.workspace = true
release_channel.workspace = true
rope.workspace = true
serde.workspace = true
settings.workspace = true
text.workspace = true
theme.workspace = true
ui.workspace = true
util.workspace = true
uuid.workspace = true
workspace.workspace = true
zed_actions.workspace = true

File diff suppressed because it is too large Load diff