Inline terminal assistant v2 (#21888)

Follow-up to https://github.com/zed-industries/zed/pull/21828 to add it
to the terminal as well.


https://github.com/user-attachments/assets/505d1443-4081-4dd8-9725-17d85532f52d

As with the previous PR, there's plenty of code duplication here; the
plan is to do more code sharing in separate PRs!


Release Notes:

- N/A
This commit is contained in:
Richard Feldman 2024-12-12 11:06:09 -05:00 committed by GitHub
parent 77d066200a
commit bcf8a2f9fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 1100 additions and 10 deletions

1
Cargo.lock generated
View file

@ -499,6 +499,7 @@ dependencies = [
"similar",
"smol",
"telemetry_events",
"terminal",
"terminal_view",
"text",
"theme",

View file

@ -58,6 +58,7 @@ smol.workspace = true
telemetry_events.workspace = true
terminal_view.workspace = true
text.workspace = true
terminal.workspace = true
theme.workspace = true
time.workspace = true
time_format.workspace = true

View file

@ -7,6 +7,7 @@ mod inline_assistant;
mod message_editor;
mod prompts;
mod streaming_diff;
mod terminal_inline_assistant;
mod thread;
mod thread_history;
mod thread_store;
@ -63,6 +64,12 @@ pub fn init(fs: Arc<dyn Fs>, client: Arc<Client>, stdout_is_a_pty: bool, cx: &mu
client.telemetry().clone(),
cx,
);
terminal_inline_assistant::init(
fs.clone(),
prompt_builder.clone(),
client.telemetry().clone(),
cx,
);
feature_gate_assistant2_actions(cx);
}

View file

@ -2,6 +2,7 @@ use crate::{
assistant_settings::AssistantSettings,
prompts::PromptBuilder,
streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff},
terminal_inline_assistant::TerminalInlineAssistant,
CycleNextInlineAssist, CyclePreviousInlineAssist, ToggleInlineAssist,
};
use anyhow::{Context as _, Result};
@ -207,16 +208,16 @@ impl InlineAssistant {
.map_or(false, |provider| provider.is_authenticated(cx))
};
let handle_assist = |cx: &mut ViewContext<Workspace>| {
match inline_assist_target {
InlineAssistTarget::Editor(active_editor) => {
InlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(&active_editor, Some(cx.view().downgrade()), cx)
})
}
InlineAssistTarget::Terminal(_active_terminal) => {
// TODO show the terminal inline assistant
}
let handle_assist = |cx: &mut ViewContext<Workspace>| match inline_assist_target {
InlineAssistTarget::Editor(active_editor) => {
InlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(&active_editor, Some(cx.view().downgrade()), cx)
})
}
InlineAssistTarget::Terminal(active_terminal) => {
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
assistant.assist(&active_terminal, Some(cx.view().downgrade()), cx)
})
}
};

View file

@ -288,4 +288,25 @@ impl PromptBuilder {
};
self.handlebars.lock().render("content_prompt", &context)
}
pub fn generate_terminal_assistant_prompt(
&self,
user_prompt: &str,
shell: Option<&str>,
working_directory: Option<&str>,
latest_output: &[String],
) -> Result<String, RenderError> {
let context = TerminalAssistantPromptContext {
os: std::env::consts::OS.to_string(),
arch: std::env::consts::ARCH.to_string(),
shell: shell.map(|s| s.to_string()),
working_directory: working_directory.map(|s| s.to_string()),
latest_output: latest_output.to_vec(),
user_prompt: user_prompt.to_string(),
};
self.handlebars
.lock()
.render("terminal_assistant_prompt", &context)
}
}

File diff suppressed because it is too large Load diff