agent2: Port rules UI (#36429)

Release Notes:

- N/A
This commit is contained in:
Bennet Bo Fenner 2025-08-19 11:12:57 +02:00 committed by GitHub
parent ed14ab8c02
commit b8ddb0141c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 197 additions and 32 deletions

View file

@ -22,7 +22,6 @@ use prompt_store::{
};
use settings::update_settings_file;
use std::any::Any;
use std::cell::RefCell;
use std::collections::HashMap;
use std::path::Path;
use std::rc::Rc;
@ -156,7 +155,7 @@ pub struct NativeAgent {
/// Session ID -> Session mapping
sessions: HashMap<acp::SessionId, Session>,
/// Shared project context for all threads
project_context: Rc<RefCell<ProjectContext>>,
project_context: Entity<ProjectContext>,
project_context_needs_refresh: watch::Sender<()>,
_maintain_project_context: Task<Result<()>>,
context_server_registry: Entity<ContextServerRegistry>,
@ -200,7 +199,7 @@ impl NativeAgent {
watch::channel(());
Self {
sessions: HashMap::new(),
project_context: Rc::new(RefCell::new(project_context)),
project_context: cx.new(|_| project_context),
project_context_needs_refresh: project_context_needs_refresh_tx,
_maintain_project_context: cx.spawn(async move |this, cx| {
Self::maintain_project_context(this, project_context_needs_refresh_rx, cx).await
@ -233,7 +232,9 @@ impl NativeAgent {
Self::build_project_context(&this.project, this.prompt_store.as_ref(), cx)
})?
.await;
this.update(cx, |this, _| this.project_context.replace(project_context))?;
this.update(cx, |this, cx| {
this.project_context = cx.new(|_| project_context);
})?;
}
Ok(())
@ -872,8 +873,8 @@ mod tests {
)
.await
.unwrap();
agent.read_with(cx, |agent, _| {
assert_eq!(agent.project_context.borrow().worktrees, vec![])
agent.read_with(cx, |agent, cx| {
assert_eq!(agent.project_context.read(cx).worktrees, vec![])
});
let worktree = project
@ -881,9 +882,9 @@ mod tests {
.await
.unwrap();
cx.run_until_parked();
agent.read_with(cx, |agent, _| {
agent.read_with(cx, |agent, cx| {
assert_eq!(
agent.project_context.borrow().worktrees,
agent.project_context.read(cx).worktrees,
vec![WorktreeContext {
root_name: "a".into(),
abs_path: Path::new("/a").into(),
@ -898,7 +899,7 @@ mod tests {
agent.read_with(cx, |agent, cx| {
let rules_entry = worktree.read(cx).entry_for_path(".rules").unwrap();
assert_eq!(
agent.project_context.borrow().worktrees,
agent.project_context.read(cx).worktrees,
vec![WorktreeContext {
root_name: "a".into(),
abs_path: Path::new("/a").into(),