Skip to content

Commit 984dbdd

Browse files
authored
Organize chats by projects (#92)
1 parent ad8451b commit 984dbdd

13 files changed

Lines changed: 665 additions & 451 deletions

File tree

crates/code_assistant/src/app/gpui.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ pub fn run(config: AgentRunConfig) -> Result<()> {
2222

2323
let session_config_template = SessionConfig {
2424
init_path: Some(root_path.clone()),
25-
initial_project: String::new(),
25+
initial_project: root_path
26+
.file_name()
27+
.and_then(|name| name.to_str())
28+
.unwrap_or("unknown")
29+
.to_string(),
2630
tool_syntax: config.tool_syntax,
2731
use_diff_blocks: config.use_diff_format,
2832
sandbox_policy: config.sandbox_policy.clone(),

crates/code_assistant/src/session/manager.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ impl SessionManager {
7070
}
7171
}
7272

73+
/// Returns the session config template.
74+
pub fn session_config_template(&self) -> &SessionConfig {
75+
&self.session_config_template
76+
}
77+
7378
/// Create a new session and return its ID
7479
pub fn create_session(&mut self, name: Option<String>) -> Result<String> {
7580
// Always create sessions with a default model config

crates/code_assistant/src/ui/backend.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ pub enum BackendEvent {
2020
LoadSession {
2121
session_id: String,
2222
},
23+
2324
CreateNewSession {
2425
name: Option<String>,
26+
initial_project: Option<String>,
2527
},
2628
DeleteSession {
2729
session_id: String,
@@ -161,9 +163,10 @@ pub async fn handle_backend_events(
161163
let response = match event {
162164
BackendEvent::ListSessions => Some(handle_list_sessions(&multi_session_manager).await),
163165

164-
BackendEvent::CreateNewSession { name } => {
165-
Some(handle_create_session(&multi_session_manager, name).await)
166-
}
166+
BackendEvent::CreateNewSession {
167+
name,
168+
initial_project,
169+
} => Some(handle_create_session(&multi_session_manager, name, initial_project).await),
167170

168171
BackendEvent::LoadSession { session_id } => {
169172
handle_load_session(&multi_session_manager, &session_id, &ui).await
@@ -275,10 +278,18 @@ async fn handle_list_sessions(
275278
async fn handle_create_session(
276279
multi_session_manager: &Arc<Mutex<SessionManager>>,
277280
name: Option<String>,
281+
initial_project: Option<String>,
278282
) -> BackendResponse {
279283
let create_result = {
280284
let mut manager = multi_session_manager.lock().await;
281-
manager.create_session(name.clone())
285+
if let Some(project) = initial_project {
286+
// Create a session config override with the specified project
287+
let mut config = manager.session_config_template().clone();
288+
config.initial_project = project;
289+
manager.create_session_with_config(name.clone(), Some(config), None)
290+
} else {
291+
manager.create_session(name.clone())
292+
}
282293
};
283294

284295
match create_result {

crates/code_assistant/src/ui/gpui/attachment.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::file_icons;
22
use super::image;
33
use crate::persistence::DraftAttachment;
4+
45
use gpui::{
5-
div, img, prelude::*, px, Context, FocusHandle, Focusable, ImageSource, InteractiveElement,
6-
MouseButton, ObjectFit, SharedString, Window,
6+
div, img, prelude::*, px, ClickEvent, Context, FocusHandle, Focusable, ImageSource,
7+
InteractiveElement, ObjectFit, SharedString, Window,
78
};
89
use gpui_component::ActiveTheme;
910

@@ -142,6 +143,7 @@ impl Render for AttachmentView {
142143
container.child(
143144
// Remove button - only visible on hover
144145
div()
146+
.id("remove-attachment-btn")
145147
.absolute()
146148
.top(px(4.))
147149
.right(px(4.))
@@ -158,13 +160,9 @@ impl Render for AttachmentView {
158160
cx.theme().danger,
159161
"🗑",
160162
))
161-
.on_mouse_up(
162-
MouseButton::Left,
163-
cx.listener(move |_view, _event, _window, cx| {
164-
// Emit a custom event that the parent can listen to
165-
cx.emit(AttachmentEvent::Remove(index));
166-
}),
167-
),
163+
.on_click(cx.listener(move |_view, _event: &ClickEvent, _window, cx| {
164+
cx.emit(AttachmentEvent::Remove(index));
165+
})),
168166
)
169167
})
170168
}

crates/code_assistant/src/ui/gpui/branch_switcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::persistence::BranchInfo;
2-
use gpui::{div, prelude::*, px, App, CursorStyle, MouseButton, SharedString, Window};
2+
use gpui::{div, prelude::*, px, App, CursorStyle, SharedString, Window};
33
use gpui_component::{ActiveTheme, Icon};
44

55
/// A stateless branch navigation component styled as a bubble on the message border.
@@ -93,7 +93,7 @@ impl RenderOnce for BranchSwitcherElement {
9393

9494
if has_prev {
9595
base.hover(|s| s.bg(cx.theme().accent.opacity(0.15)))
96-
.on_mouse_up(MouseButton::Left, move |_event, _window, cx| {
96+
.on_click(move |_event, _window, cx| {
9797
if let Some(node_id) = prev_node_id {
9898
if let Some(sender) =
9999
cx.try_global::<super::UiEventSender>()
@@ -141,7 +141,7 @@ impl RenderOnce for BranchSwitcherElement {
141141

142142
if has_next {
143143
base.hover(|s| s.bg(cx.theme().accent.opacity(0.25)))
144-
.on_mouse_up(MouseButton::Left, move |_event, _window, cx| {
144+
.on_click(move |_event, _window, cx| {
145145
if let Some(node_id) = next_node_id {
146146
if let Some(sender) =
147147
cx.try_global::<super::UiEventSender>()

0 commit comments

Comments
 (0)