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.

extension: Simplify on_main_thread to not box the returned future (#66569)

Piotr Osiewicz654efae441bc
diff --git a/crates/extension_host/src/wasm_host.rs b/crates/extension_host/src/wasm_host.rs
index 857d33e0de7..cbd5d27c90f 100644
--- a/crates/extension_host/src/wasm_host.rs
+++ b/crates/extension_host/src/wasm_host.rs
@@ -942,10 +942,10 @@ impl WasmExtension {
}
impl WasmState {
- fn on_main_thread<T, Fn>(&self, f: Fn) -> impl 'static + Future<Output = T>
+ fn on_main_thread<T, AsyncFn>(&self, f: AsyncFn) -> impl 'static + Future<Output = T>
where
T: 'static + Send,
- Fn: 'static + Send + for<'a> FnOnce(&'a mut AsyncApp) -> LocalBoxFuture<'a, T>,
+ AsyncFn: 'static + Send + AsyncFnOnce(&mut AsyncApp) -> T,
{
let (return_tx, return_rx) = oneshot::channel();
self.host
diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs
index d7df044773e..3e90644a7b6 100644
--- a/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs
+++ b/crates/extension_host/src/wasm_host/wit/since_v0_1_0.rs
@@ -8,8 +8,7 @@ use anyhow::{Context as _, Result, bail};
use async_compression::futures::bufread::GzipDecoder;
use async_tar::Archive;
use extension::{ExtensionLanguageServerProxy, KeyValueStoreDelegate, WorktreeDelegate};
-use futures::{AsyncReadExt, lock::Mutex};
-use futures::{FutureExt as _, io::BufReader};
+use futures::{AsyncReadExt, io::BufReader, lock::Mutex};
use gpui::BackgroundExecutor;
use language::LanguageName;
use language::{BinaryStatus, language_settings::AllLanguageSettings};
@@ -441,55 +440,49 @@ impl ExtensionImports for WasmState {
category: String,
key: Option<String>,
) -> wasmtime::Result<Result<String, String>> {
- self.on_main_thread(|cx| {
- async move {
- let path = location.as_ref().and_then(|location| {
- RelPath::new(Path::new(&location.path), PathStyle::Unix).ok()
+ self.on_main_thread(async move |cx| {
+ let path = location
+ .as_ref()
+ .and_then(|location| RelPath::new(Path::new(&location.path), PathStyle::Unix).ok());
+ let location = path
+ .as_ref()
+ .zip(location.as_ref())
+ .map(|(path, location)| ::settings::SettingsLocation {
+ worktree_id: WorktreeId::from_proto(location.worktree_id),
+ path,
});
- let location = path
- .as_ref()
- .zip(location.as_ref())
- .map(|(path, location)| ::settings::SettingsLocation {
- worktree_id: WorktreeId::from_proto(location.worktree_id),
- path,
- });
-
- cx.update(|cx| match category.as_str() {
- "language" => {
- let key = key.map(|k| LanguageName::new(&k));
- let settings = AllLanguageSettings::get(location, cx).language(
- location,
- key.as_ref(),
- cx,
- );
- Ok(serde_json::to_string(&settings::LanguageSettings {
- tab_size: settings.tab_size,
- })?)
- }
- "lsp" => {
- let settings = key
- .and_then(|key| {
- ProjectSettings::get(location, cx)
- .lsp
- .get(&::lsp::LanguageServerName(key.into()))
- })
- .cloned()
- .unwrap_or_default();
- Ok(serde_json::to_string(&settings::LspSettings {
- binary: settings.binary.map(|binary| settings::BinarySettings {
- path: binary.path,
- arguments: binary.arguments,
- }),
- settings: settings.settings,
- initialization_options: settings.initialization_options,
- })?)
- }
- _ => {
- bail!("Unknown settings category: {}", category);
- }
- })
- }
- .boxed_local()
+
+ cx.update(|cx| match category.as_str() {
+ "language" => {
+ let key = key.map(|k| LanguageName::new(&k));
+ let settings =
+ AllLanguageSettings::get(location, cx).language(location, key.as_ref(), cx);
+ Ok(serde_json::to_string(&settings::LanguageSettings {
+ tab_size: settings.tab_size,
+ })?)
+ }
+ "lsp" => {
+ let settings = key
+ .and_then(|key| {
+ ProjectSettings::get(location, cx)
+ .lsp
+ .get(&::lsp::LanguageServerName(key.into()))
+ })
+ .cloned()
+ .unwrap_or_default();
+ Ok(serde_json::to_string(&settings::LspSettings {
+ binary: settings.binary.map(|binary| settings::BinarySettings {
+ path: binary.path,
+ arguments: binary.arguments,
+ }),
+ settings: settings.settings,
+ initialization_options: settings.initialization_options,
+ })?)
+ }
+ _ => {
+ bail!("Unknown settings category: {}", category);
+ }
+ })
})
.await
.to_wasmtime_result()
diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs
index e406544d24e..0c17b309f12 100644
--- a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs
+++ b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs
@@ -13,8 +13,7 @@ use async_trait::async_trait;
use extension::{
ExtensionLanguageServerProxy, KeyValueStoreDelegate, ProjectDelegate, WorktreeDelegate,
};
-use futures::{AsyncReadExt, lock::Mutex};
-use futures::{FutureExt as _, io::BufReader};
+use futures::{AsyncReadExt, io::BufReader, lock::Mutex};
use gpui::{BackgroundExecutor, SharedString};
use language::{BinaryStatus, LanguageName, language_settings::AllLanguageSettings};
use project::project_settings::ProjectSettings;
@@ -956,97 +955,90 @@ impl ExtensionImports for WasmState {
category: String,
key: Option<String>,
) -> wasmtime::Result<Result<String, String>> {
- self.on_main_thread(|cx| {
- async move {
- let path = location.as_ref().and_then(|location| {
- RelPath::new(Path::new(&location.path), PathStyle::Unix).ok()
+ self.on_main_thread(async move |cx| {
+ let path = location
+ .as_ref()
+ .and_then(|location| RelPath::new(Path::new(&location.path), PathStyle::Unix).ok());
+ let location = path
+ .as_ref()
+ .zip(location.as_ref())
+ .map(|(path, location)| ::settings::SettingsLocation {
+ worktree_id: WorktreeId::from_proto(location.worktree_id),
+ path,
});
- let location = path
- .as_ref()
- .zip(location.as_ref())
- .map(|(path, location)| ::settings::SettingsLocation {
- worktree_id: WorktreeId::from_proto(location.worktree_id),
- path,
- });
-
- cx.update(|cx| match category.as_str() {
- "language" => {
- let key = key.map(|k| LanguageName::new(&k));
- let settings = AllLanguageSettings::get(location, cx).language(
- location,
- key.as_ref(),
- cx,
- );
- Ok(serde_json::to_string(&settings::LanguageSettings {
- tab_size: settings.tab_size,
- hard_tabs: settings.hard_tabs,
- preferred_line_length: settings.preferred_line_length,
- })?)
- }
- "lsp" => {
- let settings = key
- .and_then(|key| {
- ProjectSettings::get(location, cx)
- .lsp
- .get(&::lsp::LanguageServerName::from_proto(key))
- })
- .cloned()
- .unwrap_or_default();
- Ok(serde_json::to_string(&settings::LspSettings {
- binary: settings.binary.map(|binary| settings::CommandSettings {
- path: binary.path,
- arguments: binary.arguments,
- env: binary.env.map(|env| env.into_iter().collect()),
+
+ cx.update(|cx| match category.as_str() {
+ "language" => {
+ let key = key.map(|k| LanguageName::new(&k));
+ let settings =
+ AllLanguageSettings::get(location, cx).language(location, key.as_ref(), cx);
+ Ok(serde_json::to_string(&settings::LanguageSettings {
+ tab_size: settings.tab_size,
+ hard_tabs: settings.hard_tabs,
+ preferred_line_length: settings.preferred_line_length,
+ })?)
+ }
+ "lsp" => {
+ let settings = key
+ .and_then(|key| {
+ ProjectSettings::get(location, cx)
+ .lsp
+ .get(&::lsp::LanguageServerName::from_proto(key))
+ })
+ .cloned()
+ .unwrap_or_default();
+ Ok(serde_json::to_string(&settings::LspSettings {
+ binary: settings.binary.map(|binary| settings::CommandSettings {
+ path: binary.path,
+ arguments: binary.arguments,
+ env: binary.env.map(|env| env.into_iter().collect()),
+ }),
+ settings: settings.settings,
+ initialization_options: settings.initialization_options,
+ })?)
+ }
+ "context_servers" => {
+ let settings = key
+ .and_then(|key| {
+ ProjectSettings::get(location, cx)
+ .context_servers
+ .get(key.as_str())
+ })
+ .cloned()
+ .unwrap_or_else(|| {
+ project::project_settings::ContextServerSettings::default_extension()
+ });
+
+ match settings {
+ project::project_settings::ContextServerSettings::Stdio {
+ enabled: _,
+ command,
+ ..
+ } => Ok(serde_json::to_string(&settings::ContextServerSettings {
+ command: Some(settings::CommandSettings {
+ path: command.path.to_str().map(|path| path.to_string()),
+ arguments: Some(command.args),
+ env: command.env.map(|env| env.into_iter().collect()),
}),
- settings: settings.settings,
- initialization_options: settings.initialization_options,
- })?)
- }
- "context_servers" => {
- let settings = key
- .and_then(|key| {
- ProjectSettings::get(location, cx)
- .context_servers
- .get(key.as_str())
- })
- .cloned()
- .unwrap_or_else(|| {
- project::project_settings::ContextServerSettings::default_extension(
- )
- });
-
- match settings {
- project::project_settings::ContextServerSettings::Stdio {
- enabled: _,
- command,
- ..
- } => Ok(serde_json::to_string(&settings::ContextServerSettings {
- command: Some(settings::CommandSettings {
- path: command.path.to_str().map(|path| path.to_string()),
- arguments: Some(command.args),
- env: command.env.map(|env| env.into_iter().collect()),
- }),
- settings: None,
- })?),
- project::project_settings::ContextServerSettings::Extension {
- enabled: _,
- settings,
- ..
- } => Ok(serde_json::to_string(&settings::ContextServerSettings {
- command: None,
- settings: Some(settings),
- })?),
- project::project_settings::ContextServerSettings::Http { .. } => {
- bail!("remote context server settings not supported in 0.6.0")
- }
+ settings: None,
+ })?),
+ project::project_settings::ContextServerSettings::Extension {
+ enabled: _,
+ settings,
+ ..
+ } => Ok(serde_json::to_string(&settings::ContextServerSettings {
+ command: None,
+ settings: Some(settings),
+ })?),
+ project::project_settings::ContextServerSettings::Http { .. } => {
+ bail!("remote context server settings not supported in 0.6.0")
}
}
- _ => {
- bail!("Unknown settings category: {}", category);
- }
- })
- }
- .boxed_local()
+ }
+ _ => {
+ bail!("Unknown settings category: {}", category);
+ }
+ })
})
.await
.to_wasmtime_result()