assistant: Allow guests to create new contexts on the host (#15439)
This PR extends collaboration in the Assistant to allow guests to create new contexts on the host when collaborating. Release Notes: - N/A
This commit is contained in:
parent
2b0c60043d
commit
aa1633ba40
5 changed files with 225 additions and 24 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::ContextStoreEvent;
|
||||
use crate::{
|
||||
assistant_settings::{AssistantDockPosition, AssistantSettings},
|
||||
humanize_token_count,
|
||||
|
@ -389,6 +390,7 @@ impl AssistantPanel {
|
|||
cx.subscribe(&pane, Self::handle_pane_event),
|
||||
cx.subscribe(&context_editor_toolbar, Self::handle_toolbar_event),
|
||||
cx.subscribe(&model_summary_editor, Self::handle_summary_editor_event),
|
||||
cx.subscribe(&context_store, Self::handle_context_store_event),
|
||||
cx.observe(
|
||||
&LanguageModelCompletionProvider::global(cx),
|
||||
|this, _, cx| {
|
||||
|
@ -507,6 +509,46 @@ impl AssistantPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_context_store_event(
|
||||
&mut self,
|
||||
_context_store: Model<ContextStore>,
|
||||
event: &ContextStoreEvent,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let ContextStoreEvent::ContextCreated(context_id) = event;
|
||||
let Some(context) = self
|
||||
.context_store
|
||||
.read(cx)
|
||||
.loaded_context_for_id(&context_id, cx)
|
||||
else {
|
||||
log::error!("no context found with ID: {}", context_id.to_proto());
|
||||
return;
|
||||
};
|
||||
let Some(workspace) = self.workspace.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let lsp_adapter_delegate = workspace.update(cx, |workspace, cx| {
|
||||
make_lsp_adapter_delegate(workspace.project(), cx).log_err()
|
||||
});
|
||||
|
||||
let assistant_panel = cx.view().downgrade();
|
||||
let editor = cx.new_view(|cx| {
|
||||
let mut editor = ContextEditor::for_context(
|
||||
context,
|
||||
self.fs.clone(),
|
||||
workspace.clone(),
|
||||
self.project.clone(),
|
||||
lsp_adapter_delegate,
|
||||
assistant_panel,
|
||||
cx,
|
||||
);
|
||||
editor.insert_default_prompt(cx);
|
||||
editor
|
||||
});
|
||||
|
||||
self.show_context(editor.clone(), cx);
|
||||
}
|
||||
|
||||
fn completion_provider_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(editor) = self.active_context_editor(cx) {
|
||||
editor.update(cx, |active_context, cx| {
|
||||
|
@ -681,29 +723,75 @@ impl AssistantPanel {
|
|||
}
|
||||
|
||||
fn new_context(&mut self, cx: &mut ViewContext<Self>) -> Option<View<ContextEditor>> {
|
||||
let context = self.context_store.update(cx, |store, cx| store.create(cx));
|
||||
let workspace = self.workspace.upgrade()?;
|
||||
let lsp_adapter_delegate = workspace.update(cx, |workspace, cx| {
|
||||
make_lsp_adapter_delegate(workspace.project(), cx).log_err()
|
||||
});
|
||||
if self.project.read(cx).is_remote() {
|
||||
let task = self
|
||||
.context_store
|
||||
.update(cx, |store, cx| store.create_remote_context(cx));
|
||||
|
||||
let assistant_panel = cx.view().downgrade();
|
||||
let editor = cx.new_view(|cx| {
|
||||
let mut editor = ContextEditor::for_context(
|
||||
context,
|
||||
self.fs.clone(),
|
||||
workspace.clone(),
|
||||
self.project.clone(),
|
||||
lsp_adapter_delegate,
|
||||
assistant_panel,
|
||||
cx,
|
||||
);
|
||||
editor.insert_default_prompt(cx);
|
||||
editor
|
||||
});
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let context = task.await?;
|
||||
|
||||
self.show_context(editor.clone(), cx);
|
||||
Some(editor)
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let Some(workspace) = this.workspace.upgrade() else {
|
||||
return Ok(());
|
||||
};
|
||||
let lsp_adapter_delegate = workspace.update(cx, |workspace, cx| {
|
||||
make_lsp_adapter_delegate(workspace.project(), cx).log_err()
|
||||
});
|
||||
|
||||
let fs = this.fs.clone();
|
||||
let project = this.project.clone();
|
||||
let weak_assistant_panel = cx.view().downgrade();
|
||||
|
||||
let editor = cx.new_view(|cx| {
|
||||
let mut editor = ContextEditor::for_context(
|
||||
context,
|
||||
fs,
|
||||
workspace.clone(),
|
||||
project,
|
||||
lsp_adapter_delegate,
|
||||
weak_assistant_panel,
|
||||
cx,
|
||||
);
|
||||
editor.insert_default_prompt(cx);
|
||||
editor
|
||||
});
|
||||
|
||||
this.show_context(editor, cx);
|
||||
|
||||
anyhow::Ok(())
|
||||
})??;
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
None
|
||||
} else {
|
||||
let context = self.context_store.update(cx, |store, cx| store.create(cx));
|
||||
let workspace = self.workspace.upgrade()?;
|
||||
let lsp_adapter_delegate = workspace.update(cx, |workspace, cx| {
|
||||
make_lsp_adapter_delegate(workspace.project(), cx).log_err()
|
||||
});
|
||||
|
||||
let assistant_panel = cx.view().downgrade();
|
||||
let editor = cx.new_view(|cx| {
|
||||
let mut editor = ContextEditor::for_context(
|
||||
context,
|
||||
self.fs.clone(),
|
||||
workspace.clone(),
|
||||
self.project.clone(),
|
||||
lsp_adapter_delegate,
|
||||
assistant_panel,
|
||||
cx,
|
||||
);
|
||||
editor.insert_default_prompt(cx);
|
||||
editor
|
||||
});
|
||||
|
||||
self.show_context(editor.clone(), cx);
|
||||
Some(editor)
|
||||
}
|
||||
}
|
||||
|
||||
fn show_context(&mut self, context_editor: View<ContextEditor>, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue