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-19 02:09:02 +00:00
committed by GitHub
parent 7f2e3fb5bd
commit 1aefa5178b
256 changed files with 3110 additions and 3200 deletions
+41 -47
View File
@@ -111,9 +111,9 @@ impl RemoteBufferStore {
let (tx, rx) = oneshot::channel();
self.remote_buffer_listeners.entry(id).or_default().push(tx);
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Some(buffer) = this
.read_with(&cx, |buffer_store, _| buffer_store.get(id))
.read_with(cx, |buffer_store, _| buffer_store.get(id))
.ok()
.flatten()
{
@@ -135,7 +135,7 @@ impl RemoteBufferStore {
let version = buffer.version();
let rpc = self.upstream_client.clone();
let project_id = self.project_id;
cx.spawn(move |_, mut cx| async move {
cx.spawn(async move |_, cx| {
let response = rpc
.request(proto::SaveBuffer {
project_id,
@@ -147,7 +147,7 @@ impl RemoteBufferStore {
let version = deserialize_version(&response.version);
let mtime = response.mtime.map(|mtime| mtime.into());
buffer_handle.update(&mut cx, |buffer, cx| {
buffer_handle.update(cx, |buffer, cx| {
buffer.did_save(version.clone(), mtime, cx);
})?;
@@ -263,15 +263,13 @@ impl RemoteBufferStore {
push_to_history: bool,
cx: &mut Context<BufferStore>,
) -> Task<Result<ProjectTransaction>> {
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let mut project_transaction = ProjectTransaction::default();
for (buffer_id, transaction) in message.buffer_ids.into_iter().zip(message.transactions)
{
let buffer_id = BufferId::new(buffer_id)?;
let buffer = this
.update(&mut cx, |this, cx| {
this.wait_for_remote_buffer(buffer_id, cx)
})?
.update(cx, |this, cx| this.wait_for_remote_buffer(buffer_id, cx))?
.await?;
let transaction = language::proto::deserialize_transaction(transaction)?;
project_transaction.0.insert(buffer, transaction);
@@ -279,13 +277,13 @@ impl RemoteBufferStore {
for (buffer, transaction) in &project_transaction.0 {
buffer
.update(&mut cx, |buffer, _| {
.update(cx, |buffer, _| {
buffer.wait_for_edits(transaction.edit_ids.iter().copied())
})?
.await?;
if push_to_history {
buffer.update(&mut cx, |buffer, _| {
buffer.update(cx, |buffer, _| {
buffer.push_transaction(transaction.clone(), Instant::now());
})?;
}
@@ -304,7 +302,7 @@ impl RemoteBufferStore {
let worktree_id = worktree.read(cx).id().to_proto();
let project_id = self.project_id;
let client = self.upstream_client.clone();
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let response = client
.request(proto::OpenBufferByPath {
project_id,
@@ -315,7 +313,7 @@ impl RemoteBufferStore {
let buffer_id = BufferId::new(response.buffer_id)?;
let buffer = this
.update(&mut cx, {
.update(cx, {
|this, cx| this.wait_for_remote_buffer(buffer_id, cx)
})?
.await?;
@@ -328,14 +326,12 @@ impl RemoteBufferStore {
let create = self.upstream_client.request(proto::OpenNewBuffer {
project_id: self.project_id,
});
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let response = create.await?;
let buffer_id = BufferId::new(response.buffer_id)?;
this.update(&mut cx, |this, cx| {
this.wait_for_remote_buffer(buffer_id, cx)
})?
.await
this.update(cx, |this, cx| this.wait_for_remote_buffer(buffer_id, cx))?
.await
})
}
@@ -353,12 +349,12 @@ impl RemoteBufferStore {
.collect(),
});
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let response = request
.await?
.transaction
.ok_or_else(|| anyhow!("missing transaction"))?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.deserialize_project_transaction(response, push_to_history, cx)
})?
.await
@@ -392,10 +388,10 @@ impl LocalBufferStore {
worktree.write_file(path.as_ref(), text, line_ending, cx)
});
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let new_file = save.await?;
let mtime = new_file.disk_state().mtime();
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
if let Some((downstream_client, project_id)) = this.downstream_client.clone() {
if has_changed_file {
downstream_client
@@ -416,7 +412,7 @@ impl LocalBufferStore {
.log_err();
}
})?;
buffer_handle.update(&mut cx, |buffer, cx| {
buffer_handle.update(cx, |buffer, cx| {
if has_changed_file {
buffer.file_updated(new_file, cx);
}
@@ -654,7 +650,7 @@ impl LocalBufferStore {
let load_file = worktree.load_file(path.as_ref(), cx);
let reservation = cx.reserve_entity();
let buffer_id = BufferId::from(reservation.entity_id().as_non_zero_u64());
cx.spawn(move |_, mut cx| async move {
cx.spawn(async move |_, cx| {
let loaded = load_file.await?;
let text_buffer = cx
.background_spawn(async move { text::Buffer::new(0, buffer_id, loaded.text) })
@@ -665,7 +661,7 @@ impl LocalBufferStore {
})
});
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let buffer = match load_buffer.await {
Ok(buffer) => Ok(buffer),
Err(error) if is_not_found_error(&error) => cx.new(|cx| {
@@ -686,7 +682,7 @@ impl LocalBufferStore {
}),
Err(e) => Err(e),
}?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.add_buffer(buffer.clone(), cx)?;
let buffer_id = buffer.read(cx).remote_id();
if let Some(file) = File::from_dyn(buffer.read(cx).file()) {
@@ -713,10 +709,10 @@ impl LocalBufferStore {
}
fn create_buffer(&self, cx: &mut Context<BufferStore>) -> Task<Result<Entity<Buffer>>> {
cx.spawn(|buffer_store, mut cx| async move {
cx.spawn(async move |buffer_store, cx| {
let buffer =
cx.new(|cx| Buffer::local("", cx).with_language(language::PLAIN_TEXT.clone(), cx))?;
buffer_store.update(&mut cx, |buffer_store, cx| {
buffer_store.update(cx, |buffer_store, cx| {
buffer_store.add_buffer(buffer.clone(), cx).log_err();
})?;
Ok(buffer)
@@ -729,13 +725,11 @@ impl LocalBufferStore {
push_to_history: bool,
cx: &mut Context<BufferStore>,
) -> Task<Result<ProjectTransaction>> {
cx.spawn(move |_, mut cx| async move {
cx.spawn(async move |_, cx| {
let mut project_transaction = ProjectTransaction::default();
for buffer in buffers {
let transaction = buffer
.update(&mut cx, |buffer, cx| buffer.reload(cx))?
.await?;
buffer.update(&mut cx, |buffer, cx| {
let transaction = buffer.update(cx, |buffer, cx| buffer.reload(cx))?.await?;
buffer.update(cx, |buffer, cx| {
if let Some(transaction) = transaction {
if !push_to_history {
buffer.forget_transaction(transaction.id);
@@ -866,9 +860,9 @@ impl BufferStore {
entry
.insert(
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let load_result = load_buffer.await;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
// Record the fact that the buffer is no longer loading.
this.loading_buffers.remove(&project_path);
@@ -936,9 +930,9 @@ impl BufferStore {
this.save_remote_buffer(buffer.clone(), Some(path.to_proto()), cx)
}
};
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
task.await?;
this.update(&mut cx, |_, cx| {
this.update(cx, |_, cx| {
cx.emit(BufferStoreEvent::BufferChangedFilePath { buffer, old_file });
})
})
@@ -978,7 +972,7 @@ impl BufferStore {
anyhow::Ok(Some((repo, relative_path, content)))
});
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
let Some((repo, relative_path, content)) = blame_params? else {
return Ok(None);
};
@@ -993,7 +987,7 @@ impl BufferStore {
let version = buffer.version();
let project_id = worktree.project_id();
let client = worktree.client();
cx.spawn(|_| async move {
cx.spawn(async move |_| {
let response = client
.request(proto::BlameBuffer {
project_id,
@@ -1038,7 +1032,7 @@ impl BufferStore {
return Task::ready(Err(anyhow!("no permalink available")));
}
let file_path = worktree_path.join(file.path());
return cx.spawn(|cx| async move {
return cx.spawn(async move |cx| {
let provider_registry =
cx.update(GitHostingProviderRegistry::default_global)?;
get_permalink_in_rust_registry_src(provider_registry, file_path, selection)
@@ -1058,7 +1052,7 @@ impl BufferStore {
.unwrap_or("origin")
.to_string();
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
let origin_url = repo
.remote_url(&remote)
.ok_or_else(|| anyhow!("remote \"{remote}\" not found"))?;
@@ -1092,7 +1086,7 @@ impl BufferStore {
let buffer_id = buffer.remote_id();
let project_id = worktree.project_id();
let client = worktree.client();
cx.spawn(|_| async move {
cx.spawn(async move |_| {
let response = client
.request(proto::GetPermalinkToLine {
project_id,
@@ -1281,14 +1275,14 @@ impl BufferStore {
})
.chunks(MAX_CONCURRENT_BUFFER_OPENS);
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
for buffer in unnamed_buffers {
tx.send(buffer).await.ok();
}
let mut project_paths_rx = pin!(project_paths_rx);
while let Some(project_paths) = project_paths_rx.next().await {
let buffers = this.update(&mut cx, |this, cx| {
let buffers = this.update(cx, |this, cx| {
project_paths
.into_iter()
.map(|project_path| this.open_buffer(project_path, cx))
@@ -1776,14 +1770,14 @@ impl BufferStore {
return Task::ready(Ok(()));
};
cx.spawn(|this, mut cx| async move {
let Some(buffer) = this.update(&mut cx, |this, _| this.get(buffer_id))? else {
cx.spawn(async move |this, cx| {
let Some(buffer) = this.update(cx, |this, _| this.get(buffer_id))? else {
return anyhow::Ok(());
};
let operations = buffer.update(&mut cx, |b, cx| b.serialize_ops(None, cx))?;
let operations = buffer.update(cx, |b, cx| b.serialize_ops(None, cx))?;
let operations = operations.await;
let state = buffer.update(&mut cx, |buffer, cx| buffer.to_proto(cx))?;
let state = buffer.update(cx, |buffer, cx| buffer.to_proto(cx))?;
let initial_state = proto::CreateBufferForPeer {
project_id,
+11 -7
View File
@@ -7,7 +7,7 @@ use gpui::{App, AppContext as _, AsyncApp, Context, Entity, Global, Task, WeakEn
use postage::stream::Stream;
use rpc::proto;
use std::{sync::Arc, time::Duration};
use util::{ResultExt, TryFutureExt};
use util::ResultExt;
impl Global for GlobalManager {}
struct GlobalManager(Entity<Manager>);
@@ -65,7 +65,11 @@ impl Manager {
if self.maintain_connection.is_none() {
self.maintain_connection = Some(cx.spawn({
let client = self.client.clone();
move |_, cx| Self::maintain_connection(manager, client.clone(), cx).log_err()
async move |_, cx| {
Self::maintain_connection(manager, client.clone(), cx)
.await
.log_err()
}
}));
}
}
@@ -102,11 +106,11 @@ impl Manager {
.collect(),
});
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let response = request.await?;
let message_id = response.message_id;
this.update(&mut cx, |_, cx| {
this.update(cx, |_, cx| {
for rejoined_project in response.payload.rejoined_projects {
if let Some(project) = projects.get(&rejoined_project.id) {
project.update(cx, |project, cx| {
@@ -133,7 +137,7 @@ impl Manager {
async fn maintain_connection(
this: WeakEntity<Self>,
client: Arc<Client>,
mut cx: AsyncApp,
cx: &mut AsyncApp,
) -> Result<()> {
let mut client_status = client.status();
loop {
@@ -155,7 +159,7 @@ impl Manager {
log::info!("client reconnected, attempting to rejoin projects");
let Some(this) = this.upgrade() else { break };
match this.update(&mut cx, |this, cx| this.reconnected(cx)) {
match this.update(cx, |this, cx| this.reconnected(cx)) {
Ok(task) => {
if task.await.log_err().is_some() {
return true;
@@ -204,7 +208,7 @@ impl Manager {
// we leave the room and return an error.
if let Some(this) = this.upgrade() {
log::info!("reconnection failed, disconnecting projects");
this.update(&mut cx, |this, cx| this.connection_lost(cx))?;
this.update(cx, |this, cx| this.connection_lost(cx))?;
}
Ok(())
+2 -2
View File
@@ -35,7 +35,7 @@ impl<E: 'static> DebouncedDelay<E> {
self.cancel_channel = Some(sender);
let previous_task = self.task.take();
self.task = Some(cx.spawn(move |entity, mut cx| async move {
self.task = Some(cx.spawn(async move |entity, cx| {
let mut timer = cx.background_executor().timer(delay).fuse();
if let Some(previous_task) = previous_task {
previous_task.await;
@@ -46,7 +46,7 @@ impl<E: 'static> DebouncedDelay<E> {
_ = timer => {}
}
if let Ok(task) = entity.update(&mut cx, |project, cx| (func)(project, cx)) {
if let Ok(task) = entity.update(cx, |project, cx| (func)(project, cx)) {
task.await;
}
}));
@@ -448,7 +448,7 @@ impl BreakpointStore {
) -> Task<Result<()>> {
if let BreakpointStoreMode::Local(mode) = &self.mode {
let mode = mode.clone();
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let mut new_breakpoints = BTreeMap::default();
for (path, bps) in breakpoints {
if bps.is_empty() {
@@ -456,13 +456,13 @@ impl BreakpointStore {
}
let (worktree, relative_path) = mode
.worktree_store
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.find_or_create_worktree(&path, false, cx)
})?
.await?;
let buffer = mode
.buffer_store
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
let path = ProjectPath {
worktree_id: worktree.read(cx).id(),
path: relative_path.into(),
@@ -474,10 +474,10 @@ impl BreakpointStore {
log::error!("Todo: Serialized breakpoints which do not have buffer (yet)");
continue;
};
let snapshot = buffer.update(&mut cx, |buffer, _| buffer.snapshot())?;
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
let mut breakpoints_for_file =
this.update(&mut cx, |_, cx| BreakpointsInFile::new(buffer, cx))?;
this.update(cx, |_, cx| BreakpointsInFile::new(buffer, cx))?;
for bp in bps {
let position = snapshot.anchor_before(PointUtf16::new(bp.position, 0));
@@ -487,7 +487,7 @@ impl BreakpointStore {
}
new_breakpoints.insert(path, breakpoints_for_file);
}
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.breakpoints = new_breakpoints;
cx.notify();
})?;
+11 -11
View File
@@ -149,12 +149,12 @@ impl DapStore {
let (start_debugging_tx, mut message_rx) =
futures::channel::mpsc::unbounded::<(SessionId, Message)>();
let _start_debugging_task = cx.spawn(move |this, mut cx| async move {
let _start_debugging_task = cx.spawn(async move |this, cx| {
while let Some((session_id, message)) = message_rx.next().await {
match message {
Message::Request(request) => {
let _ = this
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
if request.command == StartDebugging::COMMAND {
this.handle_start_debugging_request(session_id, request, cx)
.detach_and_log_err(cx);
@@ -361,11 +361,11 @@ impl DapStore {
cx,
);
let task = cx.spawn(|this, mut cx| async move {
let task = cx.spawn(async move |this, cx| {
let session = match start_client_task.await {
Ok(session) => session,
Err(error) => {
this.update(&mut cx, |_, cx| {
this.update(cx, |_, cx| {
cx.emit(DapStoreEvent::Notification(error.to_string()));
})
.log_err();
@@ -376,21 +376,21 @@ impl DapStore {
// we have to insert the session early, so we can handle reverse requests
// that need the session to be available
this.update(&mut cx, |store, cx| {
this.update(cx, |store, cx| {
store.sessions.insert(session_id, session.clone());
cx.emit(DapStoreEvent::DebugClientStarted(session_id));
cx.notify();
})?;
match session
.update(&mut cx, |session, cx| {
.update(cx, |session, cx| {
session.initialize_sequence(initialized_rx, cx)
})?
.await
{
Ok(_) => {}
Err(error) => {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
cx.emit(DapStoreEvent::Notification(error.to_string()));
this.shutdown_session(session_id, cx)
@@ -456,7 +456,7 @@ impl DapStore {
);
let request_seq = request.seq;
cx.spawn(|_, mut cx| async move {
cx.spawn(async move |_, cx| {
let (success, body) = match new_session_task.await {
Ok(_) => (true, None),
Err(error) => (
@@ -476,7 +476,7 @@ impl DapStore {
};
parent_session
.update(&mut cx, |session, cx| {
.update(cx, |session, cx| {
session.respond_to_client(
request_seq,
success,
@@ -572,7 +572,7 @@ impl DapStore {
cx.notify();
let session = session.downgrade();
cx.spawn(|_, mut cx| async move {
cx.spawn(async move |_, cx| {
let (success, body) = match rx.next().await {
Some(Ok(pid)) => (
true,
@@ -615,7 +615,7 @@ impl DapStore {
};
session
.update(&mut cx, |session, cx| {
.update(cx, |session, cx| {
session.respond_to_client(
seq,
success,
+26 -27
View File
@@ -191,8 +191,8 @@ impl LocalMode {
messages_tx: futures::channel::mpsc::UnboundedSender<Message>,
cx: AsyncApp,
) -> Task<Result<(Self, Capabilities)>> {
cx.spawn(move |mut cx| async move {
let (adapter, binary) = Self::get_adapter_binary(&config, &delegate, &mut cx).await?;
cx.spawn(async move |cx| {
let (adapter, binary) = Self::get_adapter_binary(&config, &delegate, cx).await?;
let message_handler = Box::new(move |message| {
messages_tx.unbounded_send(message).ok();
@@ -439,7 +439,7 @@ impl LocalMode {
let configuration_sequence = cx.spawn({
let this = self.clone();
move |cx| async move {
async move |cx| {
initialized_rx.await?;
// todo(debugger) figure out if we want to handle a breakpoint response error
// This will probably consist of letting a user know that breakpoints failed to be set
@@ -697,7 +697,7 @@ impl Session {
) -> Task<Result<Entity<Self>>> {
let (message_tx, mut message_rx) = futures::channel::mpsc::unbounded();
cx.spawn(move |mut cx| async move {
cx.spawn(async move |cx| {
let (mode, capabilities) = LocalMode::new(
session_id,
parent_session.clone(),
@@ -710,31 +710,30 @@ impl Session {
.await?;
cx.new(|cx| {
let _background_tasks =
vec![cx.spawn(move |this: WeakEntity<Self>, mut cx| async move {
let mut initialized_tx = Some(initialized_tx);
while let Some(message) = message_rx.next().await {
if let Message::Event(event) = message {
if let Events::Initialized(_) = *event {
if let Some(tx) = initialized_tx.take() {
tx.send(()).ok();
}
} else {
let Ok(_) = this.update(&mut cx, |session, cx| {
session.handle_dap_event(event, cx);
}) else {
break;
};
let _background_tasks = vec![cx.spawn(async move |this: WeakEntity<Self>, cx| {
let mut initialized_tx = Some(initialized_tx);
while let Some(message) = message_rx.next().await {
if let Message::Event(event) = message {
if let Events::Initialized(_) = *event {
if let Some(tx) = initialized_tx.take() {
tx.send(()).ok();
}
} else {
let Ok(_) = start_debugging_requests_tx
.unbounded_send((session_id, message))
else {
let Ok(_) = this.update(cx, |session, cx| {
session.handle_dap_event(event, cx);
}) else {
break;
};
}
} else {
let Ok(_) =
start_debugging_requests_tx.unbounded_send((session_id, message))
else {
break;
};
}
})];
}
})];
cx.subscribe(&breakpoint_store, |this, _, event, cx| match event {
BreakpointStoreEvent::BreakpointsUpdated(path, reason) => {
@@ -1102,17 +1101,17 @@ impl Session {
let error = Err(anyhow::Error::msg(
"Couldn't complete request because it's not supported",
));
return cx.spawn(|this, mut cx| async move {
this.update(&mut cx, |this, cx| process_result(this, error, cx))
return cx.spawn(async move |this, cx| {
this.update(cx, |this, cx| process_result(this, error, cx))
.log_err()
.flatten()
});
}
let request = mode.request_dap(session_id, request, cx);
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let result = request.await;
this.update(&mut cx, |this, cx| process_result(this, result, cx))
this.update(cx, |this, cx| process_result(this, result, cx))
.log_err()
.flatten()
})
+3 -3
View File
@@ -97,7 +97,7 @@ impl ProjectEnvironment {
if let Some(cli_environment) = self.get_cli_environment() {
return cx
.spawn(|_, _| async move {
.spawn(async move |_, _| {
let path = cli_environment
.get("PATH")
.map(|path| path.as_str())
@@ -144,7 +144,7 @@ impl ProjectEnvironment {
) -> Task<Option<HashMap<String, String>>> {
let load_direnv = ProjectSettings::get_global(cx).load_direnv.clone();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let (mut shell_env, error_message) = cx
.background_spawn({
let worktree_abs_path = worktree_abs_path.clone();
@@ -169,7 +169,7 @@ impl ProjectEnvironment {
}
if let Some(error) = error_message {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.environment_error_messages.insert(worktree_id, error);
cx.emit(ProjectEnvironmentEvent::ErrorsUpdated)
})
+30 -30
View File
@@ -351,7 +351,7 @@ impl GitStore {
let staged_text = self.state.load_staged_text(&buffer, &self.buffer_store, cx);
entry
.insert(
cx.spawn(move |this, cx| async move {
cx.spawn(async move |this, cx| {
Self::open_diff_internal(
this,
DiffKind::Unstaged,
@@ -406,7 +406,7 @@ impl GitStore {
entry
.insert(
cx.spawn(move |this, cx| async move {
cx.spawn(async move |this, cx| {
Self::open_diff_internal(
this,
DiffKind::Uncommitted,
@@ -431,11 +431,11 @@ impl GitStore {
kind: DiffKind,
texts: Result<DiffBasesChange>,
buffer_entity: Entity<Buffer>,
mut cx: AsyncApp,
cx: &mut AsyncApp,
) -> Result<Entity<BufferDiff>> {
let diff_bases_change = match texts {
Err(e) => {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
let buffer = buffer_entity.read(cx);
let buffer_id = buffer.remote_id();
this.loading_diffs.remove(&(buffer_id, kind));
@@ -445,7 +445,7 @@ impl GitStore {
Ok(change) => change,
};
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
let buffer = buffer_entity.read(cx);
let buffer_id = buffer.remote_id();
let language = buffer.language().cloned();
@@ -736,13 +736,13 @@ impl GitStore {
)
});
let diff = diff.downgrade();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(Err(error)) = cx.background_spawn(recv).await {
diff.update(&mut cx, |diff, cx| {
diff.update(cx, |diff, cx| {
diff.clear_pending_hunks(cx);
})
.ok();
this.update(&mut cx, |_, cx| cx.emit(GitEvent::IndexWriteError(error)))
this.update(cx, |_, cx| cx.emit(GitEvent::IndexWriteError(error)))
.ok();
}
})
@@ -973,7 +973,7 @@ impl GitStore {
fn spawn_git_worker(cx: &mut Context<GitStore>) -> mpsc::UnboundedSender<GitJob> {
let (job_tx, mut job_rx) = mpsc::unbounded::<GitJob>();
cx.spawn(|_, mut cx| async move {
cx.spawn(async move |_, cx| {
let mut jobs = VecDeque::new();
loop {
while let Ok(Some(next_job)) = job_rx.try_next() {
@@ -989,7 +989,7 @@ impl GitStore {
continue;
}
}
(job.job)(&mut cx).await;
(job.job)(cx).await;
} else if let Some(job) = job_rx.next().await {
jobs.push_back(job);
} else {
@@ -1772,7 +1772,7 @@ impl BufferDiffState {
(None, None) => true,
_ => false,
};
self.recalculate_diff_task = Some(cx.spawn(|this, mut cx| async move {
self.recalculate_diff_task = Some(cx.spawn(async move |this, cx| {
let mut new_unstaged_diff = None;
if let Some(unstaged_diff) = &unstaged_diff {
new_unstaged_diff = Some(
@@ -1784,7 +1784,7 @@ impl BufferDiffState {
language_changed,
language.clone(),
language_registry.clone(),
&mut cx,
cx,
)
.await?,
);
@@ -1804,7 +1804,7 @@ impl BufferDiffState {
language_changed,
language.clone(),
language_registry.clone(),
&mut cx,
cx,
)
.await?,
)
@@ -1814,7 +1814,7 @@ impl BufferDiffState {
let unstaged_changed_range = if let Some((unstaged_diff, new_unstaged_diff)) =
unstaged_diff.as_ref().zip(new_unstaged_diff.clone())
{
unstaged_diff.update(&mut cx, |diff, cx| {
unstaged_diff.update(cx, |diff, cx| {
diff.set_snapshot(&buffer, new_unstaged_diff, language_changed, None, cx)
})?
} else {
@@ -1824,7 +1824,7 @@ impl BufferDiffState {
if let Some((uncommitted_diff, new_uncommitted_diff)) =
uncommitted_diff.as_ref().zip(new_uncommitted_diff.clone())
{
uncommitted_diff.update(&mut cx, |uncommitted_diff, cx| {
uncommitted_diff.update(cx, |uncommitted_diff, cx| {
uncommitted_diff.set_snapshot(
&buffer,
new_uncommitted_diff,
@@ -1836,7 +1836,7 @@ impl BufferDiffState {
}
if let Some(this) = this.upgrade() {
this.update(&mut cx, |this, _| {
this.update(cx, |this, _| {
this.index_changed = false;
this.head_changed = false;
this.language_changed = false;
@@ -1873,7 +1873,7 @@ fn make_remote_delegate(
askpass_id,
prompt,
});
cx.spawn(|_, _| async move {
cx.spawn(async move |_, _| {
tx.send(response.await?.response).ok();
anyhow::Ok(())
})
@@ -2028,7 +2028,7 @@ impl Repository {
key,
job: Box::new(|cx: &mut AsyncApp| {
let job = job(git_repo, cx.clone());
cx.spawn(|_| async move {
cx.spawn(async move |_| {
let result = job.await;
result_tx.send(result).ok();
})
@@ -2150,7 +2150,7 @@ impl Repository {
} = self.git_repo.clone()
{
let client = client.clone();
cx.spawn(|repository, mut cx| async move {
cx.spawn(async move |repository, cx| {
let request = client.request(proto::OpenCommitMessageBuffer {
project_id: project_id.0,
worktree_id: worktree_id.to_proto(),
@@ -2159,18 +2159,18 @@ impl Repository {
let response = request.await.context("requesting to open commit buffer")?;
let buffer_id = BufferId::new(response.buffer_id)?;
let buffer = buffer_store
.update(&mut cx, |buffer_store, cx| {
.update(cx, |buffer_store, cx| {
buffer_store.wait_for_remote_buffer(buffer_id, cx)
})?
.await?;
if let Some(language_registry) = languages {
let git_commit_language =
language_registry.language_for_name("Git Commit").await?;
buffer.update(&mut cx, |buffer, cx| {
buffer.update(cx, |buffer, cx| {
buffer.set_language(Some(git_commit_language), cx);
})?;
}
repository.update(&mut cx, |repository, _| {
repository.update(cx, |repository, _| {
repository.commit_message_buffer = Some(buffer.clone());
})?;
Ok(buffer)
@@ -2186,19 +2186,19 @@ impl Repository {
buffer_store: Entity<BufferStore>,
cx: &mut Context<Self>,
) -> Task<Result<Entity<Buffer>>> {
cx.spawn(|repository, mut cx| async move {
cx.spawn(async move |repository, cx| {
let buffer = buffer_store
.update(&mut cx, |buffer_store, cx| buffer_store.create_buffer(cx))?
.update(cx, |buffer_store, cx| buffer_store.create_buffer(cx))?
.await?;
if let Some(language_registry) = language_registry {
let git_commit_language = language_registry.language_for_name("Git Commit").await?;
buffer.update(&mut cx, |buffer, cx| {
buffer.update(cx, |buffer, cx| {
buffer.set_language(Some(git_commit_language), cx);
})?;
}
repository.update(&mut cx, |repository, _| {
repository.update(cx, |repository, _| {
repository.commit_message_buffer = Some(buffer.clone());
})?;
Ok(buffer)
@@ -2347,13 +2347,13 @@ impl Repository {
})
}
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
for save_future in save_futures {
save_future.await?;
}
let env = env.await;
this.update(&mut cx, |this, _| {
this.update(cx, |this, _| {
this.send_job(|git_repo, cx| async move {
match git_repo {
GitRepo::Local(repo) => repo.stage_paths(entries, env, cx).await,
@@ -2418,13 +2418,13 @@ impl Repository {
})
}
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
for save_future in save_futures {
save_future.await?;
}
let env = env.await;
this.update(&mut cx, |this, _| {
this.update(cx, |this, _| {
this.send_job(|git_repo, cx| async move {
match git_repo {
GitRepo::Local(repo) => repo.unstage_paths(entries, env, cx).await,
+10 -10
View File
@@ -191,14 +191,14 @@ impl ImageItem {
let (tx, rx) = futures::channel::oneshot::channel();
let content = local_file.load_bytes(cx);
self.reload_task = Some(cx.spawn(|this, mut cx| async move {
self.reload_task = Some(cx.spawn(async move |this, cx| {
if let Some(image) = content
.await
.context("Failed to load image content")
.and_then(create_gpui_image)
.log_err()
{
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.image = image;
cx.emit(ImageItemEvent::Reloaded);
})
@@ -238,9 +238,9 @@ impl ProjectItem for ImageItem {
// Only open the item if it's a binary image (no SVGs, etc.)
// Since we do not have a way to toggle to an editor
if Img::extensions().contains(&ext) && !ext.contains("svg") {
Some(cx.spawn(|mut cx| async move {
Some(cx.spawn(async move |cx| {
project
.update(&mut cx, |project, cx| project.open_image(path, cx))?
.update(cx, |project, cx| project.open_image(path, cx))?
.await
}))
} else {
@@ -389,9 +389,9 @@ impl ImageStore {
.state
.open_image(project_path.path.clone(), worktree, cx);
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
let load_result = load_image.await;
*tx.borrow_mut() = Some(this.update(&mut cx, |this, _cx| {
*tx.borrow_mut() = Some(this.update(cx, |this, _cx| {
// Record the fact that the image is no longer loading.
this.loading_images_by_path.remove(&project_path);
let image = load_result.map_err(Arc::new)?;
@@ -480,7 +480,7 @@ impl ImageStoreImpl for Entity<LocalImageStore> {
let load_file = worktree.update(cx, |worktree, cx| {
worktree.load_binary_file(path.as_ref(), cx)
});
cx.spawn(move |image_store, mut cx| async move {
cx.spawn(async move |image_store, cx| {
let LoadedBinaryFile { file, content } = load_file.await?;
let image = create_gpui_image(content)?;
@@ -494,7 +494,7 @@ impl ImageStoreImpl for Entity<LocalImageStore> {
let image_id = cx.read_entity(&entity, |model, _| model.id)?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
image_store.update(cx, |image_store, cx| {
image_store.add_image(entity.clone(), cx)
})??;
@@ -522,9 +522,9 @@ impl ImageStoreImpl for Entity<LocalImageStore> {
images: HashSet<Entity<ImageItem>>,
cx: &mut Context<ImageStore>,
) -> Task<Result<()>> {
cx.spawn(move |_, mut cx| async move {
cx.spawn(async move |_, cx| {
for image in images {
if let Some(rec) = image.update(&mut cx, |image, cx| image.reload(cx))? {
if let Some(rec) = image.update(cx, |image, cx| image.reload(cx))? {
rec.await?
}
}
+2 -2
View File
@@ -2957,14 +2957,14 @@ impl LspCommand for InlayHints {
};
let buffer = buffer.clone();
cx.spawn(move |mut cx| async move {
cx.spawn(async move |cx| {
InlayHints::lsp_to_project_hint(
lsp_hint,
&buffer,
server_id,
resolve_state,
force_no_type_left_padding,
&mut cx,
cx,
)
.await
})
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -44,9 +44,9 @@ pub fn register_notifications(
let adapter = adapter.clone();
let this = lsp_store;
move |params: InactiveRegionsParams, mut cx| {
move |params: InactiveRegionsParams, cx| {
let adapter = adapter.clone();
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
let diagnostics = params
.regions
.into_iter()
@@ -51,7 +51,7 @@ pub fn register_notifications(lsp_store: WeakEntity<LspStore>, language_server:
language_server
.on_notification::<ServerStatus, _>({
let name = name.to_string();
move |params, mut cx| {
move |params, cx| {
let this = this.clone();
let name = name.to_string();
if let Some(ref message) = params.message {
@@ -74,7 +74,7 @@ pub fn register_notifications(lsp_store: WeakEntity<LspStore>, language_server:
lsp_name: name.clone(),
};
let _ = this
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
cx.emit(LspStoreEvent::LanguageServerPrompt(request));
})
.ok();
+25 -25
View File
@@ -86,11 +86,11 @@ impl PrettierStore {
}
}
}
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
while let Some(prettier_server_id) = prettier_instances_to_clean.next().await {
if let Some(prettier_server_id) = prettier_server_id {
prettier_store
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
cx.emit(PrettierStoreEvent::LanguageServerRemoved(
prettier_server_id,
));
@@ -119,7 +119,7 @@ impl PrettierStore {
Some((worktree_id, buffer_path)) => {
let fs = Arc::clone(&self.fs);
let installed_prettiers = self.prettier_instances.keys().cloned().collect();
cx.spawn(|lsp_store, mut cx| async move {
cx.spawn(async move |lsp_store, cx| {
match cx
.background_spawn(async move {
Prettier::locate_prettier_installation(
@@ -134,7 +134,7 @@ impl PrettierStore {
Ok(ControlFlow::Break(())) => None,
Ok(ControlFlow::Continue(None)) => {
let default_instance = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
lsp_store
.prettiers_per_worktree
.entry(worktree_id)
@@ -151,7 +151,7 @@ impl PrettierStore {
}
Ok(ControlFlow::Continue(Some(prettier_dir))) => {
lsp_store
.update(&mut cx, |lsp_store, _| {
.update(cx, |lsp_store, _| {
lsp_store
.prettiers_per_worktree
.entry(worktree_id)
@@ -160,7 +160,7 @@ impl PrettierStore {
})
.ok()?;
if let Some(prettier_task) = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
lsp_store.prettier_instances.get_mut(&prettier_dir).map(
|existing_instance| {
existing_instance.prettier_task(
@@ -180,7 +180,7 @@ impl PrettierStore {
log::info!("Found prettier in {prettier_dir:?}, starting.");
let new_prettier_task = lsp_store
.update(&mut cx, |lsp_store, cx| {
.update(cx, |lsp_store, cx| {
let new_prettier_task = Self::start_prettier(
node,
prettier_dir.clone(),
@@ -208,7 +208,7 @@ impl PrettierStore {
}
None => {
let new_task = self.default_prettier.prettier_task(&node, None, cx);
cx.spawn(|_, _| async move { Some((None, new_task?.log_err().await?)) })
cx.spawn(async move |_, _| Some((None, new_task?.log_err().await?)))
}
}
}
@@ -231,7 +231,7 @@ impl PrettierStore {
.get(&worktree_id)
.cloned()
.unwrap_or_default();
cx.spawn(|lsp_store, mut cx| async move {
cx.spawn(async move |lsp_store, cx| {
match cx
.background_spawn(async move {
Prettier::locate_prettier_ignore(
@@ -248,7 +248,7 @@ impl PrettierStore {
Ok(ControlFlow::Continue(Some(ignore_dir))) => {
log::debug!("Found prettier ignore in {ignore_dir:?}");
lsp_store
.update(&mut cx, |store, _| {
.update(cx, |store, _| {
store
.prettier_ignores_per_worktree
.entry(worktree_id)
@@ -277,9 +277,9 @@ impl PrettierStore {
worktree_id: Option<WorktreeId>,
cx: &mut Context<Self>,
) -> PrettierTask {
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
log::info!("Starting prettier at path {prettier_dir:?}");
let new_server_id = prettier_store.update(&mut cx, |prettier_store, _| {
let new_server_id = prettier_store.update(cx, |prettier_store, _| {
prettier_store.languages.next_language_server_id()
})?;
@@ -293,7 +293,7 @@ impl PrettierStore {
&new_prettier,
worktree_id,
new_server_id,
&mut cx,
cx,
);
Ok(new_prettier)
})
@@ -305,8 +305,8 @@ impl PrettierStore {
worktree_id: Option<WorktreeId>,
cx: &mut Context<PrettierStore>,
) -> Task<anyhow::Result<PrettierTask>> {
cx.spawn(|prettier_store, mut cx| async move {
let installation_task = prettier_store.update(&mut cx, |prettier_store, _| {
cx.spawn(async move |prettier_store, cx| {
let installation_task = prettier_store.update(cx, |prettier_store, _| {
match &prettier_store.default_prettier.prettier {
PrettierInstallation::NotInstalled {
installation_task, ..
@@ -323,7 +323,7 @@ impl PrettierStore {
ControlFlow::Continue(Some(installation_task)) => {
log::info!("Waiting for default prettier to install");
if let Err(e) = installation_task.await {
prettier_store.update(&mut cx, |project, _| {
prettier_store.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled {
installation_task,
attempts,
@@ -339,7 +339,7 @@ impl PrettierStore {
);
}
let new_default_prettier =
prettier_store.update(&mut cx, |prettier_store, cx| {
prettier_store.update(cx, |prettier_store, cx| {
let new_default_prettier = Self::start_prettier(
node,
default_prettier_dir().clone(),
@@ -359,7 +359,7 @@ impl PrettierStore {
Some(instance) => Ok(instance),
None => {
let new_default_prettier =
prettier_store.update(&mut cx, |prettier_store, cx| {
prettier_store.update(cx, |prettier_store, cx| {
let new_default_prettier = Self::start_prettier(
node,
default_prettier_dir().clone(),
@@ -578,7 +578,7 @@ impl PrettierStore {
let plugins_to_install = new_plugins.clone();
let fs = Arc::clone(&self.fs);
let new_installation_task = cx
.spawn(|project, mut cx| async move {
.spawn(async move |project, cx| {
match locate_prettier_installation
.await
.context("locate prettier installation")
@@ -593,7 +593,7 @@ impl PrettierStore {
if let Some(previous_installation_task) = previous_installation_task {
if let Err(e) = previous_installation_task.await {
log::error!("Failed to install default prettier: {e:#}");
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled { attempts, not_installed_plugins, .. } = &mut project.default_prettier.prettier {
*attempts += 1;
new_plugins.extend(not_installed_plugins.iter().cloned());
@@ -604,7 +604,7 @@ impl PrettierStore {
}
};
if installation_attempt > prettier::FAIL_THRESHOLD {
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
if let PrettierInstallation::NotInstalled { installation_task, .. } = &mut project.default_prettier.prettier {
*installation_task = None;
};
@@ -614,7 +614,7 @@ impl PrettierStore {
);
return Ok(());
}
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
new_plugins.retain(|plugin| {
!project.default_prettier.installed_plugins.contains(plugin)
});
@@ -638,7 +638,7 @@ impl PrettierStore {
.context("prettier & plugins install")
.map_err(Arc::new)?;
log::info!("Initialized prettier with plugins: {installed_plugins:?}");
project.update(&mut cx, |project, _| {
project.update(cx, |project, _| {
project.default_prettier.prettier =
PrettierInstallation::Installed(PrettierInstance {
attempt: 0,
@@ -865,9 +865,9 @@ impl PrettierInstance {
None => {
self.attempt += 1;
let node = node.clone();
cx.spawn(|prettier_store, mut cx| async move {
cx.spawn(async move |prettier_store, cx| {
prettier_store
.update(&mut cx, |_, cx| {
.update(cx, |_, cx| {
PrettierStore::start_default_prettier(node, worktree_id, cx)
})?
.await
+60 -63
View File
@@ -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()
+1 -1
View File
@@ -580,7 +580,7 @@ impl SettingsObserver {
}
let worktree = worktree.clone();
cx.spawn(move |this, cx| async move {
cx.spawn(async move |this, cx| {
let settings_contents: Vec<(Arc<Path>, _, _)> =
futures::future::join_all(settings_contents).await;
cx.update(|cx| {
+7 -7
View File
@@ -312,9 +312,9 @@ impl TaskStore {
) -> Task<()> {
let mut user_tasks_file_rx = watch_config_file(&cx.background_executor(), fs, file_path);
let user_tasks_content = cx.background_executor().block(user_tasks_file_rx.next());
cx.spawn(move |task_store, mut cx| async move {
cx.spawn(async move |task_store, cx| {
if let Some(user_tasks_content) = user_tasks_content {
let Ok(_) = task_store.update(&mut cx, |task_store, cx| {
let Ok(_) = task_store.update(cx, |task_store, cx| {
task_store
.update_user_tasks(None, Some(&user_tasks_content), task_kind, cx)
.log_err();
@@ -323,7 +323,7 @@ impl TaskStore {
};
}
while let Some(user_tasks_content) = user_tasks_file_rx.next().await {
let Ok(()) = task_store.update(&mut cx, |task_store, cx| {
let Ok(()) = task_store.update(cx, |task_store, cx| {
let result = task_store.update_user_tasks(
None,
Some(&user_tasks_content),
@@ -359,10 +359,10 @@ fn local_task_context_for_location(
.and_then(|worktree_id| worktree_store.read(cx).worktree_for_id(worktree_id, cx))
.and_then(|worktree| worktree.read(cx).root_dir());
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
let worktree_abs_path = worktree_abs_path.clone();
let project_env = environment
.update(&mut cx, |environment, cx| {
.update(cx, |environment, cx| {
environment.get_environment(worktree_id, worktree_abs_path.clone(), cx)
})
.ok()?
@@ -402,7 +402,7 @@ fn remote_task_context_for_location(
toolchain_store: Arc<dyn LanguageToolchainStore>,
cx: &mut App,
) -> Task<Option<TaskContext>> {
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
// We need to gather a client context, as the headless one may lack certain information (e.g. tree-sitter parsing is disabled there, so symbols are not available).
let mut remote_context = cx
.update(|cx| {
@@ -469,7 +469,7 @@ fn combine_task_variables(
.read(cx)
.language()
.and_then(|language| language.context_provider());
cx.spawn(move |cx| async move {
cx.spawn(async move |cx| {
let baseline = cx
.update(|cx| {
baseline.build_context(
+7 -7
View File
@@ -115,17 +115,17 @@ impl Project {
}
let settings = TerminalSettings::get(settings_location, cx).clone();
cx.spawn(move |project, mut cx| async move {
cx.spawn(async move |project, cx| {
let python_venv_directory = if let Some(path) = path.clone() {
project
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.python_venv_directory(path, settings.detect_venv.clone(), cx)
})?
.await
} else {
None
};
project.update(&mut cx, |project, cx| {
project.update(cx, |project, cx| {
project.create_terminal_with_venv(kind, python_venv_directory, window, cx)
})?
})
@@ -406,13 +406,13 @@ impl Project {
venv_settings: VenvSettings,
cx: &Context<Project>,
) -> Task<Option<PathBuf>> {
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
if let Some((worktree, _)) = this
.update(&mut cx, |this, cx| this.find_worktree(&abs_path, cx))
.update(cx, |this, cx| this.find_worktree(&abs_path, cx))
.ok()?
{
let toolchain = this
.update(&mut cx, |this, cx| {
.update(cx, |this, cx| {
this.active_toolchain(
worktree.read(cx).id(),
LanguageName::new("Python"),
@@ -428,7 +428,7 @@ impl Project {
}
}
let venv_settings = venv_settings.as_option()?;
this.update(&mut cx, move |this, cx| {
this.update(cx, move |this, cx| {
if let Some(path) = this.find_venv_in_worktree(&abs_path, &venv_settings, cx) {
return Some(path);
}
+7 -7
View File
@@ -288,8 +288,8 @@ impl LocalToolchainStore {
toolchain: Toolchain,
cx: &mut Context<Self>,
) -> Task<Option<()>> {
cx.spawn(move |this, mut cx| async move {
this.update(&mut cx, |this, cx| {
cx.spawn(async move |this, cx| {
this.update(cx, |this, cx| {
this.active_toolchains.insert(
(worktree_id, toolchain.language_name.clone()),
toolchain.clone(),
@@ -317,9 +317,9 @@ impl LocalToolchainStore {
};
let environment = self.project_environment.clone();
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
let project_env = environment
.update(&mut cx, |environment, cx| {
.update(cx, |environment, cx| {
environment.get_environment(Some(worktree_id), Some(root.clone()), cx)
})
.ok()?
@@ -363,7 +363,7 @@ impl RemoteToolchainStore {
) -> Task<Option<()>> {
let project_id = self.project_id;
let client = self.client.clone();
cx.spawn(move |_| async move {
cx.spawn(async move |_| {
let path = PathBuf::from(toolchain.path.to_string());
let _ = client
.request(proto::ActivateToolchain {
@@ -390,7 +390,7 @@ impl RemoteToolchainStore {
) -> Task<Option<ToolchainList>> {
let project_id = self.project_id;
let client = self.client.clone();
cx.spawn(move |_| async move {
cx.spawn(async move |_| {
let response = client
.request(proto::ListToolchains {
project_id,
@@ -441,7 +441,7 @@ impl RemoteToolchainStore {
) -> Task<Option<Toolchain>> {
let project_id = self.project_id;
let client = self.client.clone();
cx.spawn(move |_| async move {
cx.spawn(async move |_| {
let response = client
.request(proto::ActiveToolchain {
project_id,
+10 -10
View File
@@ -237,9 +237,9 @@ impl WorktreeStore {
.insert(abs_path.clone(), task.shared());
}
let task = self.loading_worktrees.get(&abs_path).unwrap().clone();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let result = task.await;
this.update(&mut cx, |this, _| this.loading_worktrees.remove(&abs_path))
this.update(cx, |this, _| this.loading_worktrees.remove(&abs_path))
.ok();
match result {
Ok(worktree) => Ok(worktree),
@@ -266,7 +266,7 @@ impl WorktreeStore {
if abs_path.is_empty() || abs_path == "/" {
abs_path = "~/".to_string();
}
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let this = this.upgrade().context("Dropped worktree store")?;
let path = Path::new(abs_path.as_str());
@@ -278,7 +278,7 @@ impl WorktreeStore {
})
.await?;
if let Some(existing_worktree) = this.read_with(&cx, |this, cx| {
if let Some(existing_worktree) = this.read_with(cx, |this, cx| {
this.worktree_for_id(WorktreeId::from_proto(response.worktree_id), cx)
})? {
return Ok(existing_worktree);
@@ -305,7 +305,7 @@ impl WorktreeStore {
)
})?;
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.add(&worktree, cx);
})?;
Ok(worktree)
@@ -322,12 +322,12 @@ impl WorktreeStore {
let next_entry_id = self.next_entry_id.clone();
let path: SanitizedPath = abs_path.into();
cx.spawn(move |this, mut cx| async move {
let worktree = Worktree::local(path.clone(), visible, fs, next_entry_id, &mut cx).await;
cx.spawn(async move |this, cx| {
let worktree = Worktree::local(path.clone(), visible, fs, next_entry_id, cx).await;
let worktree = worktree?;
this.update(&mut cx, |this, cx| this.add(&worktree, cx))?;
this.update(cx, |this, cx| this.add(&worktree, cx))?;
if visible {
cx.update(|cx| {
@@ -554,12 +554,12 @@ impl WorktreeStore {
downstream_client.send(update).log_err();
None
};
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
if let Some(update_project) = update_project {
update_project.await?;
}
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
let worktrees = this.worktrees().collect::<Vec<_>>();
for worktree in worktrees {
+4 -4
View File
@@ -91,9 +91,9 @@ impl YarnPathStore {
};
if let Some(zip_file) = zip_path(&path) {
let zip_file: Arc<Path> = Arc::from(zip_file);
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let dir = this
.update(&mut cx, |this, _| {
.update(cx, |this, _| {
this.temp_dirs
.get(&zip_file)
.map(|temp| temp.path().to_owned())
@@ -102,10 +102,10 @@ impl YarnPathStore {
let zip_root = if let Some(dir) = dir {
dir
} else {
let fs = this.update(&mut cx, |this, _| this.fs.clone()).ok()?;
let fs = this.update(cx, |this, _| this.fs.clone()).ok()?;
let tempdir = dump_zip(zip_file.clone(), fs).await.log_err()?;
let new_path = tempdir.path().to_owned();
this.update(&mut cx, |this, _| {
this.update(cx, |this, _| {
this.temp_dirs.insert(zip_file.clone(), tempdir);
})
.ok()?;