assistant: Add basic current project context (#11828)
This PR adds the beginnings of current project context to the Assistant. Currently it supports reading a `Cargo.toml` file and using that to get some basic information about the project, and its dependencies: <img width="1264" alt="Screenshot 2024-05-14 at 6 17 03 PM" src="https://github.com/zed-industries/zed/assets/1486634/cc8ed5ad-0ccb-45da-9c07-c96af84a14e3"> Release Notes: - N/A --------- Co-authored-by: Nate <nate@zed.dev>
This commit is contained in:
parent
5b2c019f83
commit
26b5f34046
6 changed files with 228 additions and 34 deletions
|
@ -778,6 +778,7 @@ impl AssistantPanel {
|
|||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
self.show_conversation(editor.clone(), cx);
|
||||
Some(editor)
|
||||
}
|
||||
|
@ -1351,7 +1352,7 @@ struct Summary {
|
|||
pub struct Conversation {
|
||||
id: Option<String>,
|
||||
buffer: Model<Buffer>,
|
||||
ambient_context: AmbientContext,
|
||||
pub(crate) ambient_context: AmbientContext,
|
||||
message_anchors: Vec<MessageAnchor>,
|
||||
messages_metadata: HashMap<MessageId, MessageMetadata>,
|
||||
next_message_id: MessageId,
|
||||
|
@ -1521,6 +1522,17 @@ impl Conversation {
|
|||
self.update_recent_buffers_context(cx);
|
||||
}
|
||||
|
||||
fn toggle_current_project_context(
|
||||
&mut self,
|
||||
fs: Arc<dyn Fs>,
|
||||
project: WeakModel<Project>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
self.ambient_context.current_project.enabled =
|
||||
!self.ambient_context.current_project.enabled;
|
||||
self.ambient_context.current_project.update(fs, project, cx);
|
||||
}
|
||||
|
||||
fn set_recent_buffers(
|
||||
&mut self,
|
||||
buffers: impl IntoIterator<Item = Model<Buffer>>,
|
||||
|
@ -1887,15 +1899,12 @@ impl Conversation {
|
|||
}
|
||||
|
||||
fn to_completion_request(&self, cx: &mut ModelContext<Conversation>) -> LanguageModelRequest {
|
||||
let messages = self
|
||||
.ambient_context
|
||||
.recent_buffers
|
||||
.enabled
|
||||
.then(|| LanguageModelRequestMessage {
|
||||
role: Role::System,
|
||||
content: self.ambient_context.recent_buffers.message.clone(),
|
||||
})
|
||||
let recent_buffers_context = self.ambient_context.recent_buffers.to_message();
|
||||
let current_project_context = self.ambient_context.current_project.to_message();
|
||||
|
||||
let messages = recent_buffers_context
|
||||
.into_iter()
|
||||
.chain(current_project_context)
|
||||
.chain(
|
||||
self.messages(cx)
|
||||
.filter(|message| matches!(message.status, MessageStatus::Done))
|
||||
|
@ -2533,6 +2542,11 @@ impl ConversationEditor {
|
|||
}
|
||||
|
||||
fn update_message_headers(&mut self, cx: &mut ViewContext<Self>) {
|
||||
let project = self
|
||||
.workspace
|
||||
.update(cx, |workspace, _cx| workspace.project().downgrade())
|
||||
.unwrap();
|
||||
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
let excerpt_id = *buffer.as_singleton().unwrap().0;
|
||||
|
@ -2549,6 +2563,8 @@ impl ConversationEditor {
|
|||
height: 2,
|
||||
style: BlockStyle::Sticky,
|
||||
render: Box::new({
|
||||
let fs = self.fs.clone();
|
||||
let project = project.clone();
|
||||
let conversation = self.conversation.clone();
|
||||
move |cx| {
|
||||
let message_id = message.id;
|
||||
|
@ -2630,31 +2646,40 @@ impl ConversationEditor {
|
|||
Tooltip::text("Include Open Files", cx)
|
||||
}),
|
||||
)
|
||||
// .child(
|
||||
// IconButton::new("include_terminal", IconName::Terminal)
|
||||
// .icon_size(IconSize::Small)
|
||||
// .tooltip(|cx| {
|
||||
// Tooltip::text("Include Terminal", cx)
|
||||
// }),
|
||||
// )
|
||||
// .child(
|
||||
// IconButton::new(
|
||||
// "include_edit_history",
|
||||
// IconName::FileGit,
|
||||
// )
|
||||
// .icon_size(IconSize::Small)
|
||||
// .tooltip(
|
||||
// |cx| Tooltip::text("Include Edit History", cx),
|
||||
// ),
|
||||
// )
|
||||
// .child(
|
||||
// IconButton::new(
|
||||
// "include_file_trees",
|
||||
// IconName::FileTree,
|
||||
// )
|
||||
// .icon_size(IconSize::Small)
|
||||
// .tooltip(|cx| Tooltip::text("Include File Trees", cx)),
|
||||
// )
|
||||
.child(
|
||||
IconButton::new(
|
||||
"include_current_project",
|
||||
IconName::FileTree,
|
||||
)
|
||||
.icon_size(IconSize::Small)
|
||||
.selected(
|
||||
conversation
|
||||
.read(cx)
|
||||
.ambient_context
|
||||
.current_project
|
||||
.enabled,
|
||||
)
|
||||
.on_click({
|
||||
let fs = fs.clone();
|
||||
let project = project.clone();
|
||||
let conversation = conversation.downgrade();
|
||||
move |_, cx| {
|
||||
let fs = fs.clone();
|
||||
let project = project.clone();
|
||||
conversation
|
||||
.update(cx, |conversation, cx| {
|
||||
conversation
|
||||
.toggle_current_project_context(
|
||||
fs, project, cx,
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
.tooltip(
|
||||
|cx| Tooltip::text("Include Current Project", cx),
|
||||
),
|
||||
)
|
||||
.into_any()
|
||||
}))
|
||||
.into_any_element()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue