Move "async move" a few characters to the left in cx.spawn() (#26758)

This is the core change:
https://github.com/zed-industries/zed/pull/26758/files#diff-044302c0d57147af17e68a0009fee3e8dcdfb4f32c27a915e70cfa80e987f765R1052

TODO:
- [x] Use AsyncFn instead of Fn() -> Future in GPUI spawn methods
- [x] Implement it in the whole app
- [x] Implement it in the debugger 
- [x] Glance at the RPC crate, and see if those box future methods can
be switched over. Answer: It can't directly, as you can't make an
AsyncFn* into a trait object. There's ways around that, but they're all
more complex than just keeping the code as is.
- [ ] Fix platform specific code

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-03-18 19:09:02 -07:00 committed by GitHub
parent 7f2e3fb5bd
commit 1aefa5178b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
256 changed files with 3110 additions and 3200 deletions

View file

@ -87,11 +87,11 @@ impl Supermaven {
pub fn start(&mut self, client: Arc<Client>, cx: &mut Context<Self>) {
if let Self::Starting = self {
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let binary_path =
supermaven_api::get_supermaven_agent_path(client.http_client()).await?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
if let Self::Starting = this {
*this =
Self::Spawned(SupermavenAgent::new(binary_path, client.clone(), cx)?);
@ -290,7 +290,7 @@ impl SupermavenAgent {
cx.spawn({
let client = client.clone();
let outgoing_tx = outgoing_tx.clone();
move |this, mut cx| async move {
async move |this, cx| {
let mut status = client.status();
while let Some(status) = status.next().await {
if status.is_connected() {
@ -298,7 +298,7 @@ impl SupermavenAgent {
outgoing_tx
.unbounded_send(OutboundMessage::SetApiKey(SetApiKey { api_key }))
.ok();
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
if let Supermaven::Spawned(this) = this {
this.account_status = AccountStatus::Ready;
cx.notify();
@ -317,10 +317,12 @@ impl SupermavenAgent {
next_state_id: SupermavenCompletionStateId::default(),
states: BTreeMap::default(),
outgoing_tx,
_handle_outgoing_messages: cx
.spawn(|_, _cx| Self::handle_outgoing_messages(outgoing_rx, stdin)),
_handle_incoming_messages: cx
.spawn(|this, cx| Self::handle_incoming_messages(this, stdout, cx)),
_handle_outgoing_messages: cx.spawn(async move |_, _cx| {
Self::handle_outgoing_messages(outgoing_rx, stdin).await
}),
_handle_incoming_messages: cx.spawn(async move |this, cx| {
Self::handle_incoming_messages(this, stdout, cx).await
}),
account_status: AccountStatus::Unknown,
service_tier: None,
client,
@ -342,7 +344,7 @@ impl SupermavenAgent {
async fn handle_incoming_messages(
this: WeakEntity<Supermaven>,
stdout: ChildStdout,
mut cx: AsyncApp,
cx: &mut AsyncApp,
) -> Result<()> {
const MESSAGE_PREFIX: &str = "SM-MESSAGE ";
@ -362,7 +364,7 @@ impl SupermavenAgent {
continue;
};
this.update(&mut cx, |this, _cx| {
this.update(cx, |this, _cx| {
if let Supermaven::Spawned(this) = this {
this.handle_message(message);
}

View file

@ -133,13 +133,13 @@ impl EditPredictionProvider for SupermavenCompletionProvider {
return;
};
self.pending_refresh = Some(cx.spawn(|this, mut cx| async move {
self.pending_refresh = Some(cx.spawn(async move |this, cx| {
if debounce {
cx.background_executor().timer(DEBOUNCE_TIMEOUT).await;
}
while let Some(()) = completion.updates.next().await {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.completion_id = Some(completion.id);
this.buffer_id = Some(buffer_handle.entity_id());
this.file_extension = buffer_handle.read(cx).file().and_then(|file| {