Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Change from try (reserved keyword) to maybe

Mikayla26a3d41dc75d
diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs
index dda638e107a..cfd61c17473 100644
--- a/crates/collab/src/rpc.rs
+++ b/crates/collab/src/rpc.rs
@@ -944,7 +944,7 @@ async fn create_room(
let live_kit_room = live_kit_room.clone();
let live_kit = session.live_kit_client.as_ref();
- util::async_iife!({
+ util::async_maybe!({
let live_kit = live_kit?;
let token = live_kit
diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs
index 8c33727cfba..69ba9859686 100644
--- a/crates/collab_ui/src/collab_panel.rs
+++ b/crates/collab_ui/src/collab_panel.rs
@@ -46,7 +46,7 @@ use serde_derive::{Deserialize, Serialize};
use settings::SettingsStore;
use std::{borrow::Cow, hash::Hash, mem, sync::Arc};
use theme::{components::ComponentExt, IconButton, Interactive};
-use util::{iife, ResultExt, TryFutureExt};
+use util::{maybe, ResultExt, TryFutureExt};
use workspace::{
dock::{DockPosition, Panel},
item::ItemHandle,
@@ -1487,7 +1487,7 @@ impl CollabPanel {
let text = match section {
Section::ActiveCall => {
- let channel_name = iife!({
+ let channel_name = maybe!({
let channel_id = ActiveCall::global(cx).read(cx).channel_id(cx)?;
let channel = self.channel_store.read(cx).channel_for_id(channel_id)?;
@@ -1929,7 +1929,7 @@ impl CollabPanel {
self.selected_channel().map(|channel| channel.0.id) == Some(channel.id);
let disclosed = has_children.then(|| !self.collapsed_channels.binary_search(&path).is_ok());
- let is_active = iife!({
+ let is_active = maybe!({
let call_channel = ActiveCall::global(cx)
.read(cx)
.room()?
@@ -2817,7 +2817,7 @@ impl CollabPanel {
}
}
ListEntry::Channel { channel, .. } => {
- let is_active = iife!({
+ let is_active = maybe!({
let call_channel = ActiveCall::global(cx)
.read(cx)
.room()?
diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs
index a28db249d34..9247c6e36d9 100644
--- a/crates/db/src/db.rs
+++ b/crates/db/src/db.rs
@@ -20,7 +20,7 @@ use std::future::Future;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use util::channel::ReleaseChannel;
-use util::{async_iife, ResultExt};
+use util::{async_maybe, ResultExt};
const CONNECTION_INITIALIZE_QUERY: &'static str = sql!(
PRAGMA foreign_keys=TRUE;
@@ -57,7 +57,7 @@ pub async fn open_db<M: Migrator + 'static>(
let release_channel_name = release_channel.dev_name();
let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name)));
- let connection = async_iife!({
+ let connection = async_maybe!({
smol::fs::create_dir_all(&main_db_dir)
.await
.context("Could not create db directory")
diff --git a/crates/project_panel/src/file_associations.rs b/crates/project_panel/src/file_associations.rs
index f2692b96db2..9e9a865f3e7 100644
--- a/crates/project_panel/src/file_associations.rs
+++ b/crates/project_panel/src/file_associations.rs
@@ -4,7 +4,7 @@ use collections::HashMap;
use gpui::{AppContext, AssetSource};
use serde_derive::Deserialize;
-use util::{iife, paths::PathExt};
+use util::{maybe, paths::PathExt};
#[derive(Deserialize, Debug)]
struct TypeConfig {
@@ -42,12 +42,12 @@ impl FileAssociations {
}
pub fn get_icon(path: &Path, cx: &AppContext) -> Arc<str> {
- iife!({
+ maybe!({
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
// FIXME: Associate a type with the languages and have the file's langauge
// override these associations
- iife!({
+ maybe!({
let suffix = path.icon_suffix()?;
this.suffixes
@@ -61,7 +61,7 @@ impl FileAssociations {
}
pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
- iife!({
+ maybe!({
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
let key = if expanded {
@@ -78,7 +78,7 @@ impl FileAssociations {
}
pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Arc<str> {
- iife!({
+ maybe!({
let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
let key = if expanded {
diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs
index 8bc0607f9dd..19a2cd90779 100644
--- a/crates/util/src/util.rs
+++ b/crates/util/src/util.rs
@@ -349,19 +349,19 @@ pub fn unzip_option<T, U>(option: Option<(T, U)>) -> (Option<T>, Option<U>) {
}
}
-/// Immediately invoked function expression. Good for using the ? operator
+/// Evaluates to an immediately invoked function expression. Good for using the ? operator
/// in functions which do not return an Option or Result
#[macro_export]
-macro_rules! try {
+macro_rules! maybe {
($block:block) => {
(|| $block)()
};
}
-/// Async Immediately invoked function expression. Good for using the ? operator
-/// in functions which do not return an Option or Result. Async version of above
+/// Evaluates to an immediately invoked function expression. Good for using the ? operator
+/// in functions which do not return an Option or Result, but async.
#[macro_export]
-macro_rules! async_try {
+macro_rules! async_maybe {
($block:block) => {
(|| async move { $block })()
};
@@ -434,7 +434,7 @@ mod tests {
None
}
- let foo = iife!({
+ let foo = maybe!({
option_returning_function()?;
Some(())
});
diff --git a/crates/zed/src/languages/elixir.rs b/crates/zed/src/languages/elixir.rs
index 9d2ebb7f474..5c0ff273ae3 100644
--- a/crates/zed/src/languages/elixir.rs
+++ b/crates/zed/src/languages/elixir.rs
@@ -19,7 +19,7 @@ use std::{
},
};
use util::{
- async_iife,
+ async_maybe,
fs::remove_matching,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt,
@@ -421,7 +421,7 @@ impl LspAdapter for NextLspAdapter {
}
async fn get_cached_server_binary_next(container_dir: PathBuf) -> Option<LanguageServerBinary> {
- async_iife!({
+ async_maybe!({
let mut last_binary_path = None;
let mut entries = fs::read_dir(&container_dir).await?;
while let Some(entry) = entries.next().await {
diff --git a/crates/zed/src/languages/lua.rs b/crates/zed/src/languages/lua.rs
index 8187847c9ac..5fffb37e81b 100644
--- a/crates/zed/src/languages/lua.rs
+++ b/crates/zed/src/languages/lua.rs
@@ -8,7 +8,7 @@ use lsp::LanguageServerBinary;
use smol::fs;
use std::{any::Any, env::consts, path::PathBuf};
use util::{
- async_iife,
+ async_maybe,
github::{latest_github_release, GitHubLspBinaryVersion},
ResultExt,
};
@@ -106,7 +106,7 @@ impl super::LspAdapter for LuaLspAdapter {
}
async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServerBinary> {
- async_iife!({
+ async_maybe!({
let mut last_binary_path = None;
let mut entries = fs::read_dir(&container_dir).await?;
while let Some(entry) = entries.next().await {