Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add `#[track_caller]` to gpui foreground executor spawn methods (#24103)

Michael Sloan691de6b4b36d
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs
index 828836efadd..1408f44a939 100644
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@ -1040,6 +1040,7 @@ impl App {
/// Spawns the future returned by the given function on the thread pool. The closure will be invoked
/// with [AsyncApp], which allows the application state to be accessed across await points.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs
index 3e8f5cdd914..2375180e6f5 100644
--- a/crates/gpui/src/app/async_context.rs
+++ b/crates/gpui/src/app/async_context.rs
@@ -172,6 +172,7 @@ impl AsyncApp {
}
/// Schedule a future to be polled in the background.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
@@ -297,6 +298,7 @@ impl AsyncWindowContext {
/// Schedule a future to be executed on the main thread. This is used for collecting
/// the results of background tasks and updating the UI.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
diff --git a/crates/gpui/src/app/context.rs b/crates/gpui/src/app/context.rs
index 5e892a6505a..31f17cd9c89 100644
--- a/crates/gpui/src/app/context.rs
+++ b/crates/gpui/src/app/context.rs
@@ -183,6 +183,7 @@ impl<'a, T: 'static> Context<'a, T> {
/// Spawn the future returned by the given function.
/// The function is provided a weak handle to the entity owned by this context and a context that can be held across await points.
/// The returned task must be held or detached.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, f: impl FnOnce(WeakEntity<T>, AsyncApp) -> Fut) -> Task<R>
where
T: 'static,
@@ -583,6 +584,7 @@ impl<'a, T: 'static> Context<'a, T> {
/// The given callback is invoked with a [`WeakEntity<V>`] to avoid leaking the view for a long-running process.
/// It's also given an [`AsyncWindowContext`], which can be used to access the state of the view across await points.
/// The returned future will be polled on the main thread.
+ #[track_caller]
pub fn spawn_in<Fut, R>(
&self,
window: &Window,
diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs
index b14e572b505..7ad7623d33f 100644
--- a/crates/gpui/src/app/test_context.rs
+++ b/crates/gpui/src/app/test_context.rs
@@ -317,6 +317,7 @@ impl TestAppContext {
}
/// Run the given task on the main thread.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task<R>
where
Fut: Future<Output = R> + 'static,
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index 19254d280d1..ffedaadb07f 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -1307,6 +1307,7 @@ impl Window {
/// Spawn the future returned by the given closure on the application thread pool.
/// The closure is provided a handle to the current window and an `AsyncWindowContext` for
/// use within your future.
+ #[track_caller]
pub fn spawn<Fut, R>(&self, cx: &App, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task<R>
where
R: 'static,