Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Fix project context on first thread (#51868)
Ben Brandtc932aa9f5b8f
diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rsindex 140c872ecac..5a3b1710d18 100644--- a/crates/agent/src/agent.rs+++ b/crates/agent/src/agent.rs@@ -493,8 +493,12 @@ impl NativeAgent {})??.await;this.update(cx, |this, cx| {- if let Some(state) = this.projects.get_mut(&project_id) {- state.project_context = cx.new(|_| project_context);+ if let Some(state) = this.projects.get(&project_id) {+ state+ .project_context+ .update(cx, |current_project_context, _cx| {+ *current_project_context = project_context;+ });}})?;}@@ -2131,10 +2135,15 @@ mod internal_tests {.unwrap();cx.run_until_parked();+ let thread = agent.read_with(cx, |agent, _cx| {+ agent.sessions.values().next().unwrap().thread.clone()+ });+agent.read_with(cx, |agent, cx| {let project_id = project.entity_id();let state = agent.projects.get(&project_id).unwrap();- assert_eq!(state.project_context.read(cx).worktrees, vec![])+ assert_eq!(state.project_context.read(cx).worktrees, vec![]);+ assert_eq!(thread.read(cx).project_context().read(cx).worktrees, vec![]);});let worktree = project@@ -2145,14 +2154,16 @@ mod internal_tests {agent.read_with(cx, |agent, cx| {let project_id = project.entity_id();let state = agent.projects.get(&project_id).unwrap();+ let expected_worktrees = vec![WorktreeContext {+ root_name: "a".into(),+ abs_path: Path::new("/a").into(),+ rules_file: None,+ }];+ assert_eq!(state.project_context.read(cx).worktrees, expected_worktrees);assert_eq!(- state.project_context.read(cx).worktrees,- vec![WorktreeContext {- root_name: "a".into(),- abs_path: Path::new("/a").into(),- rules_file: None- }]- )+ thread.read(cx).project_context().read(cx).worktrees,+ expected_worktrees+ );});// Creating `/a/.rules` updates the project context.@@ -2165,18 +2176,20 @@ mod internal_tests {.read(cx).entry_for_path(rel_path(".rules")).unwrap();+ let expected_worktrees = vec![WorktreeContext {+ root_name: "a".into(),+ abs_path: Path::new("/a").into(),+ rules_file: Some(RulesFileContext {+ path_in_worktree: rel_path(".rules").into(),+ text: "".into(),+ project_entry_id: rules_entry.id.to_usize(),+ }),+ }];+ assert_eq!(state.project_context.read(cx).worktrees, expected_worktrees);assert_eq!(- state.project_context.read(cx).worktrees,- vec![WorktreeContext {- root_name: "a".into(),- abs_path: Path::new("/a").into(),- rules_file: Some(RulesFileContext {- path_in_worktree: rel_path(".rules").into(),- text: "".into(),- project_entry_id: rules_entry.id.to_usize()- })- }]- )+ thread.read(cx).project_context().read(cx).worktrees,+ expected_worktrees+ );});}