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:
parent
7f2e3fb5bd
commit
1aefa5178b
256 changed files with 3110 additions and 3200 deletions
|
@ -810,7 +810,7 @@ impl Project {
|
|||
) -> Entity<Self> {
|
||||
cx.new(|cx: &mut Context<Self>| {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
|
||||
cx.spawn(async move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx).await)
|
||||
.detach();
|
||||
let snippets = SnippetProvider::new(fs.clone(), BTreeSet::from_iter([]), cx);
|
||||
let worktree_store = cx.new(|_| WorktreeStore::local(false, fs.clone()));
|
||||
|
@ -963,7 +963,7 @@ impl Project {
|
|||
) -> Entity<Self> {
|
||||
cx.new(|cx: &mut Context<Self>| {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
|
||||
cx.spawn(async move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx).await)
|
||||
.detach();
|
||||
let global_snippets_dir = paths::config_dir().join("snippets");
|
||||
let snippets =
|
||||
|
@ -1285,7 +1285,7 @@ impl Project {
|
|||
}
|
||||
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
|
||||
cx.spawn(async move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx).await)
|
||||
.detach();
|
||||
|
||||
cx.subscribe(&worktree_store, Self::on_worktree_store_event)
|
||||
|
@ -1856,9 +1856,9 @@ impl Project {
|
|||
let is_root_entry = self.entry_is_worktree_root(entry_id, cx);
|
||||
|
||||
let lsp_store = self.lsp_store().downgrade();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.spawn(async move |_, cx| {
|
||||
let (old_abs_path, new_abs_path) = {
|
||||
let root_path = worktree.update(&mut cx, |this, _| this.abs_path())?;
|
||||
let root_path = worktree.update(cx, |this, _| this.abs_path())?;
|
||||
let new_abs_path = if is_root_entry {
|
||||
root_path.parent().unwrap().join(&new_path)
|
||||
} else {
|
||||
|
@ -1877,13 +1877,13 @@ impl Project {
|
|||
.await;
|
||||
|
||||
let entry = worktree
|
||||
.update(&mut cx, |worktree, cx| {
|
||||
.update(cx, |worktree, cx| {
|
||||
worktree.rename_entry(entry_id, new_path.clone(), cx)
|
||||
})?
|
||||
.await?;
|
||||
|
||||
lsp_store
|
||||
.update(&mut cx, |this, _| {
|
||||
.update(cx, |this, _| {
|
||||
this.did_rename_entry(worktree_id, &old_abs_path, &new_abs_path, is_dir);
|
||||
})
|
||||
.ok();
|
||||
|
@ -1934,9 +1934,9 @@ impl Project {
|
|||
let task = worktree.update(cx, |worktree, cx| {
|
||||
worktree.expand_all_for_entry(entry_id, cx)
|
||||
});
|
||||
Some(cx.spawn(|this, mut cx| async move {
|
||||
Some(cx.spawn(async move |this, cx| {
|
||||
task.ok_or_else(|| anyhow!("no task"))?.await?;
|
||||
this.update(&mut cx, |_, cx| {
|
||||
this.update(cx, |_, cx| {
|
||||
cx.emit(Event::ExpandedAllForEntry(worktree_id, entry_id));
|
||||
})?;
|
||||
Ok(())
|
||||
|
@ -2230,9 +2230,9 @@ impl Project {
|
|||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<(Option<ProjectEntryId>, AnyEntity)>> {
|
||||
let task = self.open_buffer(path.clone(), cx);
|
||||
cx.spawn(move |_project, cx| async move {
|
||||
cx.spawn(async move |_project, cx| {
|
||||
let buffer = task.await?;
|
||||
let project_entry_id = buffer.read_with(&cx, |buffer, cx| {
|
||||
let project_entry_id = buffer.read_with(cx, |buffer, cx| {
|
||||
File::from_dyn(buffer.file()).and_then(|file| file.project_entry_id(cx))
|
||||
})?;
|
||||
|
||||
|
@ -2287,9 +2287,9 @@ impl Project {
|
|||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<(Entity<Buffer>, lsp_store::OpenLspBufferHandle)>> {
|
||||
let buffer = self.open_buffer(path, cx);
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let buffer = buffer.await?;
|
||||
let handle = this.update(&mut cx, |project, cx| {
|
||||
let handle = this.update(cx, |project, cx| {
|
||||
project.register_buffer_with_language_servers(&buffer, cx)
|
||||
})?;
|
||||
Ok((buffer, handle))
|
||||
|
@ -2345,10 +2345,10 @@ impl Project {
|
|||
project_id,
|
||||
id: id.into(),
|
||||
});
|
||||
cx.spawn(move |project, mut cx| async move {
|
||||
cx.spawn(async move |project, cx| {
|
||||
let buffer_id = BufferId::new(request.await?.buffer_id)?;
|
||||
project
|
||||
.update(&mut cx, |project, cx| {
|
||||
.update(cx, |project, cx| {
|
||||
project.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.wait_for_remote_buffer(buffer_id, cx)
|
||||
})
|
||||
|
@ -2365,9 +2365,9 @@ impl Project {
|
|||
buffers: HashSet<Entity<Buffer>>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let save_tasks = buffers.into_iter().filter_map(|buffer| {
|
||||
this.update(&mut cx, |this, cx| this.save_buffer(buffer, cx))
|
||||
this.update(cx, |this, cx| this.save_buffer(buffer, cx))
|
||||
.ok()
|
||||
});
|
||||
try_join_all(save_tasks).await?;
|
||||
|
@ -2427,15 +2427,14 @@ impl Project {
|
|||
});
|
||||
|
||||
let weak_project = cx.entity().downgrade();
|
||||
cx.spawn(move |_, mut cx| async move {
|
||||
cx.spawn(async move |_, cx| {
|
||||
let image_item = open_image_task.await?;
|
||||
let project = weak_project
|
||||
.upgrade()
|
||||
.ok_or_else(|| anyhow!("Project dropped"))?;
|
||||
|
||||
let metadata =
|
||||
ImageItem::load_image_metadata(image_item.clone(), project, &mut cx).await?;
|
||||
image_item.update(&mut cx, |image_item, cx| {
|
||||
let metadata = ImageItem::load_image_metadata(image_item.clone(), project, cx).await?;
|
||||
image_item.update(cx, |image_item, cx| {
|
||||
image_item.image_metadata = Some(metadata);
|
||||
cx.emit(ImageItemEvent::MetadataUpdated);
|
||||
})?;
|
||||
|
@ -2447,7 +2446,7 @@ impl Project {
|
|||
async fn send_buffer_ordered_messages(
|
||||
this: WeakEntity<Self>,
|
||||
rx: UnboundedReceiver<BufferOrderedMessage>,
|
||||
mut cx: AsyncApp,
|
||||
cx: &mut AsyncApp,
|
||||
) -> Result<()> {
|
||||
const MAX_BATCH_SIZE: usize = 128;
|
||||
|
||||
|
@ -2482,7 +2481,7 @@ impl Project {
|
|||
let mut changes = rx.ready_chunks(MAX_BATCH_SIZE);
|
||||
|
||||
while let Some(changes) = changes.next().await {
|
||||
let is_local = this.update(&mut cx, |this, _| this.is_local())?;
|
||||
let is_local = this.update(cx, |this, _| this.is_local())?;
|
||||
|
||||
for change in changes {
|
||||
match change {
|
||||
|
@ -2503,7 +2502,7 @@ impl Project {
|
|||
BufferOrderedMessage::Resync => {
|
||||
operations_by_buffer_id.clear();
|
||||
if this
|
||||
.update(&mut cx, |this, cx| this.synchronize_remote_buffers(cx))?
|
||||
.update(cx, |this, cx| this.synchronize_remote_buffers(cx))?
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
|
@ -2520,11 +2519,11 @@ impl Project {
|
|||
&mut operations_by_buffer_id,
|
||||
&mut needs_resync_with_host,
|
||||
is_local,
|
||||
&mut cx,
|
||||
cx,
|
||||
)
|
||||
.await?;
|
||||
|
||||
this.update(&mut cx, |this, _| {
|
||||
this.update(cx, |this, _| {
|
||||
if let Some(project_id) = this.remote_id() {
|
||||
this.client
|
||||
.send(proto::UpdateLanguageServer {
|
||||
|
@ -2544,7 +2543,7 @@ impl Project {
|
|||
&mut operations_by_buffer_id,
|
||||
&mut needs_resync_with_host,
|
||||
is_local,
|
||||
&mut cx,
|
||||
cx,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -2891,31 +2890,29 @@ impl Project {
|
|||
}
|
||||
|
||||
fn recalculate_buffer_diffs(&mut self, cx: &mut Context<Self>) -> Task<()> {
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
loop {
|
||||
let task = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
let buffers = this
|
||||
.buffers_needing_diff
|
||||
.drain()
|
||||
.filter_map(|buffer| buffer.upgrade())
|
||||
.collect::<Vec<_>>();
|
||||
if buffers.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(this.git_store.update(cx, |git_store, cx| {
|
||||
git_store.recalculate_buffer_diffs(buffers, cx)
|
||||
}))
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
.flatten();
|
||||
cx.spawn(async move |this, cx| loop {
|
||||
let task = this
|
||||
.update(cx, |this, cx| {
|
||||
let buffers = this
|
||||
.buffers_needing_diff
|
||||
.drain()
|
||||
.filter_map(|buffer| buffer.upgrade())
|
||||
.collect::<Vec<_>>();
|
||||
if buffers.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(this.git_store.update(cx, |git_store, cx| {
|
||||
git_store.recalculate_buffer_diffs(buffers, cx)
|
||||
}))
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
if let Some(task) = task {
|
||||
task.await;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if let Some(task) = task {
|
||||
task.await;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -2975,7 +2972,7 @@ impl Project {
|
|||
cx: &App,
|
||||
) -> Task<Option<ToolchainList>> {
|
||||
if let Some(toolchain_store) = self.toolchain_store.clone() {
|
||||
cx.spawn(|cx| async move {
|
||||
cx.spawn(async move |cx| {
|
||||
cx.update(|cx| {
|
||||
toolchain_store
|
||||
.read(cx)
|
||||
|
@ -3225,7 +3222,7 @@ impl Project {
|
|||
|
||||
let proto_client = ssh_client.read(cx).proto_client();
|
||||
|
||||
cx.spawn(|project, mut cx| async move {
|
||||
cx.spawn(async move |project, cx| {
|
||||
let buffer = proto_client
|
||||
.request(proto::OpenServerSettings {
|
||||
project_id: SSH_PROJECT_ID,
|
||||
|
@ -3233,7 +3230,7 @@ impl Project {
|
|||
.await?;
|
||||
|
||||
let buffer = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
.update(cx, |project, cx| {
|
||||
project.buffer_store.update(cx, |buffer_store, cx| {
|
||||
anyhow::Ok(
|
||||
buffer_store
|
||||
|
@ -3468,7 +3465,7 @@ impl Project {
|
|||
self.find_search_candidate_buffers(&query, MAX_SEARCH_RESULT_FILES + 1, cx)
|
||||
};
|
||||
|
||||
cx.spawn(|_, cx| async move {
|
||||
cx.spawn(async move |_, cx| {
|
||||
let mut range_count = 0;
|
||||
let mut buffer_count = 0;
|
||||
let mut limit_reached = false;
|
||||
|
@ -3485,7 +3482,7 @@ impl Project {
|
|||
for buffer in matching_buffer_chunk {
|
||||
let buffer = buffer.clone();
|
||||
let query = query.clone();
|
||||
let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot())?;
|
||||
let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot())?;
|
||||
chunk_results.push(cx.background_spawn(async move {
|
||||
let ranges = query
|
||||
.search(&snapshot, None)
|
||||
|
@ -3610,12 +3607,12 @@ impl Project {
|
|||
});
|
||||
let guard = self.retain_remotely_created_models(cx);
|
||||
|
||||
cx.spawn(move |project, mut cx| async move {
|
||||
cx.spawn(async move |project, cx| {
|
||||
let response = request.await?;
|
||||
for buffer_id in response.buffer_ids {
|
||||
let buffer_id = BufferId::new(buffer_id)?;
|
||||
let buffer = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
.update(cx, |project, cx| {
|
||||
project.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.wait_for_remote_buffer(buffer_id, cx)
|
||||
})
|
||||
|
@ -3646,7 +3643,7 @@ impl Project {
|
|||
let task = self.lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store.request_lsp(buffer_handle, server, request, cx)
|
||||
});
|
||||
cx.spawn(|_, _| async move {
|
||||
cx.spawn(async move |_, _| {
|
||||
let result = task.await;
|
||||
drop(guard);
|
||||
result
|
||||
|
@ -3797,7 +3794,7 @@ impl Project {
|
|||
})
|
||||
.collect();
|
||||
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
cx.spawn(async move |_, mut cx| {
|
||||
if let Some(buffer_worktree_id) = buffer_worktree_id {
|
||||
if let Some((worktree, _)) = worktrees_with_ids
|
||||
.iter()
|
||||
|
@ -4515,8 +4512,8 @@ impl Project {
|
|||
};
|
||||
|
||||
let client = self.client.clone();
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let (buffers, incomplete_buffer_ids) = this.update(&mut cx, |this, cx| {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let (buffers, incomplete_buffer_ids) = this.update(cx, |this, cx| {
|
||||
this.buffer_store.read(cx).buffer_version_info(cx)
|
||||
})?;
|
||||
let response = client
|
||||
|
@ -4526,7 +4523,7 @@ impl Project {
|
|||
})
|
||||
.await?;
|
||||
|
||||
let send_updates_for_buffers = this.update(&mut cx, |this, cx| {
|
||||
let send_updates_for_buffers = this.update(cx, |this, cx| {
|
||||
response
|
||||
.buffers
|
||||
.into_iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue