Fix warnings/errors now that AsyncAppContext::update returns Result

This commit is contained in:
Antonio Scandurra 2023-04-18 14:58:57 +02:00
parent 31e6bb4fc1
commit d03c431f9a
33 changed files with 494 additions and 371 deletions

View file

@ -20,7 +20,7 @@ mod editor_tests;
pub mod test;
use aho_corasick::AhoCorasick;
use anyhow::Result;
use anyhow::{anyhow, Result};
use blink_manager::BlinkManager;
use clock::ReplicaId;
use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
@ -2397,7 +2397,7 @@ impl Editor {
} else if this.hide_context_menu(cx).is_none() {
this.update_visible_copilot_suggestion(cx);
}
});
})?;
}
Ok::<_, anyhow::Error>(())
}
@ -2534,11 +2534,13 @@ impl Editor {
prev_task.await;
task = this
.upgrade(&cx)
.and_then(|this| this.update(&mut cx, |this, _| this.code_actions_task.take()));
.ok_or_else(|| anyhow!("editor dropped"))?
.update(&mut cx, |this, _| this.code_actions_task.take())?;
}
if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| {
this.upgrade(&cx)
.ok_or_else(|| anyhow!("editor dropped"))?
.update(&mut cx, |this, cx| {
if this.focused {
if let Some((buffer, actions)) = this.available_code_actions.clone() {
this.show_context_menu(
@ -2553,8 +2555,8 @@ impl Editor {
);
}
}
})
}
})?;
Ok::<_, anyhow::Error>(())
})
.detach_and_log_err(cx);
@ -2666,7 +2668,7 @@ impl Editor {
cx,
);
});
});
})?;
Ok(())
}
@ -2697,6 +2699,7 @@ impl Editor {
});
cx.notify();
})
.log_err();
}
}));
None
@ -2786,7 +2789,8 @@ impl Editor {
cx,
);
cx.notify();
});
})
.log_err();
}
}));
None
@ -2823,17 +2827,19 @@ impl Editor {
let mut completions = Vec::new();
completions.extend(completion.log_err().into_iter().flatten());
completions.extend(completions_cycling.log_err().into_iter().flatten());
this.upgrade(&cx)?.update(&mut cx, |this, cx| {
if !completions.is_empty() {
this.copilot_state.completions.clear();
this.copilot_state.active_completion_index = 0;
this.copilot_state.excerpt_id = Some(cursor.excerpt_id);
for completion in completions {
this.copilot_state.push_completion(completion);
this.upgrade(&cx)?
.update(&mut cx, |this, cx| {
if !completions.is_empty() {
this.copilot_state.completions.clear();
this.copilot_state.active_completion_index = 0;
this.copilot_state.excerpt_id = Some(cursor.excerpt_id);
for completion in completions {
this.copilot_state.push_completion(completion);
}
this.update_visible_copilot_suggestion(cx);
}
this.update_visible_copilot_suggestion(cx);
}
});
})
.log_err()?;
Some(())
});
@ -5416,7 +5422,7 @@ impl Editor {
let definitions = definitions.await?;
workspace.update(&mut cx, |workspace, cx| {
Editor::navigate_to_definitions(workspace, editor_handle, definitions, cx);
});
})?;
Ok::<(), anyhow::Error>(())
})
@ -5517,7 +5523,7 @@ impl Editor {
Self::open_locations_in_multibuffer(
workspace, locations, replica_id, title, cx,
);
});
})?;
Ok(())
},
@ -5705,7 +5711,7 @@ impl Editor {
editor: rename_editor,
block_id,
});
});
})?;
}
Ok(())
@ -5751,7 +5757,7 @@ impl Editor {
editor.update(&mut cx, |editor, cx| {
editor.refresh_document_highlights(cx);
});
})?;
Ok(())
}))
}
@ -6552,9 +6558,16 @@ impl Editor {
let position = action.position;
let anchor = action.anchor;
cx.spawn_weak(|_, mut cx| async move {
let editor = editor.await.log_err()?.downcast::<Editor>()?;
let editor = editor
.await?
.downcast::<Editor>()
.ok_or_else(|| anyhow!("opened item was not an editor"))?;
editor.update(&mut cx, |editor, cx| {
let buffer = editor.buffer().read(cx).as_singleton()?;
let buffer = editor
.buffer()
.read(cx)
.as_singleton()
.ok_or_else(|| anyhow!("cannot jump in a multi-buffer"))?;
let buffer = buffer.read(cx);
let cursor = if buffer.can_resolve(&anchor) {
language::ToPoint::to_point(&anchor, buffer)
@ -6568,11 +6581,11 @@ impl Editor {
});
editor.nav_history = nav_history;
Some(())
})?;
Some(())
anyhow::Ok(())
})??;
anyhow::Ok(())
})
.detach()
.detach_and_log_err(cx);
}
fn marked_text_ranges(&self, cx: &AppContext) -> Option<Vec<Range<OffsetUtf16>>> {

View file

@ -208,7 +208,7 @@ fn show_hover(
local_diagnostic,
primary_diagnostic,
});
});
})?;
}
// Construct new hover popover from hover request
@ -254,7 +254,7 @@ fn show_hover(
this.hover_state.info_popover = hover_popover;
cx.notify();
});
})?;
}
Ok::<_, anyhow::Error>(())
}

View file

@ -80,7 +80,9 @@ impl FollowableItem for Editor {
})
});
let editor = editor.unwrap_or_else(|| {
let editor = if let Some(editor) = editor {
editor
} else {
pane.update(&mut cx, |_, cx| {
let multibuffer = cx.add_model(|cx| {
let mut multibuffer;
@ -116,8 +118,8 @@ impl FollowableItem for Editor {
});
cx.add_view(|cx| Editor::for_multibuffer(multibuffer, Some(project), cx))
})
});
})?
};
editor.update(&mut cx, |editor, cx| {
editor.remote_id = Some(remote_id);
@ -154,7 +156,7 @@ impl FollowableItem for Editor {
}
anyhow::Ok(())
})?;
})??;
Ok(editor)
}))
@ -387,7 +389,7 @@ impl FollowableItem for Editor {
offset: vec2f(message.scroll_x, message.scroll_y)
}, cx);
}
});
})?;
Ok(())
})
}
@ -670,7 +672,7 @@ impl Item for Editor {
let transaction = reload_buffers.log_err().await;
this.update(&mut cx, |editor, cx| {
editor.request_autoscroll(Autoscroll::fit(), cx)
});
})?;
buffer.update(&mut cx, |buffer, _| {
if let Some(transaction) = transaction {
if !buffer.is_singleton() {

View file

@ -261,7 +261,7 @@ pub fn show_link_definition(
hide_link_definition(this, cx);
}
}
})
})?;
}
Ok::<_, anyhow::Error>(())

View file

@ -248,10 +248,12 @@ impl ScrollManager {
self.hide_scrollbar_task = Some(cx.spawn_weak(|editor, mut cx| async move {
cx.background().timer(SCROLLBAR_SHOW_INTERVAL).await;
if let Some(editor) = editor.upgrade(&cx) {
editor.update(&mut cx, |editor, cx| {
editor.scroll_manager.show_scrollbars = false;
cx.notify();
});
editor
.update(&mut cx, |editor, cx| {
editor.scroll_manager.show_scrollbars = false;
cx.notify();
})
.log_err();
}
}));
} else {