mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Extract ContextHistory
to assistant_context_editor
(#23437)
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Linux x86_x64 release bundle (push) Blocked by required conditions
CI / Linux arm64 release bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
Some checks are pending
CI / Check Postgres and Protobuf migrations, mergability (push) Waiting to run
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Linux x86_x64 release bundle (push) Blocked by required conditions
CI / Linux arm64 release bundle (push) Blocked by required conditions
CI / Auto release preview (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Script / ShellCheck Scripts (push) Waiting to run
This PR extracts the `ContextHistory` to the `assistant_context_editor` crate. Release Notes: - N/A
This commit is contained in:
parent
e59c910845
commit
be407e27f9
7 changed files with 47 additions and 25 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -403,7 +403,6 @@ dependencies = [
|
||||||
"multi_buffer",
|
"multi_buffer",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"paths",
|
"paths",
|
||||||
"picker",
|
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"project",
|
"project",
|
||||||
"prompt_library",
|
"prompt_library",
|
||||||
|
|
|
@ -50,7 +50,6 @@ menu.workspace = true
|
||||||
multi_buffer.workspace = true
|
multi_buffer.workspace = true
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
paths.workspace = true
|
paths.workspace = true
|
||||||
picker.workspace = true
|
|
||||||
project.workspace = true
|
project.workspace = true
|
||||||
prompt_library.workspace = true
|
prompt_library.workspace = true
|
||||||
proto.workspace = true
|
proto.workspace = true
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#![cfg_attr(target_os = "windows", allow(unused, dead_code))]
|
#![cfg_attr(target_os = "windows", allow(unused, dead_code))]
|
||||||
|
|
||||||
pub mod assistant_panel;
|
pub mod assistant_panel;
|
||||||
mod context_history;
|
|
||||||
mod inline_assistant;
|
mod inline_assistant;
|
||||||
pub mod slash_command_settings;
|
pub mod slash_command_settings;
|
||||||
mod terminal_inline_assistant;
|
mod terminal_inline_assistant;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::context_history::ContextHistory;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, DeployPromptLibrary,
|
terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, DeployPromptLibrary,
|
||||||
InlineAssistant, NewContext, ToggleFocus,
|
InlineAssistant, NewContext, ToggleFocus,
|
||||||
|
@ -6,9 +5,9 @@ use crate::{
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use assistant_context_editor::{
|
use assistant_context_editor::{
|
||||||
make_lsp_adapter_delegate, AssistantPanelDelegate, Context, ContextEditor,
|
make_lsp_adapter_delegate, AssistantPanelDelegate, Context, ContextEditor,
|
||||||
ContextEditorToolbarItem, ContextEditorToolbarItemEvent, ContextId, ContextStore,
|
ContextEditorToolbarItem, ContextEditorToolbarItemEvent, ContextHistory, ContextId,
|
||||||
ContextStoreEvent, InsertDraggedFiles, SlashCommandCompletionProvider, ToggleModelSelector,
|
ContextStore, ContextStoreEvent, InsertDraggedFiles, SlashCommandCompletionProvider,
|
||||||
DEFAULT_TAB_TITLE,
|
ToggleModelSelector, DEFAULT_TAB_TITLE,
|
||||||
};
|
};
|
||||||
use assistant_settings::{AssistantDockPosition, AssistantSettings};
|
use assistant_settings::{AssistantDockPosition, AssistantSettings};
|
||||||
use assistant_slash_command::SlashCommandWorkingSet;
|
use assistant_slash_command::SlashCommandWorkingSet;
|
||||||
|
@ -966,12 +965,11 @@ impl AssistantPanel {
|
||||||
pane.activate_item(history_item_ix, true, true, cx);
|
pane.activate_item(history_item_ix, true, true, cx);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let assistant_panel = cx.view().downgrade();
|
|
||||||
let history = cx.new_view(|cx| {
|
let history = cx.new_view(|cx| {
|
||||||
ContextHistory::new(
|
ContextHistory::new(
|
||||||
self.project.clone(),
|
self.project.clone(),
|
||||||
self.context_store.clone(),
|
self.context_store.clone(),
|
||||||
assistant_panel,
|
self.workspace.clone(),
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -1308,6 +1306,19 @@ impl AssistantPanelDelegate for ConcreteAssistantPanelDelegate {
|
||||||
panel.read(cx).active_context_editor(cx)
|
panel.read(cx).active_context_editor(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_saved_context(
|
||||||
|
&self,
|
||||||
|
workspace: &mut Workspace,
|
||||||
|
path: PathBuf,
|
||||||
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
let Some(panel) = workspace.panel::<AssistantPanel>(cx) else {
|
||||||
|
return Task::ready(Err(anyhow!("no Assistant panel found")));
|
||||||
|
};
|
||||||
|
|
||||||
|
panel.update(cx, |panel, cx| panel.open_saved_context(path, cx))
|
||||||
|
}
|
||||||
|
|
||||||
fn open_remote_context(
|
fn open_remote_context(
|
||||||
&self,
|
&self,
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
mod context;
|
mod context;
|
||||||
mod context_editor;
|
mod context_editor;
|
||||||
|
mod context_history;
|
||||||
mod context_store;
|
mod context_store;
|
||||||
mod patch;
|
mod patch;
|
||||||
mod slash_command;
|
mod slash_command;
|
||||||
|
@ -12,6 +13,7 @@ use gpui::AppContext;
|
||||||
|
|
||||||
pub use crate::context::*;
|
pub use crate::context::*;
|
||||||
pub use crate::context_editor::*;
|
pub use crate::context_editor::*;
|
||||||
|
pub use crate::context_history::*;
|
||||||
pub use crate::context_store::*;
|
pub use crate::context_store::*;
|
||||||
pub use crate::patch::*;
|
pub use crate::patch::*;
|
||||||
pub use crate::slash_command::*;
|
pub use crate::slash_command::*;
|
||||||
|
|
|
@ -121,6 +121,13 @@ pub trait AssistantPanelDelegate {
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) -> Option<View<ContextEditor>>;
|
) -> Option<View<ContextEditor>>;
|
||||||
|
|
||||||
|
fn open_saved_context(
|
||||||
|
&self,
|
||||||
|
workspace: &mut Workspace,
|
||||||
|
path: PathBuf,
|
||||||
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
) -> Task<Result<()>>;
|
||||||
|
|
||||||
fn open_remote_context(
|
fn open_remote_context(
|
||||||
&self,
|
&self,
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use assistant_context_editor::{
|
|
||||||
ContextStore, RemoteContextMetadata, SavedContextMetadata, DEFAULT_TAB_TITLE,
|
|
||||||
};
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AppContext, EventEmitter, FocusHandle, FocusableView, Model, Subscription, Task, View, WeakView,
|
AppContext, EventEmitter, FocusHandle, FocusableView, Model, Subscription, Task, View, WeakView,
|
||||||
};
|
};
|
||||||
|
@ -10,9 +7,12 @@ use picker::{Picker, PickerDelegate};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use ui::utils::{format_distance_from_now, DateTimeType};
|
use ui::utils::{format_distance_from_now, DateTimeType};
|
||||||
use ui::{prelude::*, Avatar, ListItem, ListItemSpacing};
|
use ui::{prelude::*, Avatar, ListItem, ListItemSpacing};
|
||||||
use workspace::Item;
|
use workspace::{Item, Workspace};
|
||||||
|
|
||||||
use crate::AssistantPanel;
|
use crate::{
|
||||||
|
AssistantPanelDelegate, ContextStore, RemoteContextMetadata, SavedContextMetadata,
|
||||||
|
DEFAULT_TAB_TITLE,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum ContextMetadata {
|
pub enum ContextMetadata {
|
||||||
|
@ -27,14 +27,14 @@ enum SavedContextPickerEvent {
|
||||||
pub struct ContextHistory {
|
pub struct ContextHistory {
|
||||||
picker: View<Picker<SavedContextPickerDelegate>>,
|
picker: View<Picker<SavedContextPickerDelegate>>,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
assistant_panel: WeakView<AssistantPanel>,
|
workspace: WeakView<Workspace>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextHistory {
|
impl ContextHistory {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
project: Model<Project>,
|
project: Model<Project>,
|
||||||
context_store: Model<ContextStore>,
|
context_store: Model<ContextStore>,
|
||||||
assistant_panel: WeakView<AssistantPanel>,
|
workspace: WeakView<Workspace>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let picker = cx.new_view(|cx| {
|
let picker = cx.new_view(|cx| {
|
||||||
|
@ -46,7 +46,7 @@ impl ContextHistory {
|
||||||
.max_height(None)
|
.max_height(None)
|
||||||
});
|
});
|
||||||
|
|
||||||
let _subscriptions = vec![
|
let subscriptions = vec![
|
||||||
cx.observe(&context_store, |this, _, cx| {
|
cx.observe(&context_store, |this, _, cx| {
|
||||||
this.picker.update(cx, |picker, cx| picker.refresh(cx));
|
this.picker.update(cx, |picker, cx| picker.refresh(cx));
|
||||||
}),
|
}),
|
||||||
|
@ -55,8 +55,8 @@ impl ContextHistory {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
picker,
|
picker,
|
||||||
_subscriptions,
|
_subscriptions: subscriptions,
|
||||||
assistant_panel,
|
workspace,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,16 +67,21 @@ impl ContextHistory {
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let SavedContextPickerEvent::Confirmed(context) = event;
|
let SavedContextPickerEvent::Confirmed(context) = event;
|
||||||
self.assistant_panel
|
|
||||||
.update(cx, |assistant_panel, cx| match context {
|
let Some(assistant_panel_delegate) = <dyn AssistantPanelDelegate>::try_global(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.workspace
|
||||||
|
.update(cx, |workspace, cx| match context {
|
||||||
ContextMetadata::Remote(metadata) => {
|
ContextMetadata::Remote(metadata) => {
|
||||||
assistant_panel
|
assistant_panel_delegate
|
||||||
.open_remote_context(metadata.id.clone(), cx)
|
.open_remote_context(workspace, metadata.id.clone(), cx)
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
ContextMetadata::Saved(metadata) => {
|
ContextMetadata::Saved(metadata) => {
|
||||||
assistant_panel
|
assistant_panel_delegate
|
||||||
.open_saved_context(metadata.path.clone(), cx)
|
.open_saved_context(workspace, metadata.path.clone(), cx)
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
})
|
})
|
Loading…
Reference in a new issue