assistant_tool: Pass an Entity<Project> to Tool::run (#26312)

This PR updates the `Tool::run` method to take an `Entity<Project>`
instead of a `WeakEntity<Project>`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2025-03-07 23:30:56 +00:00
committed by GitHub
parent 921c24e274
commit e70d0edfac
7 changed files with 20 additions and 30 deletions
@@ -1,8 +1,8 @@
use std::sync::Arc;
use anyhow::{anyhow, Result};
use anyhow::Result;
use assistant_tool::Tool;
use gpui::{App, Task, WeakEntity};
use gpui::{App, Entity, Task};
use project::Project;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -34,13 +34,9 @@ impl Tool for ListWorktreesTool {
fn run(
self: Arc<Self>,
_input: serde_json::Value,
project: WeakEntity<Project>,
project: Entity<Project>,
cx: &mut App,
) -> Task<Result<String>> {
let Some(project) = project.upgrade() else {
return Task::ready(Err(anyhow!("project dropped")));
};
cx.spawn(|cx| async move {
cx.update(|cx| {
#[derive(Debug, Serialize)]
+2 -2
View File
@@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{anyhow, Result};
use assistant_tool::Tool;
use chrono::{Local, Utc};
use gpui::{App, Task, WeakEntity};
use gpui::{App, Entity, Task};
use project::Project;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -42,7 +42,7 @@ impl Tool for NowTool {
fn run(
self: Arc<Self>,
input: serde_json::Value,
_project: WeakEntity<Project>,
_project: Entity<Project>,
_cx: &mut App,
) -> Task<Result<String>> {
let input: NowToolInput = match serde_json::from_value(input) {
+2 -6
View File
@@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{anyhow, Result};
use assistant_tool::Tool;
use gpui::{App, Task, WeakEntity};
use gpui::{App, Entity, Task};
use project::{Project, ProjectPath, WorktreeId};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -37,13 +37,9 @@ impl Tool for ReadFileTool {
fn run(
self: Arc<Self>,
input: serde_json::Value,
project: WeakEntity<Project>,
project: Entity<Project>,
cx: &mut App,
) -> Task<Result<String>> {
let Some(project) = project.upgrade() else {
return Task::ready(Err(anyhow!("project dropped")));
};
let input = match serde_json::from_value::<ReadFileToolInput>(input) {
Ok(input) => input,
Err(err) => return Task::ready(Err(anyhow!(err))),