@@ -6,11 +6,10 @@ use crate::{
default_command::DefaultSlashCommand, SlashCommandCompletionProvider, SlashCommandLine,
SlashCommandRegistry,
},
- ApplyEdit, Assist, CompletionProvider, ConfirmCommand, ConversationStore, CycleMessageRole,
+ ApplyEdit, Assist, CompletionProvider, ConfirmCommand, ContextStore, CycleMessageRole,
InlineAssist, InlineAssistant, LanguageModelRequest, LanguageModelRequestMessage, MessageId,
- MessageMetadata, MessageStatus, ModelSelector, QuoteSelection, ResetKey, Role,
- SavedConversation, SavedConversationMetadata, SavedMessage, Split, ToggleFocus, ToggleHistory,
- ToggleModelSelector,
+ MessageMetadata, MessageStatus, ModelSelector, QuoteSelection, ResetKey, Role, SavedContext,
+ SavedContextMetadata, SavedMessage, Split, ToggleFocus, ToggleHistory, ToggleModelSelector,
};
use anyhow::{anyhow, Result};
use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandOutputSection};
@@ -30,10 +29,10 @@ use futures::future::Shared;
use futures::{FutureExt, StreamExt};
use gpui::{
div, point, rems, Action, AnyElement, AnyView, AppContext, AsyncAppContext, AsyncWindowContext,
- ClipboardItem, Context, Empty, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
- IntoElement, Model, ModelContext, ParentElement, Pixels, Render, SharedString,
- StatefulInteractiveElement, Styled, Subscription, Task, UpdateGlobal, View, ViewContext,
- VisualContext, WeakView, WindowContext,
+ ClipboardItem, Context as _, Empty, EventEmitter, FocusHandle, FocusableView,
+ InteractiveElement, IntoElement, Model, ModelContext, ParentElement, Pixels, Render,
+ SharedString, StatefulInteractiveElement, Styled, Subscription, Task, UpdateGlobal, View,
+ ViewContext, VisualContext, WeakView, WindowContext,
};
use language::{
language_settings::SoftWrap, AnchorRangeExt, AutoindentMode, Buffer, LanguageRegistry,
@@ -58,7 +57,7 @@ use ui::{
popover_menu, prelude::*, ButtonLike, ContextMenu, ElevationIndex, KeyBinding, ListItem,
ListItemSpacing, PopoverMenuHandle, Tab, TabBar, Tooltip,
};
-use util::{paths::CONVERSATIONS_DIR, post_inc, ResultExt, TryFutureExt};
+use util::{paths::CONTEXTS_DIR, post_inc, ResultExt, TryFutureExt};
use uuid::Uuid;
use workspace::NewFile;
use workspace::{
@@ -81,8 +80,7 @@ pub fn init(cx: &mut AppContext) {
})
.register_action(AssistantPanel::inline_assist)
.register_action(AssistantPanel::cancel_last_inline_assist)
- // .register_action(ConversationEditor::insert_active_prompt)
- .register_action(ConversationEditor::quote_selection);
+ .register_action(ContextEditor::quote_selection);
},
)
.detach();
@@ -92,10 +90,10 @@ pub struct AssistantPanel {
workspace: WeakView<Workspace>,
width: Option<Pixels>,
height: Option<Pixels>,
- active_conversation_editor: Option<ActiveConversationEditor>,
- show_saved_conversations: bool,
- conversation_store: Model<ConversationStore>,
- saved_conversation_picker: View<Picker<SavedConversationPickerDelegate>>,
+ active_context_editor: Option<ActiveContextEditor>,
+ show_saved_contexts: bool,
+ context_store: Model<ContextStore>,
+ saved_context_picker: View<Picker<SavedContextPickerDelegate>>,
zoomed: bool,
focus_handle: FocusHandle,
toolbar: View<Toolbar>,
@@ -108,20 +106,20 @@ pub struct AssistantPanel {
model_menu_handle: PopoverMenuHandle<ContextMenu>,
}
-struct SavedConversationPickerDelegate {
- store: Model<ConversationStore>,
- matches: Vec<SavedConversationMetadata>,
+struct SavedContextPickerDelegate {
+ store: Model<ContextStore>,
+ matches: Vec<SavedContextMetadata>,
selected_index: usize,
}
-enum SavedConversationPickerEvent {
+enum SavedContextPickerEvent {
Confirmed { path: PathBuf },
}
-impl EventEmitter<SavedConversationPickerEvent> for Picker<SavedConversationPickerDelegate> {}
+impl EventEmitter<SavedContextPickerEvent> for Picker<SavedContextPickerDelegate> {}
-impl SavedConversationPickerDelegate {
- fn new(store: Model<ConversationStore>) -> Self {
+impl SavedContextPickerDelegate {
+ fn new(store: Model<ContextStore>) -> Self {
Self {
store,
matches: Vec::new(),
@@ -130,7 +128,7 @@ impl SavedConversationPickerDelegate {
}
}
-impl PickerDelegate for SavedConversationPickerDelegate {
+impl PickerDelegate for SavedContextPickerDelegate {
type ListItem = ListItem;
fn match_count(&self) -> usize {
@@ -164,7 +162,7 @@ impl PickerDelegate for SavedConversationPickerDelegate {
fn confirm(&mut self, _secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
if let Some(metadata) = self.matches.get(self.selected_index) {
- cx.emit(SavedConversationPickerEvent::Confirmed {
+ cx.emit(SavedContextPickerEvent::Confirmed {
path: metadata.path.clone(),
})
}
@@ -178,7 +176,7 @@ impl PickerDelegate for SavedConversationPickerDelegate {
selected: bool,
_cx: &mut ViewContext<Picker<Self>>,
) -> Option<Self::ListItem> {
- let conversation = self.matches.get(ix)?;
+ let context = self.matches.get(ix)?;
Some(
ListItem::new(ix)
.inset(true)
@@ -190,18 +188,18 @@ impl PickerDelegate for SavedConversationPickerDelegate {
.w_full()
.gap_2()
.child(
- Label::new(conversation.mtime.format("%F %I:%M%p").to_string())
+ Label::new(context.mtime.format("%F %I:%M%p").to_string())
.color(Color::Muted)
.size(LabelSize::Small),
)
- .child(Label::new(conversation.title.clone()).size(LabelSize::Small)),
+ .child(Label::new(context.title.clone()).size(LabelSize::Small)),
),
)
}
}
-struct ActiveConversationEditor {
- editor: View<ConversationEditor>,
+struct ActiveContextEditor {
+ editor: View<ContextEditor>,
_subscriptions: Vec<Subscription>,
}
@@ -212,9 +210,7 @@ impl AssistantPanel {
) -> Task<Result<View<Self>>> {
cx.spawn(|mut cx| async move {
let fs = workspace.update(&mut cx, |workspace, _| workspace.app_state().fs.clone())?;
- let conversation_store = cx
- .update(|cx| ConversationStore::new(fs.clone(), cx))?
- .await?;
+ let context_store = cx.update(|cx| ContextStore::new(fs.clone(), cx))?.await?;
// TODO: deserialize state.
let workspace_handle = workspace.clone();
@@ -227,9 +223,9 @@ impl AssistantPanel {
toolbar
});
- let saved_conversation_picker = cx.new_view(|cx| {
+ let saved_context_picker = cx.new_view(|cx| {
Picker::uniform_list(
- SavedConversationPickerDelegate::new(conversation_store.clone()),
+ SavedContextPickerDelegate::new(context_store.clone()),
cx,
)
.modal(false)
@@ -249,13 +245,13 @@ impl AssistantPanel {
CompletionProvider::global(cx).settings_version();
}
}),
- cx.observe(&conversation_store, |this, _, cx| {
- this.saved_conversation_picker
+ cx.observe(&context_store, |this, _, cx| {
+ this.saved_context_picker
.update(cx, |picker, cx| picker.refresh(cx));
}),
cx.subscribe(
- &saved_conversation_picker,
- Self::handle_saved_conversation_picker_event,
+ &saved_context_picker,
+ Self::handle_saved_context_picker_event,
),
];
@@ -266,10 +262,10 @@ impl AssistantPanel {
Self {
workspace: workspace_handle,
- active_conversation_editor: None,
- show_saved_conversations: false,
- saved_conversation_picker,
- conversation_store,
+ active_context_editor: None,
+ show_saved_contexts: false,
+ saved_context_picker,
+ context_store,
zoomed: false,
focus_handle,
toolbar,
@@ -293,10 +289,10 @@ impl AssistantPanel {
.update(cx, |toolbar, cx| toolbar.focus_changed(true, cx));
cx.notify();
if self.focus_handle.is_focused(cx) {
- if self.show_saved_conversations {
- cx.focus_view(&self.saved_conversation_picker);
- } else if let Some(conversation) = self.active_conversation_editor() {
- cx.focus_view(conversation);
+ if self.show_saved_contexts {
+ cx.focus_view(&self.saved_context_picker);
+ } else if let Some(context) = self.active_context_editor() {
+ cx.focus_view(context);
}
}
}
@@ -315,18 +311,16 @@ impl AssistantPanel {
if self.is_authenticated(cx) {
self.authentication_prompt = None;
- if let Some(editor) = self.active_conversation_editor() {
- editor.update(cx, |active_conversation, cx| {
- active_conversation
- .conversation
- .update(cx, |conversation, cx| {
- conversation.completion_provider_changed(cx)
- })
+ if let Some(editor) = self.active_context_editor() {
+ editor.update(cx, |active_context, cx| {
+ active_context
+ .context
+ .update(cx, |context, cx| context.completion_provider_changed(cx))
})
}
- if self.active_conversation_editor().is_none() {
- self.new_conversation(cx);
+ if self.active_context_editor().is_none() {
+ self.new_context(cx);
}
cx.notify();
} else if self.authentication_prompt.is_none()
@@ -340,16 +334,15 @@ impl AssistantPanel {
}
}
- fn handle_saved_conversation_picker_event(
+ fn handle_saved_context_picker_event(
&mut self,
- _picker: View<Picker<SavedConversationPickerDelegate>>,
- event: &SavedConversationPickerEvent,
+ _picker: View<Picker<SavedContextPickerDelegate>>,
+ event: &SavedContextPickerEvent,
cx: &mut ViewContext<Self>,
) {
match event {
- SavedConversationPickerEvent::Confirmed { path } => {
- self.open_conversation(path.clone(), cx)
- .detach_and_log_err(cx);
+ SavedContextPickerEvent::Confirmed { path } => {
+ self.open_context(path.clone(), cx).detach_and_log_err(cx);
}
}
}
@@ -368,30 +361,29 @@ impl AssistantPanel {
return;
};
- let conversation_editor =
- assistant
- .read(cx)
- .active_conversation_editor()
- .and_then(|editor| {
- let editor = &editor.read(cx).editor;
- if editor.read(cx).is_focused(cx) {
- Some(editor.clone())
- } else {
- None
- }
- });
+ let context_editor = assistant
+ .read(cx)
+ .active_context_editor()
+ .and_then(|editor| {
+ let editor = &editor.read(cx).editor;
+ if editor.read(cx).is_focused(cx) {
+ Some(editor.clone())
+ } else {
+ None
+ }
+ });
- let include_conversation;
+ let include_context;
let active_editor;
- if let Some(conversation_editor) = conversation_editor {
- active_editor = conversation_editor;
- include_conversation = false;
+ if let Some(context_editor) = context_editor {
+ active_editor = context_editor;
+ include_context = false;
} else if let Some(workspace_editor) = workspace
.active_item(cx)
.and_then(|item| item.act_as::<Editor>(cx))
{
active_editor = workspace_editor;
- include_conversation = true;
+ include_context = true;
} else {
return;
};
@@ -401,7 +393,7 @@ impl AssistantPanel {
assistant.assist(
&active_editor,
Some(cx.view().downgrade()),
- include_conversation,
+ include_context,
cx,
)
})
@@ -414,12 +406,7 @@ impl AssistantPanel {
if assistant.update(&mut cx, |assistant, cx| assistant.is_authenticated(cx))? {
cx.update(|cx| {
InlineAssistant::update_global(cx, |assistant, cx| {
- assistant.assist(
- &active_editor,
- Some(workspace),
- include_conversation,
- cx,
- )
+ assistant.assist(&active_editor, Some(workspace), include_context, cx)
})
})?
} else {
@@ -447,11 +434,11 @@ impl AssistantPanel {
}
}
- fn new_conversation(&mut self, cx: &mut ViewContext<Self>) -> Option<View<ConversationEditor>> {
+ fn new_context(&mut self, cx: &mut ViewContext<Self>) -> Option<View<ContextEditor>> {
let workspace = self.workspace.upgrade()?;
let editor = cx.new_view(|cx| {
- ConversationEditor::new(
+ ContextEditor::new(
self.languages.clone(),
self.slash_commands.clone(),
self.fs.clone(),
@@ -460,46 +447,41 @@ impl AssistantPanel {
)
});
- self.show_conversation(editor.clone(), cx);
+ self.show_context(editor.clone(), cx);
Some(editor)
}
- fn show_conversation(
- &mut self,
- conversation_editor: View<ConversationEditor>,
- cx: &mut ViewContext<Self>,
- ) {
+ fn show_context(&mut self, context_editor: View<ContextEditor>, cx: &mut ViewContext<Self>) {
let mut subscriptions = Vec::new();
- subscriptions
- .push(cx.subscribe(&conversation_editor, Self::handle_conversation_editor_event));
+ subscriptions.push(cx.subscribe(&context_editor, Self::handle_context_editor_event));
- let conversation = conversation_editor.read(cx).conversation.clone();
- subscriptions.push(cx.observe(&conversation, |_, _, cx| cx.notify()));
+ let context = context_editor.read(cx).context.clone();
+ subscriptions.push(cx.observe(&context, |_, _, cx| cx.notify()));
- let editor = conversation_editor.read(cx).editor.clone();
+ let editor = context_editor.read(cx).editor.clone();
self.toolbar.update(cx, |toolbar, cx| {
toolbar.set_active_item(Some(&editor), cx);
});
if self.focus_handle.contains_focused(cx) {
cx.focus_view(&editor);
}
- self.active_conversation_editor = Some(ActiveConversationEditor {
- editor: conversation_editor,
+ self.active_context_editor = Some(ActiveContextEditor {
+ editor: context_editor,
_subscriptions: subscriptions,
});
- self.show_saved_conversations = false;
+ self.show_saved_contexts = false;
cx.notify();
}
- fn handle_conversation_editor_event(
+ fn handle_context_editor_event(
&mut self,
- _: View<ConversationEditor>,
- event: &ConversationEditorEvent,
+ _: View<ContextEditor>,
+ event: &ContextEditorEvent,
cx: &mut ViewContext<Self>,
) {
match event {
- ConversationEditorEvent::TabContentChanged => cx.notify(),
+ ContextEditorEvent::TabContentChanged => cx.notify(),
}
}
@@ -512,7 +494,7 @@ impl AssistantPanel {
}
fn toggle_history(&mut self, _: &ToggleHistory, cx: &mut ViewContext<Self>) {
- if self.show_saved_conversations {
+ if self.show_saved_contexts {
self.hide_history(cx);
} else {
self.show_history(cx);
@@ -520,17 +502,17 @@ impl AssistantPanel {
}
fn show_history(&mut self, cx: &mut ViewContext<Self>) {
- cx.focus_view(&self.saved_conversation_picker);
- if !self.show_saved_conversations {
- self.show_saved_conversations = true;
+ cx.focus_view(&self.saved_context_picker);
+ if !self.show_saved_contexts {
+ self.show_saved_contexts = true;
cx.notify();
}
}
fn hide_history(&mut self, cx: &mut ViewContext<Self>) {
- if let Some(editor) = self.active_conversation_editor() {
+ if let Some(editor) = self.active_context_editor() {
cx.focus_view(&editor);
- self.show_saved_conversations = false;
+ self.show_saved_contexts = false;
cx.notify();
}
}
@@ -590,24 +572,19 @@ impl AssistantPanel {
}
fn insert_command(&mut self, name: &str, cx: &mut ViewContext<Self>) {
- if let Some(conversation_editor) = self.active_conversation_editor() {
- conversation_editor.update(cx, |conversation_editor, cx| {
- conversation_editor.insert_command(name, cx)
+ if let Some(context_editor) = self.active_context_editor() {
+ context_editor.update(cx, |context_editor, cx| {
+ context_editor.insert_command(name, cx)
});
}
}
- fn active_conversation_editor(&self) -> Option<&View<ConversationEditor>> {
- Some(&self.active_conversation_editor.as_ref()?.editor)
+ fn active_context_editor(&self) -> Option<&View<ContextEditor>> {
+ Some(&self.active_context_editor.as_ref()?.editor)
}
- pub fn active_conversation(&self, cx: &AppContext) -> Option<Model<Conversation>> {
- Some(
- self.active_conversation_editor()?
- .read(cx)
- .conversation
- .clone(),
- )
+ pub fn active_context(&self, cx: &AppContext) -> Option<Model<Context>> {
+ Some(self.active_context_editor()?.read(cx).context.clone())
}
fn render_popover_button(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
@@ -708,30 +685,28 @@ impl AssistantPanel {
}
fn render_send_button(&self, cx: &mut ViewContext<Self>) -> Option<impl IntoElement> {
- self.active_conversation_editor
- .as_ref()
- .map(|conversation| {
- let focus_handle = conversation.editor.focus_handle(cx);
- ButtonLike::new("send_button")
- .style(ButtonStyle::Filled)
- .layer(ElevationIndex::ModalSurface)
- .children(
- KeyBinding::for_action_in(&Assist, &focus_handle, cx)
- .map(|binding| binding.into_any_element()),
- )
- .child(Label::new("Send"))
- .on_click(cx.listener(|this, _event, cx| {
- if let Some(active_editor) = this.active_conversation_editor() {
- active_editor.update(cx, |editor, cx| editor.assist(&Assist, cx));
- }
- }))
- })
+ self.active_context_editor.as_ref().map(|context| {
+ let focus_handle = context.editor.focus_handle(cx);
+ ButtonLike::new("send_button")
+ .style(ButtonStyle::Filled)
+ .layer(ElevationIndex::ModalSurface)
+ .children(
+ KeyBinding::for_action_in(&Assist, &focus_handle, cx)
+ .map(|binding| binding.into_any_element()),
+ )
+ .child(Label::new("Send"))
+ .on_click(cx.listener(|this, _event, cx| {
+ if let Some(active_editor) = this.active_context_editor() {
+ active_editor.update(cx, |editor, cx| editor.assist(&Assist, cx));
+ }
+ }))
+ })
}
- fn open_conversation(&mut self, path: PathBuf, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
+ fn open_context(&mut self, path: PathBuf, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
cx.focus(&self.focus_handle);
- let saved_conversation = self.conversation_store.read(cx).load(path.clone(), cx);
+ let saved_context = self.context_store.read(cx).load(path.clone(), cx);
let fs = self.fs.clone();
let workspace = self.workspace.clone();
let slash_commands = self.slash_commands.clone();
@@ -746,9 +721,9 @@ impl AssistantPanel {
.flatten();
cx.spawn(|this, mut cx| async move {
- let saved_conversation = saved_conversation.await?;
- let conversation = Conversation::deserialize(
- saved_conversation,
+ let saved_context = saved_context.await?;
+ let context = Context::deserialize(
+ saved_context,
path.clone(),
languages,
slash_commands,
@@ -762,15 +737,9 @@ impl AssistantPanel {
.upgrade()
.ok_or_else(|| anyhow!("workspace dropped"))?;
let editor = cx.new_view(|cx| {
- ConversationEditor::for_conversation(
- conversation,
- fs,
- workspace,
- lsp_adapter_delegate,
- cx,
- )
+ ContextEditor::for_context(context, fs, workspace, lsp_adapter_delegate, cx)
});
- this.show_conversation(editor, cx);
+ this.show_context(editor, cx);
anyhow::Ok(())
})??;
Ok(())
@@ -788,7 +757,7 @@ impl AssistantPanel {
fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let header = TabBar::new("assistant_header")
.start_child(h_flex().gap_1().child(self.render_popover_button(cx)))
- .children(self.active_conversation_editor().map(|editor| {
+ .children(self.active_context_editor().map(|editor| {
h_flex()
.h(rems(Tab::CONTAINER_HEIGHT_IN_REMS))
.flex_1()
@@ -804,8 +773,8 @@ impl AssistantPanel {
.end_child(
h_flex()
.gap_2()
- .when_some(self.active_conversation_editor(), |this, editor| {
- let conversation = editor.read(cx).conversation.clone();
+ .when_some(self.active_context_editor(), |this, editor| {
+ let context = editor.read(cx).context.clone();
this.child(
h_flex()
.gap_1()
@@ -813,7 +782,7 @@ impl AssistantPanel {
self.model_menu_handle.clone(),
self.fs.clone(),
))
- .children(self.render_remaining_tokens(&conversation, cx)),
+ .children(self.render_remaining_tokens(&context, cx)),
)
.child(
ui::Divider::vertical()
@@ -840,7 +809,7 @@ impl AssistantPanel {
),
);
- let contents = if self.active_conversation_editor().is_some() {
+ let contents = if self.active_context_editor().is_some() {
let mut registrar = DivRegistrar::new(
|panel, cx| panel.toolbar.read(cx).item_of_type::<BufferSearchBar>(),
cx,
@@ -855,7 +824,7 @@ impl AssistantPanel {
.key_context("AssistantPanel")
.size_full()
.on_action(cx.listener(|this, _: &workspace::NewFile, cx| {
- this.new_conversation(cx);
+ this.new_context(cx);
}))
.on_action(cx.listener(AssistantPanel::toggle_zoom))
.on_action(cx.listener(AssistantPanel::toggle_history))
@@ -873,12 +842,12 @@ impl AssistantPanel {
Some(self.toolbar.clone())
})
.child(contents.flex_1().child(
- if self.show_saved_conversations || self.active_conversation_editor().is_none() {
+ if self.show_saved_contexts || self.active_context_editor().is_none() {
div()
.size_full()
- .child(self.saved_conversation_picker.clone())
+ .child(self.saved_context_picker.clone())
.into_any_element()
- } else if let Some(editor) = self.active_conversation_editor() {
+ } else if let Some(editor) = self.active_context_editor() {
let editor = editor.clone();
div()
.size_full()
@@ -901,10 +870,10 @@ impl AssistantPanel {
fn render_remaining_tokens(
&self,
- conversation: &Model<Conversation>,
+ context: &Model<Context>,
cx: &mut ViewContext<Self>,
) -> Option<impl IntoElement> {
- let remaining_tokens = conversation.read(cx).remaining_tokens(cx)?;
+ let remaining_tokens = context.read(cx).remaining_tokens(cx)?;
let remaining_tokens_color = if remaining_tokens <= 0 {
Color::Error
} else if remaining_tokens <= 500 {
@@ -991,8 +960,8 @@ impl Panel for AssistantPanel {
cx.spawn(|this, mut cx| async move {
load_credentials.await?;
this.update(&mut cx, |this, cx| {
- if this.is_authenticated(cx) && this.active_conversation_editor().is_none() {
- this.new_conversation(cx);
+ if this.is_authenticated(cx) && this.active_context_editor().is_none() {
+ this.new_context(cx);
}
})
})
@@ -1027,7 +996,7 @@ impl FocusableView for AssistantPanel {
}
#[derive(Clone)]
-enum ConversationEvent {
+enum ContextEvent {
MessagesEdited,
SummaryChanged,
EditSuggestionsChanged,
@@ -1049,7 +1018,7 @@ struct Summary {
done: bool,
}
-pub struct Conversation {
+pub struct Context {
id: Option<String>,
buffer: Model<Buffer>,
edit_suggestions: Vec<EditSuggestion>,
@@ -1073,9 +1042,9 @@ pub struct Conversation {
language_registry: Arc<LanguageRegistry>,
}
-impl EventEmitter<ConversationEvent> for Conversation {}
+impl EventEmitter<ContextEvent> for Context {}
-impl Conversation {
+impl Context {
fn new(
language_registry: Arc<LanguageRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
@@ -1131,11 +1100,11 @@ impl Conversation {
this
}
- fn serialize(&self, cx: &AppContext) -> SavedConversation {
- SavedConversation {
+ fn serialize(&self, cx: &AppContext) -> SavedContext {
+ SavedContext {
id: self.id.clone(),
- zed: "conversation".into(),
- version: SavedConversation::VERSION.into(),
+ zed: "context".into(),
+ version: SavedContext::VERSION.into(),
text: self.buffer.read(cx).text(),
message_metadata: self.messages_metadata.clone(),
messages: self
@@ -1155,14 +1124,14 @@ impl Conversation {
#[allow(clippy::too_many_arguments)]
async fn deserialize(
- saved_conversation: SavedConversation,
+ saved_context: SavedContext,
path: PathBuf,
language_registry: Arc<LanguageRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
telemetry: Option<Arc<Telemetry>>,
cx: &mut AsyncAppContext,
) -> Result<Model<Self>> {
- let id = match saved_conversation.id {
+ let id = match saved_context.id {
Some(id) => Some(id),
None => Some(Uuid::new_v4().to_string()),
};
@@ -1171,8 +1140,8 @@ impl Conversation {
let mut message_anchors = Vec::new();
let mut next_message_id = MessageId(0);
let buffer = cx.new_model(|cx| {
- let mut buffer = Buffer::local(saved_conversation.text, cx);
- for message in saved_conversation.messages {
+ let mut buffer = Buffer::local(saved_context.text, cx);
+ for message in saved_context.messages {
message_anchors.push(MessageAnchor {
id: message.id,
start: buffer.anchor_before(message.start),
@@ -1197,13 +1166,13 @@ impl Conversation {
let mut this = Self {
id,
message_anchors,
- messages_metadata: saved_conversation.message_metadata,
+ messages_metadata: saved_context.message_metadata,
next_message_id,
edit_suggestions: Vec::new(),
pending_slash_commands: Vec::new(),
edits_since_last_slash_command_parse,
summary: Some(Summary {
- text: saved_conversation.summary,
+ text: saved_context.summary,
done: true,
}),
pending_summary: Task::ready(None),
@@ -1249,7 +1218,7 @@ impl Conversation {
self.count_remaining_tokens(cx);
self.reparse_edit_suggestions(cx);
self.reparse_slash_commands(cx);
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
}
}
@@ -1346,7 +1315,7 @@ impl Conversation {
}
if !updated.is_empty() || !removed.is_empty() {
- cx.emit(ConversationEvent::PendingSlashCommandsUpdated { removed, updated });
+ cx.emit(ContextEvent::PendingSlashCommandsUpdated { removed, updated });
}
}
@@ -1405,7 +1374,7 @@ impl Conversation {
self.edit_suggestions
.splice(start_ix..end_ix, new_edit_suggestions);
});
- cx.emit(ConversationEvent::EditSuggestionsChanged);
+ cx.emit(ContextEvent::EditSuggestionsChanged);
cx.notify();
}
@@ -1499,7 +1468,7 @@ impl Conversation {
})
.collect::<Vec<_>>();
sections.sort_by(|a, b| a.range.cmp(&b.range, buffer));
- ConversationEvent::SlashCommandFinished {
+ ContextEvent::SlashCommandFinished {
output_range: buffer.anchor_after(start)
..buffer.anchor_before(new_end),
sections,
@@ -1514,7 +1483,7 @@ impl Conversation {
{
pending_command.status =
PendingSlashCommandStatus::Error(error.to_string());
- cx.emit(ConversationEvent::PendingSlashCommandsUpdated {
+ cx.emit(ContextEvent::PendingSlashCommandsUpdated {
removed: vec![pending_command.source_range.clone()],
updated: vec![pending_command.clone()],
});
@@ -1529,7 +1498,7 @@ impl Conversation {
pending_command.status = PendingSlashCommandStatus::Running {
_task: insert_output_task.shared(),
};
- cx.emit(ConversationEvent::PendingSlashCommandsUpdated {
+ cx.emit(ContextEvent::PendingSlashCommandsUpdated {
removed: vec![pending_command.source_range.clone()],
updated: vec![pending_command.clone()],
});
@@ -1644,7 +1613,7 @@ impl Conversation {
message_start_offset..message_new_end_offset
});
this.reparse_edit_suggestions_in_range(message_range, cx);
- cx.emit(ConversationEvent::StreamedCompletion);
+ cx.emit(ContextEvent::StreamedCompletion);
Some(())
})?;
@@ -1687,7 +1656,7 @@ impl Conversation {
);
}
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
}
})
.ok();
@@ -1725,7 +1694,7 @@ impl Conversation {
for id in ids {
if let Some(metadata) = self.messages_metadata.get_mut(&id) {
metadata.role.cycle();
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
cx.notify();
}
}
@@ -1768,7 +1737,7 @@ impl Conversation {
.insert(next_message_ix, message.clone());
self.messages_metadata
.insert(message.id, MessageMetadata { role, status });
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
Some(message)
} else {
None
@@ -1846,7 +1815,7 @@ impl Conversation {
}
let selection = if let Some(prefix_end) = prefix_end {
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
MessageAnchor {
id: MessageId(post_inc(&mut self.next_message_id.0)),
start: self.buffer.read(cx).anchor_before(prefix_end),
@@ -1875,7 +1844,7 @@ impl Conversation {
};
if !edited_buffer {
- cx.emit(ConversationEvent::MessagesEdited);
+ cx.emit(ContextEvent::MessagesEdited);
}
new_messages
} else {
@@ -1894,8 +1863,7 @@ impl Conversation {
.map(|message| message.to_request_message(self.buffer.read(cx)))
.chain(Some(LanguageModelRequestMessage {
role: Role::User,
- content: "Summarize the conversation into a short title without punctuation."
- .into(),
+ content: "Summarize the context into a short title without punctuation.".into(),
}));
let request = LanguageModelRequest {
model: CompletionProvider::global(cx).model(),
@@ -1915,7 +1883,7 @@ impl Conversation {
this.update(&mut cx, |this, cx| {
let summary = this.summary.get_or_insert(Default::default());
summary.text.extend(lines.next());
- cx.emit(ConversationEvent::SummaryChanged);
+ cx.emit(ContextEvent::SummaryChanged);
})?;
// Stop if the LLM generated multiple lines.
@@ -1927,7 +1895,7 @@ impl Conversation {
this.update(&mut cx, |this, cx| {
if let Some(summary) = this.summary.as_mut() {
summary.done = true;
- cx.emit(ConversationEvent::SummaryChanged);
+ cx.emit(ContextEvent::SummaryChanged);
}
})?;
@@ -2014,7 +1982,7 @@ impl Conversation {
&mut self,
debounce: Option<Duration>,
fs: Arc<dyn Fs>,
- cx: &mut ModelContext<Conversation>,
+ cx: &mut ModelContext<Context>,
) {
self.pending_save = cx.spawn(|this, mut cx| async move {
if let Some(debounce) = debounce {
@@ -2036,14 +2004,14 @@ impl Conversation {
})?;
if let Some(summary) = summary {
- let conversation = this.read_with(&cx, |this, cx| this.serialize(cx))?;
+ let context = this.read_with(&cx, |this, cx| this.serialize(cx))?;
let path = if let Some(old_path) = old_path {
old_path
} else {
let mut discriminant = 1;
let mut new_path;
loop {
- new_path = CONVERSATIONS_DIR.join(&format!(
+ new_path = CONTEXTS_DIR.join(&format!(
"{} - {}.zed.json",
summary.trim(),
discriminant
@@ -2057,8 +2025,8 @@ impl Conversation {
new_path
};
- fs.create_dir(CONVERSATIONS_DIR.as_ref()).await?;
- fs.atomic_write(path.clone(), serde_json::to_string(&conversation).unwrap())
+ fs.create_dir(CONTEXTS_DIR.as_ref()).await?;
+ fs.atomic_write(path.clone(), serde_json::to_string(&context).unwrap())
.await?;
this.update(&mut cx, |this, _| this.path = Some(path))?;
}
@@ -2181,7 +2149,7 @@ struct PendingCompletion {
_task: Task<()>,
}
-enum ConversationEditorEvent {
+enum ContextEditorEvent {
TabContentChanged,
}
@@ -2191,8 +2159,8 @@ struct ScrollPosition {
cursor: Anchor,
}
-pub struct ConversationEditor {
- conversation: Model<Conversation>,
+pub struct ContextEditor {
+ context: Model<Context>,
fs: Arc<dyn Fs>,
workspace: WeakView<Workspace>,
slash_command_registry: Arc<SlashCommandRegistry>,
@@ -2204,7 +2172,7 @@ pub struct ConversationEditor {
_subscriptions: Vec<Subscription>,
}
-impl ConversationEditor {
+impl ContextEditor {
fn new(
language_registry: Arc<LanguageRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
@@ -2216,8 +2184,8 @@ impl ConversationEditor {
let project = workspace.read(cx).project().clone();
let lsp_adapter_delegate = make_lsp_adapter_delegate(&project, cx).log_err();
- let conversation = cx.new_model(|cx| {
- Conversation::new(
+ let context = cx.new_model(|cx| {
+ Context::new(
language_registry,
slash_command_registry,
Some(telemetry),
@@ -2225,20 +2193,19 @@ impl ConversationEditor {
)
});
- let mut this =
- Self::for_conversation(conversation, fs, workspace, lsp_adapter_delegate, cx);
+ let mut this = Self::for_context(context, fs, workspace, lsp_adapter_delegate, cx);
this.insert_default_prompt(cx);
this
}
- fn for_conversation(
- conversation: Model<Conversation>,
+ fn for_context(
+ context: Model<Context>,
fs: Arc<dyn Fs>,
workspace: View<Workspace>,
lsp_adapter_delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut ViewContext<Self>,
) -> Self {
- let slash_command_registry = conversation.read(cx).slash_command_registry.clone();
+ let slash_command_registry = context.read(cx).slash_command_registry.clone();
let completion_provider = SlashCommandCompletionProvider::new(
slash_command_registry.clone(),
@@ -2247,7 +2214,7 @@ impl ConversationEditor {
);
let editor = cx.new_view(|cx| {
- let mut editor = Editor::for_buffer(conversation.read(cx).buffer.clone(), None, cx);
+ let mut editor = Editor::for_buffer(context.read(cx).buffer.clone(), None, cx);
editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx);
editor.set_show_line_numbers(false, cx);
editor.set_show_git_diff_gutter(false, cx);
@@ -2259,13 +2226,13 @@ impl ConversationEditor {
});
let _subscriptions = vec![
- cx.observe(&conversation, |_, _, cx| cx.notify()),
- cx.subscribe(&conversation, Self::handle_conversation_event),
+ cx.observe(&context, |_, _, cx| cx.notify()),
+ cx.subscribe(&context, Self::handle_context_event),
cx.subscribe(&editor, Self::handle_editor_event),
];
let mut this = Self {
- conversation,
+ context,
editor,
slash_command_registry,
lsp_adapter_delegate,
@@ -2286,14 +2253,14 @@ impl ConversationEditor {
editor.insert(&format!("/{command_name}"), cx)
});
self.split(&Split, cx);
- let command = self.conversation.update(cx, |conversation, cx| {
- conversation
+ let command = self.context.update(cx, |context, cx| {
+ context
.messages_metadata
.get_mut(&MessageId::default())
.unwrap()
.role = Role::System;
- conversation.reparse_slash_commands(cx);
- conversation.pending_slash_commands[0].clone()
+ context.reparse_slash_commands(cx);
+ context.pending_slash_commands[0].clone()
});
self.run_command(