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:
parent
77d066200a
commit
bcf8a2f9fc
6 changed files with 1100 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -499,6 +499,7 @@ dependencies = [
|
||||||
"similar",
|
"similar",
|
||||||
"smol",
|
"smol",
|
||||||
"telemetry_events",
|
"telemetry_events",
|
||||||
|
"terminal",
|
||||||
"terminal_view",
|
"terminal_view",
|
||||||
"text",
|
"text",
|
||||||
"theme",
|
"theme",
|
||||||
|
|
|
@ -58,6 +58,7 @@ smol.workspace = true
|
||||||
telemetry_events.workspace = true
|
telemetry_events.workspace = true
|
||||||
terminal_view.workspace = true
|
terminal_view.workspace = true
|
||||||
text.workspace = true
|
text.workspace = true
|
||||||
|
terminal.workspace = true
|
||||||
theme.workspace = true
|
theme.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
time_format.workspace = true
|
time_format.workspace = true
|
||||||
|
|
|
@ -7,6 +7,7 @@ mod inline_assistant;
|
||||||
mod message_editor;
|
mod message_editor;
|
||||||
mod prompts;
|
mod prompts;
|
||||||
mod streaming_diff;
|
mod streaming_diff;
|
||||||
|
mod terminal_inline_assistant;
|
||||||
mod thread;
|
mod thread;
|
||||||
mod thread_history;
|
mod thread_history;
|
||||||
mod thread_store;
|
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(),
|
client.telemetry().clone(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
terminal_inline_assistant::init(
|
||||||
|
fs.clone(),
|
||||||
|
prompt_builder.clone(),
|
||||||
|
client.telemetry().clone(),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
feature_gate_assistant2_actions(cx);
|
feature_gate_assistant2_actions(cx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
assistant_settings::AssistantSettings,
|
assistant_settings::AssistantSettings,
|
||||||
prompts::PromptBuilder,
|
prompts::PromptBuilder,
|
||||||
streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff},
|
streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff},
|
||||||
|
terminal_inline_assistant::TerminalInlineAssistant,
|
||||||
CycleNextInlineAssist, CyclePreviousInlineAssist, ToggleInlineAssist,
|
CycleNextInlineAssist, CyclePreviousInlineAssist, ToggleInlineAssist,
|
||||||
};
|
};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
|
@ -207,16 +208,16 @@ impl InlineAssistant {
|
||||||
.map_or(false, |provider| provider.is_authenticated(cx))
|
.map_or(false, |provider| provider.is_authenticated(cx))
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle_assist = |cx: &mut ViewContext<Workspace>| {
|
let handle_assist = |cx: &mut ViewContext<Workspace>| match inline_assist_target {
|
||||||
match inline_assist_target {
|
InlineAssistTarget::Editor(active_editor) => {
|
||||||
InlineAssistTarget::Editor(active_editor) => {
|
InlineAssistant::update_global(cx, |assistant, cx| {
|
||||||
InlineAssistant::update_global(cx, |assistant, cx| {
|
assistant.assist(&active_editor, Some(cx.view().downgrade()), cx)
|
||||||
assistant.assist(&active_editor, Some(cx.view().downgrade()), cx)
|
})
|
||||||
})
|
}
|
||||||
}
|
InlineAssistTarget::Terminal(active_terminal) => {
|
||||||
InlineAssistTarget::Terminal(_active_terminal) => {
|
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
|
||||||
// TODO show the terminal inline assistant
|
assistant.assist(&active_terminal, Some(cx.view().downgrade()), cx)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -288,4 +288,25 @@ impl PromptBuilder {
|
||||||
};
|
};
|
||||||
self.handlebars.lock().render("content_prompt", &context)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1059
crates/assistant2/src/terminal_inline_assistant.rs
Normal file
1059
crates/assistant2/src/terminal_inline_assistant.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue