Dedupe PromptBuilder construction (#23496)

This PR dedupes the construction of the `PromptBuilder`.

Previously this was constructed by both `assistant` and `assistant2`,
but now we construct it outside and pass it in.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-22 17:17:36 -05:00 committed by GitHub
parent aad04e078a
commit 51fcb710d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 35 deletions

View file

@ -2,7 +2,7 @@ use anyhow::Result;
use assets::Assets;
use fs::Fs;
use futures::StreamExt;
use gpui::AssetSource;
use gpui::{AppContext, AssetSource};
use handlebars::{Handlebars, RenderError};
use language::{BufferSnapshot, LanguageName, Point};
use parking_lot::Mutex;
@ -56,6 +56,19 @@ pub struct PromptBuilder {
}
impl PromptBuilder {
pub fn load(fs: Arc<dyn Fs>, stdout_is_a_pty: bool, cx: &mut AppContext) -> Arc<Self> {
Self::new(Some(PromptLoadingParams {
fs: fs.clone(),
repo_path: stdout_is_a_pty
.then(|| std::env::current_dir().log_err())
.flatten(),
cx,
}))
.log_err()
.map(Arc::new)
.unwrap_or_else(|| Arc::new(Self::new(None).unwrap()))
}
pub fn new(loading_params: Option<PromptLoadingParams>) -> Result<Self> {
let mut handlebars = Handlebars::new();
Self::register_built_in_templates(&mut handlebars)?;