agent: Improve attached context display and show hovers for symbol / selection / rules / thread (#29551)
* Brings back hover popover of selection context. * Adds hover popover for symbol, rules, and thread context. * Makes context attached to messages display the names / content at attachment time. * Adds the file name as the displayed parent of symbol context. * Brings back `impl Component for AddedContext` Release Notes: - N/A --------- Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
This commit is contained in:
parent
8afac388bb
commit
abb48b7711
5 changed files with 946 additions and 556 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::context::{AgentContext, RULES_ICON};
|
||||
use crate::context::{AgentContextHandle, RULES_ICON};
|
||||
use crate::context_picker::MentionLink;
|
||||
use crate::thread::{
|
||||
LastRestoreCheckpoint, MessageId, MessageSegment, Thread, ThreadError, ThreadEvent,
|
||||
|
@ -1491,19 +1491,13 @@ impl ActiveThread {
|
|||
|
||||
let workspace = self.workspace.clone();
|
||||
let thread = self.thread.read(cx);
|
||||
let prompt_store = self.thread_store.read(cx).prompt_store().as_ref();
|
||||
|
||||
// Get all the data we need from thread before we start using it in closures
|
||||
let checkpoint = thread.checkpoint_for_message(message_id);
|
||||
let added_context = if let Some(workspace) = workspace.upgrade() {
|
||||
let project = workspace.read(cx).project().read(cx);
|
||||
thread
|
||||
.context_for_message(message_id)
|
||||
.flat_map(|context| AddedContext::new(context.clone(), prompt_store, project, cx))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
return Empty.into_any();
|
||||
};
|
||||
let added_context = thread
|
||||
.context_for_message(message_id)
|
||||
.map(|context| AddedContext::new_attached(context, cx))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let tool_uses = thread.tool_uses_for_message(message_id, cx);
|
||||
let has_tool_uses = !tool_uses.is_empty();
|
||||
|
@ -1713,7 +1707,7 @@ impl ActiveThread {
|
|||
.when(!added_context.is_empty(), |parent| {
|
||||
parent.child(h_flex().flex_wrap().gap_1().children(
|
||||
added_context.into_iter().map(|added_context| {
|
||||
let context = added_context.context.clone();
|
||||
let context = added_context.handle.clone();
|
||||
ContextPill::added(added_context, false, false, None).on_click(Rc::new(
|
||||
cx.listener({
|
||||
let workspace = workspace.clone();
|
||||
|
@ -3188,13 +3182,13 @@ impl Render for ActiveThread {
|
|||
}
|
||||
|
||||
pub(crate) fn open_context(
|
||||
context: &AgentContext,
|
||||
context: &AgentContextHandle,
|
||||
workspace: Entity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
match context {
|
||||
AgentContext::File(file_context) => {
|
||||
AgentContextHandle::File(file_context) => {
|
||||
if let Some(project_path) = file_context.project_path(cx) {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace
|
||||
|
@ -3204,7 +3198,7 @@ pub(crate) fn open_context(
|
|||
}
|
||||
}
|
||||
|
||||
AgentContext::Directory(directory_context) => {
|
||||
AgentContextHandle::Directory(directory_context) => {
|
||||
let entry_id = directory_context.entry_id;
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.project().update(cx, |_project, cx| {
|
||||
|
@ -3213,7 +3207,7 @@ pub(crate) fn open_context(
|
|||
})
|
||||
}
|
||||
|
||||
AgentContext::Symbol(symbol_context) => {
|
||||
AgentContextHandle::Symbol(symbol_context) => {
|
||||
let buffer = symbol_context.buffer.read(cx);
|
||||
if let Some(project_path) = buffer.project_path(cx) {
|
||||
let snapshot = buffer.snapshot();
|
||||
|
@ -3223,7 +3217,7 @@ pub(crate) fn open_context(
|
|||
}
|
||||
}
|
||||
|
||||
AgentContext::Selection(selection_context) => {
|
||||
AgentContextHandle::Selection(selection_context) => {
|
||||
let buffer = selection_context.buffer.read(cx);
|
||||
if let Some(project_path) = buffer.project_path(cx) {
|
||||
let snapshot = buffer.snapshot();
|
||||
|
@ -3234,11 +3228,11 @@ pub(crate) fn open_context(
|
|||
}
|
||||
}
|
||||
|
||||
AgentContext::FetchedUrl(fetched_url_context) => {
|
||||
AgentContextHandle::FetchedUrl(fetched_url_context) => {
|
||||
cx.open_url(&fetched_url_context.url);
|
||||
}
|
||||
|
||||
AgentContext::Thread(thread_context) => workspace.update(cx, |workspace, cx| {
|
||||
AgentContextHandle::Thread(thread_context) => workspace.update(cx, |workspace, cx| {
|
||||
if let Some(panel) = workspace.panel::<AssistantPanel>(cx) {
|
||||
panel.update(cx, |panel, cx| {
|
||||
let thread_id = thread_context.thread.read(cx).id().clone();
|
||||
|
@ -3249,14 +3243,14 @@ pub(crate) fn open_context(
|
|||
}
|
||||
}),
|
||||
|
||||
AgentContext::Rules(rules_context) => window.dispatch_action(
|
||||
AgentContextHandle::Rules(rules_context) => window.dispatch_action(
|
||||
Box::new(OpenRulesLibrary {
|
||||
prompt_to_select: Some(rules_context.prompt_id.0),
|
||||
}),
|
||||
cx,
|
||||
),
|
||||
|
||||
AgentContext::Image(_) => {}
|
||||
AgentContextHandle::Image(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue