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:
parent
81dd68d696
commit
cb35b73020
7 changed files with 1224 additions and 1148 deletions
|
@ -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);
|
||||
|
|
|
@ -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
Loading…
Add table
Add a link
Reference in a new issue