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:
parent
aad04e078a
commit
51fcb710d7
5 changed files with 36 additions and 35 deletions
|
@ -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)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue