Remove unnecessary calls to WeakViewHandle::upgrade

This commit is contained in:
Antonio Scandurra 2023-04-26 11:13:46 +02:00
parent 94c2eaad23
commit 2b6830c798
19 changed files with 378 additions and 443 deletions

View file

@ -65,7 +65,6 @@ impl ActivityIndicator {
let mut status_events = languages.language_server_binary_statuses(); let mut status_events = languages.language_server_binary_statuses();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
while let Some((language, event)) = status_events.next().await { while let Some((language, event)) = status_events.next().await {
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.statuses.retain(|s| s.name != language.name()); this.statuses.retain(|s| s.name != language.name());
this.statuses.push(LspStatus { this.statuses.push(LspStatus {
@ -74,9 +73,6 @@ impl ActivityIndicator {
}); });
cx.notify(); cx.notify();
})?; })?;
} else {
break;
}
} }
anyhow::Ok(()) anyhow::Ok(())
}) })

View file

@ -104,7 +104,6 @@ pub fn notify_of_any_new_update(
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let should_show_notification = should_show_notification.await?; let should_show_notification = should_show_notification.await?;
if should_show_notification { if should_show_notification {
if let Some(workspace) = workspace.upgrade(&cx) {
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
workspace.show_notification(0, cx, |cx| { workspace.show_notification(0, cx, |cx| {
cx.add_view(|_| UpdateNotification::new(version)) cx.add_view(|_| UpdateNotification::new(version))
@ -115,7 +114,6 @@ pub fn notify_of_any_new_update(
.detach_and_log_err(cx); .detach_and_log_err(cx);
})?; })?;
} }
}
anyhow::Ok(()) anyhow::Ok(())
}) })
.detach(); .detach();

View file

@ -2510,9 +2510,6 @@ impl Editor {
None None
}; };
let this = this
.upgrade(&cx)
.ok_or_else(|| anyhow!("editor was dropped"))?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.completion_tasks.retain(|(task_id, _)| *task_id > id); this.completion_tasks.retain(|(task_id, _)| *task_id > id);
@ -2672,15 +2669,10 @@ impl Editor {
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
while let Some(prev_task) = task { while let Some(prev_task) = task {
prev_task.await; prev_task.await;
task = this task = this.update(&mut cx, |this, _| this.code_actions_task.take())?;
.upgrade(&cx)
.ok_or_else(|| anyhow!("editor dropped"))?
.update(&mut cx, |this, _| this.code_actions_task.take())?;
} }
this.upgrade(&cx) this.update(&mut cx, |this, cx| {
.ok_or_else(|| anyhow!("editor dropped"))?
.update(&mut cx, |this, cx| {
if this.focused { if this.focused {
if let Some((buffer, actions)) = this.available_code_actions.clone() { if let Some((buffer, actions)) = this.available_code_actions.clone() {
this.show_context_menu( this.show_context_menu(
@ -2828,7 +2820,6 @@ impl Editor {
}); });
self.code_actions_task = Some(cx.spawn(|this, mut cx| async move { self.code_actions_task = Some(cx.spawn(|this, mut cx| async move {
let actions = actions.await; let actions = actions.await;
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.available_code_actions = actions.log_err().and_then(|actions| { this.available_code_actions = actions.log_err().and_then(|actions| {
if actions.is_empty() { if actions.is_empty() {
@ -2840,7 +2831,6 @@ impl Editor {
cx.notify(); cx.notify();
}) })
.log_err(); .log_err();
}
})); }));
None None
} }
@ -2866,8 +2856,7 @@ impl Editor {
}); });
self.document_highlights_task = Some(cx.spawn(|this, mut cx| async move { self.document_highlights_task = Some(cx.spawn(|this, mut cx| async move {
let highlights = highlights.log_err().await; if let Some(highlights) = highlights.await.log_err() {
if let Some((this, highlights)) = this.upgrade(&cx).zip(highlights) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if this.pending_rename.is_some() { if this.pending_rename.is_some() {
return; return;
@ -2976,8 +2965,7 @@ impl Editor {
.flatten() .flatten()
.collect_vec(); .collect_vec();
this.upgrade(&cx)? this.update(&mut cx, |this, cx| {
.update(&mut cx, |this, cx| {
if !completions.is_empty() { if !completions.is_empty() {
this.copilot_state.cycled = false; this.copilot_state.cycled = false;
this.copilot_state.pending_cycling_refresh = Task::ready(None); this.copilot_state.pending_cycling_refresh = Task::ready(None);
@ -3021,8 +3009,7 @@ impl Editor {
}) })
.await; .await;
this.upgrade(&cx)? this.update(&mut cx, |this, cx| {
.update(&mut cx, |this, cx| {
this.copilot_state.cycled = true; this.copilot_state.cycled = true;
for completion in completions.log_err().into_iter().flatten() { for completion in completions.log_err().into_iter().flatten() {
this.copilot_state.push_completion(completion); this.copilot_state.push_completion(completion);

View file

@ -201,7 +201,6 @@ fn show_hover(
}) })
}); });
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, _| { this.update(&mut cx, |this, _| {
this.hover_state.diagnostic_popover = this.hover_state.diagnostic_popover =
local_diagnostic.map(|local_diagnostic| DiagnosticPopover { local_diagnostic.map(|local_diagnostic| DiagnosticPopover {
@ -209,7 +208,6 @@ fn show_hover(
primary_diagnostic, primary_diagnostic,
}); });
})?; })?;
}
// Construct new hover popover from hover request // Construct new hover popover from hover request
let hover_popover = hover_request.await.ok().flatten().and_then(|hover_result| { let hover_popover = hover_request.await.ok().flatten().and_then(|hover_result| {
@ -239,7 +237,6 @@ fn show_hover(
}) })
}); });
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if let Some(hover_popover) = hover_popover.as_ref() { if let Some(hover_popover) = hover_popover.as_ref() {
// Highlight the selected symbol using a background highlight // Highlight the selected symbol using a background highlight
@ -255,7 +252,7 @@ fn show_hover(
this.hover_state.info_popover = hover_popover; this.hover_state.info_popover = hover_popover;
cx.notify(); cx.notify();
})?; })?;
}
Ok::<_, anyhow::Error>(()) Ok::<_, anyhow::Error>(())
} }
.log_err() .log_err()

View file

@ -202,7 +202,6 @@ pub fn show_link_definition(
) )
}); });
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
// Clear any existing highlights // Clear any existing highlights
this.clear_text_highlights::<LinkGoToDefinitionState>(cx); this.clear_text_highlights::<LinkGoToDefinitionState>(cx);
@ -262,7 +261,6 @@ pub fn show_link_definition(
} }
} }
})?; })?;
}
Ok::<_, anyhow::Error>(()) Ok::<_, anyhow::Error>(())
} }

View file

@ -247,14 +247,12 @@ impl ScrollManager {
if cx.default_global::<ScrollbarAutoHide>().0 { if cx.default_global::<ScrollbarAutoHide>().0 {
self.hide_scrollbar_task = Some(cx.spawn(|editor, mut cx| async move { self.hide_scrollbar_task = Some(cx.spawn(|editor, mut cx| async move {
cx.background().timer(SCROLLBAR_SHOW_INTERVAL).await; cx.background().timer(SCROLLBAR_SHOW_INTERVAL).await;
if let Some(editor) = editor.upgrade(&cx) {
editor editor
.update(&mut cx, |editor, cx| { .update(&mut cx, |editor, cx| {
editor.scroll_manager.show_scrollbars = false; editor.scroll_manager.show_scrollbars = false;
cx.notify(); cx.notify();
}) })
.log_err(); .log_err();
}
})); }));
} else { } else {
self.hide_scrollbar_task = None; self.hide_scrollbar_task = None;

View file

@ -104,10 +104,8 @@ impl<V: View> Tooltip<V> {
|view, mut cx| async move { |view, mut cx| async move {
cx.background().timer(DEBOUNCE_TIMEOUT).await; cx.background().timer(DEBOUNCE_TIMEOUT).await;
state.visible.set(true); state.visible.set(true);
if let Some(view) = view.upgrade(&cx) {
view.update(&mut cx, |_, cx| cx.notify()).log_err(); view.update(&mut cx, |_, cx| cx.notify()).log_err();
} }
}
})); }));
} }
} }

View file

@ -162,7 +162,6 @@ impl PickerDelegate for LanguageSelectorDelegate {
.await .await
}; };
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let delegate = this.delegate_mut(); let delegate = this.delegate_mut();
delegate.matches = matches; delegate.matches = matches;
@ -172,7 +171,6 @@ impl PickerDelegate for LanguageSelectorDelegate {
cx.notify(); cx.notify();
}) })
.log_err(); .log_err();
}
}) })
} }

View file

@ -240,8 +240,7 @@ impl<D: PickerDelegate> Picker<D> {
self.matches_updated(cx); self.matches_updated(cx);
self.pending_update_matches = cx.spawn(|this, mut cx| async move { self.pending_update_matches = cx.spawn(|this, mut cx| async move {
update.await; update.await;
this.upgrade(&cx)? this.update(&mut cx, |this, cx| this.matches_updated(cx))
.update(&mut cx, |this, cx| this.matches_updated(cx))
.log_err() .log_err()
}); });
} }

View file

@ -1,4 +1,3 @@
use anyhow::anyhow;
use editor::{ use editor::{
combine_syntax_and_fuzzy_match_highlights, scroll::autoscroll::Autoscroll, combine_syntax_and_fuzzy_match_highlights, scroll::autoscroll::Autoscroll,
styled_runs_for_code_label, Bias, Editor, styled_runs_for_code_label, Bias, Editor,
@ -119,9 +118,6 @@ impl PickerDelegate for ProjectSymbolsDelegate {
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
let buffer = buffer.await?; let buffer = buffer.await?;
let workspace = workspace
.upgrade(&cx)
.ok_or_else(|| anyhow!("workspace was dropped"))?;
workspace.update(&mut cx, |workspace, cx| { workspace.update(&mut cx, |workspace, cx| {
let position = buffer let position = buffer
.read(cx) .read(cx)
@ -163,7 +159,6 @@ impl PickerDelegate for ProjectSymbolsDelegate {
.update(cx, |project, cx| project.symbols(&query, cx)); .update(cx, |project, cx| project.symbols(&query, cx));
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
let symbols = symbols.await.log_err(); let symbols = symbols.await.log_err();
if let Some(this) = this.upgrade(&cx) {
if let Some(symbols) = symbols { if let Some(symbols) = symbols {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let delegate = this.delegate_mut(); let delegate = this.delegate_mut();
@ -174,8 +169,7 @@ impl PickerDelegate for ProjectSymbolsDelegate {
.map(|(id, symbol)| { .map(|(id, symbol)| {
StringMatchCandidate::new( StringMatchCandidate::new(
id, id,
symbol.label.text[symbol.label.filter_range.clone()] symbol.label.text[symbol.label.filter_range.clone()].to_string(),
.to_string(),
) )
}) })
.partition(|candidate| { .partition(|candidate| {
@ -191,7 +185,6 @@ impl PickerDelegate for ProjectSymbolsDelegate {
}) })
.log_err(); .log_err();
} }
}
}) })
} }

View file

@ -196,16 +196,15 @@ impl ToolbarItemView for BufferSearchBar {
if let Some(searchable_item_handle) = if let Some(searchable_item_handle) =
item.and_then(|item| item.to_searchable_item_handle(cx)) item.and_then(|item| item.to_searchable_item_handle(cx))
{ {
let handle = cx.weak_handle(); let this = cx.weak_handle();
self.active_searchable_item_subscription = self.active_searchable_item_subscription =
Some(searchable_item_handle.subscribe_to_search_events( Some(searchable_item_handle.subscribe_to_search_events(
cx, cx,
Box::new(move |search_event, cx| { Box::new(move |search_event, cx| {
if let Some(this) = handle.upgrade(cx) {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.on_active_searchable_item_event(search_event, cx) this.on_active_searchable_item_event(search_event, cx)
}); })
} .log_err();
}), }),
)); ));
@ -584,12 +583,10 @@ impl BufferSearchBar {
let active_searchable_item = active_searchable_item.downgrade(); let active_searchable_item = active_searchable_item.downgrade();
self.pending_search = Some(cx.spawn(|this, mut cx| async move { self.pending_search = Some(cx.spawn(|this, mut cx| async move {
let matches = matches.await; let matches = matches.await;
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if let Some(active_searchable_item) = WeakSearchableItemHandle::upgrade( if let Some(active_searchable_item) =
active_searchable_item.as_ref(), WeakSearchableItemHandle::upgrade(active_searchable_item.as_ref(), cx)
cx, {
) {
this.seachable_items_with_matches this.seachable_items_with_matches
.insert(active_searchable_item.downgrade(), matches); .insert(active_searchable_item.downgrade(), matches);
@ -611,7 +608,6 @@ impl BufferSearchBar {
} }
}) })
.log_err(); .log_err();
}
})); }));
} }
} }

View file

@ -277,10 +277,8 @@ impl TerminalView {
let epoch = self.next_blink_epoch(); let epoch = self.next_blink_epoch();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
Timer::after(CURSOR_BLINK_INTERVAL).await; Timer::after(CURSOR_BLINK_INTERVAL).await;
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| this.blink_cursors(epoch, cx)) this.update(&mut cx, |this, cx| this.blink_cursors(epoch, cx))
.log_err(); .log_err();
}
}) })
.detach(); .detach();
} }
@ -293,10 +291,8 @@ impl TerminalView {
let epoch = self.next_blink_epoch(); let epoch = self.next_blink_epoch();
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
Timer::after(CURSOR_BLINK_INTERVAL).await; Timer::after(CURSOR_BLINK_INTERVAL).await;
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| this.resume_cursor_blinking(epoch, cx)) this.update(&mut cx, |this, cx| this.resume_cursor_blinking(epoch, cx))
.log_err(); .log_err();
}
}) })
.detach(); .detach();
} }

View file

@ -187,7 +187,6 @@ impl PickerDelegate for ThemeSelectorDelegate {
.await .await
}; };
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let delegate = this.delegate_mut(); let delegate = this.delegate_mut();
delegate.matches = matches; delegate.matches = matches;
@ -197,7 +196,6 @@ impl PickerDelegate for ThemeSelectorDelegate {
delegate.show_selected_theme(cx); delegate.show_selected_theme(cx);
}) })
.log_err(); .log_err();
}
}) })
} }

View file

@ -105,7 +105,6 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
.await .await
}; };
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, _| { this.update(&mut cx, |this, _| {
let delegate = this.delegate_mut(); let delegate = this.delegate_mut();
delegate.matches = matches; delegate.matches = matches;
@ -114,7 +113,6 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
.min(delegate.matches.len().saturating_sub(1)); .min(delegate.matches.len().saturating_sub(1));
}) })
.log_err(); .log_err();
}
}) })
} }

View file

@ -3,7 +3,7 @@ use crate::{
FollowableItemBuilders, ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace, FollowableItemBuilders, ItemNavHistory, Pane, ToolbarItemLocation, ViewId, Workspace,
WorkspaceId, WorkspaceId,
}; };
use anyhow::{anyhow, Result}; use anyhow::Result;
use client::{proto, Client}; use client::{proto, Client};
use gpui::{ use gpui::{
fonts::HighlightStyle, AnyElement, AnyViewHandle, AppContext, ModelHandle, Task, View, fonts::HighlightStyle, AnyElement, AnyViewHandle, AppContext, ModelHandle, Task, View,
@ -481,8 +481,6 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
} else { } else {
cx.spawn(|workspace, mut cx| async move { cx.spawn(|workspace, mut cx| async move {
workspace workspace
.upgrade(&cx)
.ok_or_else(|| anyhow!("workspace was dropped"))?
.update(&mut cx, |workspace, cx| { .update(&mut cx, |workspace, cx| {
item.git_diff_recalc( item.git_diff_recalc(
workspace.project().clone(), workspace.project().clone(),

View file

@ -2005,9 +2005,11 @@ impl NavHistory {
} }
fn did_update(&self, cx: &mut WindowContext) { fn did_update(&self, cx: &mut WindowContext) {
if let Some(pane) = self.pane.upgrade(cx) { let pane = self.pane.clone();
cx.defer(move |cx| pane.update(cx, |pane, cx| pane.history_updated(cx))); cx.defer(move |cx| {
} pane.update(cx, |pane, cx| pane.history_updated(cx))
.log_err();
});
} }
} }

View file

@ -6,7 +6,9 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use async_recursion::async_recursion; use async_recursion::async_recursion;
use gpui::{platform::WindowBounds, AsyncAppContext, Axis, ModelHandle, Task, ViewHandle}; use gpui::{
platform::WindowBounds, AsyncAppContext, Axis, ModelHandle, Task, ViewHandle, WeakViewHandle,
};
use db::sqlez::{ use db::sqlez::{
bindable::{Bind, Column, StaticColumnCount}, bindable::{Bind, Column, StaticColumnCount},
@ -97,7 +99,7 @@ impl SerializedPaneGroup {
&self, &self,
project: &ModelHandle<Project>, project: &ModelHandle<Project>,
workspace_id: WorkspaceId, workspace_id: WorkspaceId,
workspace: &ViewHandle<Workspace>, workspace: &WeakViewHandle<Workspace>,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Option<(Member, Option<ViewHandle<Pane>>)> { ) -> Option<(Member, Option<ViewHandle<Pane>>)> {
match self { match self {
@ -172,7 +174,7 @@ impl SerializedPane {
project: &ModelHandle<Project>, project: &ModelHandle<Project>,
pane_handle: &ViewHandle<Pane>, pane_handle: &ViewHandle<Pane>,
workspace_id: WorkspaceId, workspace_id: WorkspaceId,
workspace: &ViewHandle<Workspace>, workspace: &WeakViewHandle<Workspace>,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Result<()> { ) -> Result<()> {
let mut active_item_index = None; let mut active_item_index = None;
@ -181,13 +183,7 @@ impl SerializedPane {
let item_handle = pane_handle let item_handle = pane_handle
.update(cx, |_, cx| { .update(cx, |_, cx| {
if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) { if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) {
deserializer( deserializer(project, workspace.clone(), workspace_id, item.item_id, cx)
project,
workspace.downgrade(),
workspace_id,
item.item_id,
cx,
)
} else { } else {
Task::ready(Err(anyhow::anyhow!( Task::ready(Err(anyhow::anyhow!(
"Deserializer does not exist for item kind: {}", "Deserializer does not exist for item kind: {}",

View file

@ -599,14 +599,12 @@ impl DelayedDebouncedEditAction {
_ = timer => {} _ = timer => {}
} }
if let Some(workspace) = workspace.upgrade(&cx) {
if let Some(result) = workspace if let Some(result) = workspace
.update(&mut cx, |workspace, cx| (f)(workspace, cx)) .update(&mut cx, |workspace, cx| (f)(workspace, cx))
.log_err() .log_err()
{ {
result.await.log_err(); result.await.log_err();
} }
}
})); }));
} }
} }
@ -740,10 +738,8 @@ impl Workspace {
Stream::map(current_user, drop).merge(Stream::map(connection_status, drop)); Stream::map(current_user, drop).merge(Stream::map(connection_status, drop));
while stream.recv().await.is_some() { while stream.recv().await.is_some() {
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |_, cx| cx.notify())?; this.update(&mut cx, |_, cx| cx.notify())?;
} }
}
anyhow::Ok(()) anyhow::Ok(())
}); });
let handle = cx.handle(); let handle = cx.handle();
@ -754,8 +750,7 @@ impl Workspace {
mpsc::unbounded::<(PeerId, proto::UpdateFollowers)>(); mpsc::unbounded::<(PeerId, proto::UpdateFollowers)>();
let _apply_leader_updates = cx.spawn(|this, mut cx| async move { let _apply_leader_updates = cx.spawn(|this, mut cx| async move {
while let Some((leader_id, update)) = leader_updates_rx.next().await { while let Some((leader_id, update)) = leader_updates_rx.next().await {
let Some(this) = this.upgrade(&cx) else { break }; Self::process_leader_update(&this, leader_id, update, &mut cx)
Self::process_leader_update(this, leader_id, update, &mut cx)
.await .await
.log_err(); .log_err();
} }
@ -1977,7 +1972,6 @@ impl Workspace {
Some(cx.spawn(|this, mut cx| async move { Some(cx.spawn(|this, mut cx| async move {
let response = request.await?; let response = request.await?;
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, _| { this.update(&mut cx, |this, _| {
let state = this let state = this
.follower_states_by_leader .follower_states_by_leader
@ -2000,7 +1994,6 @@ impl Workspace {
) )
.await?; .await?;
this.update(&mut cx, |this, cx| this.leader_updated(leader_id, cx))?; this.update(&mut cx, |this, cx| this.leader_updated(leader_id, cx))?;
}
Ok(()) Ok(())
})) }))
} }
@ -2303,7 +2296,7 @@ impl Workspace {
} }
async fn process_leader_update( async fn process_leader_update(
this: ViewHandle<Self>, this: &WeakViewHandle<Self>,
leader_id: PeerId, leader_id: PeerId,
update: proto::UpdateFollowers, update: proto::UpdateFollowers,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
@ -2363,7 +2356,7 @@ impl Workspace {
} }
async fn add_views_from_leader( async fn add_views_from_leader(
this: ViewHandle<Self>, this: WeakViewHandle<Self>,
leader_id: PeerId, leader_id: PeerId,
panes: Vec<ViewHandle<Pane>>, panes: Vec<ViewHandle<Pane>>,
views: Vec<proto::View>, views: Vec<proto::View>,
@ -2691,7 +2684,6 @@ impl Workspace {
cx: &mut AppContext, cx: &mut AppContext,
) { ) {
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
if let Some(workspace) = workspace.upgrade(&cx) {
let (project, dock_pane_handle, old_center_pane) = let (project, dock_pane_handle, old_center_pane) =
workspace.read_with(&cx, |workspace, _| { workspace.read_with(&cx, |workspace, _| {
( (
@ -2765,8 +2757,7 @@ impl Workspace {
})?; })?;
// Serialize ourself to make sure our timestamps and any pane / item changes are replicated // Serialize ourself to make sure our timestamps and any pane / item changes are replicated
workspace.read_with(&cx, |workspace, cx| workspace.serialize_workspace(cx))? workspace.read_with(&cx, |workspace, cx| workspace.serialize_workspace(cx))?;
}
anyhow::Ok(()) anyhow::Ok(())
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);

View file

@ -509,7 +509,6 @@ fn open_log_file(
app_state.fs.load(&paths::LOG) app_state.fs.load(&paths::LOG)
); );
if let Some(workspace) = workspace.upgrade(&cx) {
let mut lines = VecDeque::with_capacity(MAX_LINES); let mut lines = VecDeque::with_capacity(MAX_LINES);
for line in old_log for line in old_log
.iter() .iter()
@ -538,14 +537,15 @@ fn open_log_file(
MultiBuffer::singleton(buffer, cx).with_title("Log".into()) MultiBuffer::singleton(buffer, cx).with_title("Log".into())
}); });
workspace.add_item( workspace.add_item(
Box::new(cx.add_view(|cx| { Box::new(
cx.add_view(|cx| {
Editor::for_multibuffer(buffer, Some(project), cx) Editor::for_multibuffer(buffer, Some(project), cx)
})), }),
),
cx, cx,
); );
}) })
.log_err(); .log_err();
}
}) })
.detach(); .detach();
}) })
@ -559,8 +559,6 @@ fn open_telemetry_log_file(
) { ) {
workspace.with_local_workspace(&app_state.clone(), cx, move |_, cx| { workspace.with_local_workspace(&app_state.clone(), cx, move |_, cx| {
cx.spawn(|workspace, mut cx| async move { cx.spawn(|workspace, mut cx| async move {
let workspace = workspace.upgrade(&cx)?;
async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> { async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
let path = app_state.client.telemetry_log_file_path()?; let path = app_state.client.telemetry_log_file_path()?;
app_state.fs.load(&path).await.log_err() app_state.fs.load(&path).await.log_err()