Use Project
instead of Workspace
in ContextStore
(#28402)
Release Notes: - N/A
This commit is contained in:
parent
9dae4d8c59
commit
f12a554f86
6 changed files with 32 additions and 40 deletions
|
@ -227,14 +227,14 @@ impl AssistantPanel {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let thread = thread_store.update(cx, |this, cx| this.create_thread(cx));
|
let thread = thread_store.update(cx, |this, cx| this.create_thread(cx));
|
||||||
let fs = workspace.app_state().fs.clone();
|
let fs = workspace.app_state().fs.clone();
|
||||||
let project = workspace.project().clone();
|
let project = workspace.project();
|
||||||
let language_registry = project.read(cx).languages().clone();
|
let language_registry = project.read(cx).languages().clone();
|
||||||
let workspace = workspace.weak_handle();
|
let workspace = workspace.weak_handle();
|
||||||
let weak_self = cx.entity().downgrade();
|
let weak_self = cx.entity().downgrade();
|
||||||
|
|
||||||
let message_editor_context_store = cx.new(|_cx| {
|
let message_editor_context_store = cx.new(|_cx| {
|
||||||
crate::context_store::ContextStore::new(
|
crate::context_store::ContextStore::new(
|
||||||
workspace.clone(),
|
project.downgrade(),
|
||||||
Some(thread_store.downgrade()),
|
Some(thread_store.downgrade()),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -344,7 +344,7 @@ impl AssistantPanel {
|
||||||
|
|
||||||
let message_editor_context_store = cx.new(|_cx| {
|
let message_editor_context_store = cx.new(|_cx| {
|
||||||
crate::context_store::ContextStore::new(
|
crate::context_store::ContextStore::new(
|
||||||
self.workspace.clone(),
|
self.project.downgrade(),
|
||||||
Some(self.thread_store.downgrade()),
|
Some(self.thread_store.downgrade()),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -521,7 +521,7 @@ impl AssistantPanel {
|
||||||
this.set_active_view(thread_view, window, cx);
|
this.set_active_view(thread_view, window, cx);
|
||||||
let message_editor_context_store = cx.new(|_cx| {
|
let message_editor_context_store = cx.new(|_cx| {
|
||||||
crate::context_store::ContextStore::new(
|
crate::context_store::ContextStore::new(
|
||||||
this.workspace.clone(),
|
this.project.downgrade(),
|
||||||
Some(this.thread_store.downgrade()),
|
Some(this.thread_store.downgrade()),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
@ -867,7 +867,7 @@ mod tests {
|
||||||
.expect("Opened test file wasn't an editor")
|
.expect("Opened test file wasn't an editor")
|
||||||
});
|
});
|
||||||
|
|
||||||
let context_store = cx.new(|_| ContextStore::new(workspace.downgrade(), None));
|
let context_store = cx.new(|_| ContextStore::new(project.downgrade(), None));
|
||||||
|
|
||||||
let editor_entity = editor.downgrade();
|
let editor_entity = editor.downgrade();
|
||||||
editor.update_in(&mut cx, |editor, window, cx| {
|
editor.update_in(&mut cx, |editor, window, cx| {
|
||||||
|
|
|
@ -8,11 +8,10 @@ use futures::future::join_all;
|
||||||
use futures::{self, Future, FutureExt, future};
|
use futures::{self, Future, FutureExt, future};
|
||||||
use gpui::{App, AppContext as _, Context, Entity, SharedString, Task, WeakEntity};
|
use gpui::{App, AppContext as _, Context, Entity, SharedString, Task, WeakEntity};
|
||||||
use language::{Buffer, File};
|
use language::{Buffer, File};
|
||||||
use project::{ProjectItem, ProjectPath, Worktree};
|
use project::{Project, ProjectItem, ProjectPath, Worktree};
|
||||||
use rope::Rope;
|
use rope::Rope;
|
||||||
use text::{Anchor, BufferId, OffsetRangeExt};
|
use text::{Anchor, BufferId, OffsetRangeExt};
|
||||||
use util::{ResultExt as _, maybe};
|
use util::{ResultExt as _, maybe};
|
||||||
use workspace::Workspace;
|
|
||||||
|
|
||||||
use crate::ThreadStore;
|
use crate::ThreadStore;
|
||||||
use crate::context::{
|
use crate::context::{
|
||||||
|
@ -23,7 +22,7 @@ use crate::context_strip::SuggestedContext;
|
||||||
use crate::thread::{Thread, ThreadId};
|
use crate::thread::{Thread, ThreadId};
|
||||||
|
|
||||||
pub struct ContextStore {
|
pub struct ContextStore {
|
||||||
workspace: WeakEntity<Workspace>,
|
project: WeakEntity<Project>,
|
||||||
context: Vec<AssistantContext>,
|
context: Vec<AssistantContext>,
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
// TODO: If an EntityId is used for all context types (like BufferId), can remove ContextId.
|
// TODO: If an EntityId is used for all context types (like BufferId), can remove ContextId.
|
||||||
|
@ -40,11 +39,11 @@ pub struct ContextStore {
|
||||||
|
|
||||||
impl ContextStore {
|
impl ContextStore {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
workspace: WeakEntity<Workspace>,
|
project: WeakEntity<Project>,
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
workspace,
|
project,
|
||||||
thread_store,
|
thread_store,
|
||||||
context: Vec::new(),
|
context: Vec::new(),
|
||||||
next_context_id: ContextId(0),
|
next_context_id: ContextId(0),
|
||||||
|
@ -81,12 +80,7 @@ impl ContextStore {
|
||||||
remove_if_exists: bool,
|
remove_if_exists: bool,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let workspace = self.workspace.clone();
|
let Some(project) = self.project.upgrade() else {
|
||||||
|
|
||||||
let Some(project) = workspace
|
|
||||||
.upgrade()
|
|
||||||
.map(|workspace| workspace.read(cx).project().clone())
|
|
||||||
else {
|
|
||||||
return Task::ready(Err(anyhow!("failed to read project")));
|
return Task::ready(Err(anyhow!("failed to read project")));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,11 +155,7 @@ impl ContextStore {
|
||||||
remove_if_exists: bool,
|
remove_if_exists: bool,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let workspace = self.workspace.clone();
|
let Some(project) = self.project.upgrade() else {
|
||||||
let Some(project) = workspace
|
|
||||||
.upgrade()
|
|
||||||
.map(|workspace| workspace.read(cx).project().clone())
|
|
||||||
else {
|
|
||||||
return Task::ready(Err(anyhow!("failed to read project")));
|
return Task::ready(Err(anyhow!("failed to read project")));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -262,13 +262,7 @@ impl InlineAssistant {
|
||||||
}
|
}
|
||||||
InlineAssistTarget::Terminal(active_terminal) => {
|
InlineAssistTarget::Terminal(active_terminal) => {
|
||||||
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
|
TerminalInlineAssistant::update_global(cx, |assistant, cx| {
|
||||||
assistant.assist(
|
assistant.assist(&active_terminal, cx.entity(), thread_store, window, cx)
|
||||||
&active_terminal,
|
|
||||||
cx.entity().downgrade(),
|
|
||||||
thread_store,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -322,6 +316,13 @@ impl InlineAssistant {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) {
|
||||||
|
let Some(project) = workspace
|
||||||
|
.upgrade()
|
||||||
|
.map(|workspace| workspace.read(cx).project().downgrade())
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let (snapshot, initial_selections) = editor.update(cx, |editor, cx| {
|
let (snapshot, initial_selections) = editor.update(cx, |editor, cx| {
|
||||||
(
|
(
|
||||||
editor.snapshot(window, cx),
|
editor.snapshot(window, cx),
|
||||||
|
@ -425,7 +426,7 @@ impl InlineAssistant {
|
||||||
for range in codegen_ranges {
|
for range in codegen_ranges {
|
||||||
let assist_id = self.next_assist_id.post_inc();
|
let assist_id = self.next_assist_id.post_inc();
|
||||||
let context_store =
|
let context_store =
|
||||||
cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
|
cx.new(|_cx| ContextStore::new(project.clone(), thread_store.clone()));
|
||||||
let codegen = cx.new(|cx| {
|
let codegen = cx.new(|cx| {
|
||||||
BufferCodegen::new(
|
BufferCodegen::new(
|
||||||
editor.read(cx).buffer().clone(),
|
editor.read(cx).buffer().clone(),
|
||||||
|
@ -519,7 +520,7 @@ impl InlineAssistant {
|
||||||
initial_prompt: String,
|
initial_prompt: String,
|
||||||
initial_transaction_id: Option<TransactionId>,
|
initial_transaction_id: Option<TransactionId>,
|
||||||
focus: bool,
|
focus: bool,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: Entity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
|
@ -537,8 +538,8 @@ impl InlineAssistant {
|
||||||
range.end = range.end.bias_right(&snapshot);
|
range.end = range.end.bias_right(&snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
let context_store =
|
let project = workspace.read(cx).project().downgrade();
|
||||||
cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
|
let context_store = cx.new(|_cx| ContextStore::new(project, thread_store.clone()));
|
||||||
|
|
||||||
let codegen = cx.new(|cx| {
|
let codegen = cx.new(|cx| {
|
||||||
BufferCodegen::new(
|
BufferCodegen::new(
|
||||||
|
@ -562,7 +563,7 @@ impl InlineAssistant {
|
||||||
codegen.clone(),
|
codegen.clone(),
|
||||||
self.fs.clone(),
|
self.fs.clone(),
|
||||||
context_store,
|
context_store,
|
||||||
workspace.clone(),
|
workspace.downgrade(),
|
||||||
thread_store,
|
thread_store,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
@ -589,7 +590,7 @@ impl InlineAssistant {
|
||||||
end_block_id,
|
end_block_id,
|
||||||
range,
|
range,
|
||||||
codegen.clone(),
|
codegen.clone(),
|
||||||
workspace.clone(),
|
workspace.downgrade(),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
),
|
),
|
||||||
|
@ -1779,6 +1780,7 @@ impl CodeActionProvider for AssistantCodeActionProvider {
|
||||||
let workspace = self.workspace.clone();
|
let workspace = self.workspace.clone();
|
||||||
let thread_store = self.thread_store.clone();
|
let thread_store = self.thread_store.clone();
|
||||||
window.spawn(cx, async move |cx| {
|
window.spawn(cx, async move |cx| {
|
||||||
|
let workspace = workspace.upgrade().context("workspace was released")?;
|
||||||
let editor = editor.upgrade().context("editor was released")?;
|
let editor = editor.upgrade().context("editor was released")?;
|
||||||
let range = editor
|
let range = editor
|
||||||
.update(cx, |editor, cx| {
|
.update(cx, |editor, cx| {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl TerminalInlineAssistant {
|
||||||
pub fn assist(
|
pub fn assist(
|
||||||
&mut self,
|
&mut self,
|
||||||
terminal_view: &Entity<TerminalView>,
|
terminal_view: &Entity<TerminalView>,
|
||||||
workspace: WeakEntity<Workspace>,
|
workspace: Entity<Workspace>,
|
||||||
thread_store: Option<WeakEntity<ThreadStore>>,
|
thread_store: Option<WeakEntity<ThreadStore>>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
|
@ -75,8 +75,8 @@ impl TerminalInlineAssistant {
|
||||||
let assist_id = self.next_assist_id.post_inc();
|
let assist_id = self.next_assist_id.post_inc();
|
||||||
let prompt_buffer =
|
let prompt_buffer =
|
||||||
cx.new(|cx| MultiBuffer::singleton(cx.new(|cx| Buffer::local(String::new(), cx)), cx));
|
cx.new(|cx| MultiBuffer::singleton(cx.new(|cx| Buffer::local(String::new(), cx)), cx));
|
||||||
let context_store =
|
let project = workspace.read(cx).project().downgrade();
|
||||||
cx.new(|_cx| ContextStore::new(workspace.clone(), thread_store.clone()));
|
let context_store = cx.new(|_cx| ContextStore::new(project, thread_store.clone()));
|
||||||
let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone()));
|
let codegen = cx.new(|_| TerminalCodegen::new(terminal, self.telemetry.clone()));
|
||||||
|
|
||||||
let prompt_editor = cx.new(|cx| {
|
let prompt_editor = cx.new(|cx| {
|
||||||
|
@ -87,7 +87,7 @@ impl TerminalInlineAssistant {
|
||||||
codegen,
|
codegen,
|
||||||
self.fs.clone(),
|
self.fs.clone(),
|
||||||
context_store.clone(),
|
context_store.clone(),
|
||||||
workspace.clone(),
|
workspace.downgrade(),
|
||||||
thread_store.clone(),
|
thread_store.clone(),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
@ -106,7 +106,7 @@ impl TerminalInlineAssistant {
|
||||||
assist_id,
|
assist_id,
|
||||||
terminal_view,
|
terminal_view,
|
||||||
prompt_editor,
|
prompt_editor,
|
||||||
workspace.clone(),
|
workspace.downgrade(),
|
||||||
context_store,
|
context_store,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -2234,7 +2234,7 @@ fn main() {{
|
||||||
});
|
});
|
||||||
|
|
||||||
let thread = thread_store.update(cx, |store, cx| store.create_thread(cx));
|
let thread = thread_store.update(cx, |store, cx| store.create_thread(cx));
|
||||||
let context_store = cx.new(|_cx| ContextStore::new(workspace.downgrade(), None));
|
let context_store = cx.new(|_cx| ContextStore::new(project.downgrade(), None));
|
||||||
|
|
||||||
(workspace, thread_store, thread, context_store)
|
(workspace, thread_store, thread, context_store)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue