diff --git a/crates/extension/src/wasm_host/wit/since_v0_0_1.rs b/crates/extension/src/wasm_host/wit/since_v0_0_1.rs index 3fd76eaaf9..1dab4a6eae 100644 --- a/crates/extension/src/wasm_host/wit/since_v0_0_1.rs +++ b/crates/extension/src/wasm_host/wit/since_v0_0_1.rs @@ -15,6 +15,8 @@ wasmtime::component::bindgen!({ path: "../extension_api/wit/since_v0.0.1", with: { "worktree": ExtensionWorktree, + "zed:extension/github": latest::zed::extension::github, + "zed:extension/platform": latest::zed::extension::platform, }, }); @@ -25,53 +27,6 @@ pub fn linker() -> &'static Linker { LINKER.get_or_init(|| super::new_linker(Extension::add_to_linker)) } -impl From for Os { - fn from(value: latest::Os) -> Self { - match value { - latest::Os::Mac => Os::Mac, - latest::Os::Linux => Os::Linux, - latest::Os::Windows => Os::Windows, - } - } -} - -impl From for Architecture { - fn from(value: latest::Architecture) -> Self { - match value { - latest::Architecture::Aarch64 => Self::Aarch64, - latest::Architecture::X86 => Self::X86, - latest::Architecture::X8664 => Self::X8664, - } - } -} - -impl From for GithubRelease { - fn from(value: latest::GithubRelease) -> Self { - Self { - version: value.version, - assets: value.assets.into_iter().map(|asset| asset.into()).collect(), - } - } -} - -impl From for GithubReleaseAsset { - fn from(value: latest::GithubReleaseAsset) -> Self { - Self { - name: value.name, - download_url: value.download_url, - } - } -} - -impl From for latest::GithubReleaseOptions { - fn from(value: GithubReleaseOptions) -> Self { - Self { - require_assets: value.require_assets, - pre_release: value.pre_release, - } - } -} - impl From for latest::DownloadedFileType { fn from(value: DownloadedFileType) -> Self { match value { @@ -135,21 +90,21 @@ impl HostWorktree for WasmState { #[async_trait] impl ExtensionImports for WasmState { async fn node_binary_path(&mut self) -> wasmtime::Result> { - latest::ExtensionImports::node_binary_path(self).await + latest::nodejs::Host::node_binary_path(self).await } async fn npm_package_latest_version( &mut self, package_name: String, ) -> wasmtime::Result> { - latest::ExtensionImports::npm_package_latest_version(self, package_name).await + latest::nodejs::Host::npm_package_latest_version(self, package_name).await } async fn npm_package_installed_version( &mut self, package_name: String, ) -> wasmtime::Result, String>> { - latest::ExtensionImports::npm_package_installed_version(self, package_name).await + latest::nodejs::Host::npm_package_installed_version(self, package_name).await } async fn npm_install_package( @@ -157,7 +112,7 @@ impl ExtensionImports for WasmState { package_name: String, version: String, ) -> wasmtime::Result> { - latest::ExtensionImports::npm_install_package(self, package_name, version).await + latest::nodejs::Host::npm_install_package(self, package_name, version).await } async fn latest_github_release( @@ -165,17 +120,11 @@ impl ExtensionImports for WasmState { repo: String, options: GithubReleaseOptions, ) -> wasmtime::Result> { - Ok( - latest::ExtensionImports::latest_github_release(self, repo, options.into()) - .await? - .map(|github| github.into()), - ) + latest::zed::extension::github::Host::latest_github_release(self, repo, options).await } async fn current_platform(&mut self) -> Result<(Os, Architecture)> { - latest::ExtensionImports::current_platform(self) - .await - .map(|(os, arch)| (os.into(), arch.into())) + latest::zed::extension::platform::Host::current_platform(self).await } async fn set_language_server_installation_status( diff --git a/crates/extension/src/wasm_host/wit/since_v0_0_4.rs b/crates/extension/src/wasm_host/wit/since_v0_0_4.rs index 6020f34263..86b3a39860 100644 --- a/crates/extension/src/wasm_host/wit/since_v0_0_4.rs +++ b/crates/extension/src/wasm_host/wit/since_v0_0_4.rs @@ -14,6 +14,8 @@ wasmtime::component::bindgen!({ path: "../extension_api/wit/since_v0.0.4", with: { "worktree": ExtensionWorktree, + "zed:extension/github": latest::zed::extension::github, + "zed:extension/platform": latest::zed::extension::platform, }, }); @@ -24,53 +26,6 @@ pub fn linker() -> &'static Linker { LINKER.get_or_init(|| super::new_linker(Extension::add_to_linker)) } -impl From for Os { - fn from(value: latest::Os) -> Self { - match value { - latest::Os::Mac => Os::Mac, - latest::Os::Linux => Os::Linux, - latest::Os::Windows => Os::Windows, - } - } -} - -impl From for Architecture { - fn from(value: latest::Architecture) -> Self { - match value { - latest::Architecture::Aarch64 => Self::Aarch64, - latest::Architecture::X86 => Self::X86, - latest::Architecture::X8664 => Self::X8664, - } - } -} - -impl From for GithubRelease { - fn from(value: latest::GithubRelease) -> Self { - Self { - version: value.version, - assets: value.assets.into_iter().map(|asset| asset.into()).collect(), - } - } -} - -impl From for GithubReleaseAsset { - fn from(value: latest::GithubReleaseAsset) -> Self { - Self { - name: value.name, - download_url: value.download_url, - } - } -} - -impl From for latest::GithubReleaseOptions { - fn from(value: GithubReleaseOptions) -> Self { - Self { - require_assets: value.require_assets, - pre_release: value.pre_release, - } - } -} - impl From for latest::DownloadedFileType { fn from(value: DownloadedFileType) -> Self { match value { @@ -145,21 +100,21 @@ impl HostWorktree for WasmState { #[async_trait] impl ExtensionImports for WasmState { async fn node_binary_path(&mut self) -> wasmtime::Result> { - latest::ExtensionImports::node_binary_path(self).await + latest::nodejs::Host::node_binary_path(self).await } async fn npm_package_latest_version( &mut self, package_name: String, ) -> wasmtime::Result> { - latest::ExtensionImports::npm_package_latest_version(self, package_name).await + latest::nodejs::Host::npm_package_latest_version(self, package_name).await } async fn npm_package_installed_version( &mut self, package_name: String, ) -> wasmtime::Result, String>> { - latest::ExtensionImports::npm_package_installed_version(self, package_name).await + latest::nodejs::Host::npm_package_installed_version(self, package_name).await } async fn npm_install_package( @@ -167,7 +122,7 @@ impl ExtensionImports for WasmState { package_name: String, version: String, ) -> wasmtime::Result> { - latest::ExtensionImports::npm_install_package(self, package_name, version).await + latest::nodejs::Host::npm_install_package(self, package_name, version).await } async fn latest_github_release( @@ -175,17 +130,11 @@ impl ExtensionImports for WasmState { repo: String, options: GithubReleaseOptions, ) -> wasmtime::Result> { - Ok( - latest::ExtensionImports::latest_github_release(self, repo, options.into()) - .await? - .map(|github| github.into()), - ) + latest::zed::extension::github::Host::latest_github_release(self, repo, options).await } async fn current_platform(&mut self) -> Result<(Os, Architecture)> { - latest::ExtensionImports::current_platform(self) - .await - .map(|(os, arch)| (os.into(), arch.into())) + latest::zed::extension::platform::Host::current_platform(self).await } async fn set_language_server_installation_status( diff --git a/crates/extension/src/wasm_host/wit/since_v0_0_6.rs b/crates/extension/src/wasm_host/wit/since_v0_0_6.rs index 27c08e2d44..2c201169a0 100644 --- a/crates/extension/src/wasm_host/wit/since_v0_0_6.rs +++ b/crates/extension/src/wasm_host/wit/since_v0_0_6.rs @@ -1,13 +1,13 @@ -use crate::wasm_host::wit::ToWasmtimeResult; -use crate::wasm_host::WasmState; +use crate::wasm_host::{wit::ToWasmtimeResult, WasmState}; use ::settings::Settings; use anyhow::{anyhow, bail, Result}; use async_compression::futures::bufread::GzipDecoder; use async_tar::Archive; use async_trait::async_trait; use futures::{io::BufReader, FutureExt as _}; -use language::language_settings::AllLanguageSettings; -use language::{LanguageServerBinaryStatus, LspAdapterDelegate}; +use language::{ + language_settings::AllLanguageSettings, LanguageServerBinaryStatus, LspAdapterDelegate, +}; use project::project_settings::ProjectSettings; use semantic_version::SemanticVersion; use std::{ @@ -29,6 +29,8 @@ wasmtime::component::bindgen!({ }, }); +pub use self::zed::extension::*; + mod settings { include!("../../../../extension_api/wit/since_v0.0.6/settings.rs"); } @@ -96,7 +98,106 @@ impl HostWorktree for WasmState { } } -impl self::zed::extension::lsp::Host for WasmState {} +#[async_trait] +impl nodejs::Host for WasmState { + async fn node_binary_path(&mut self) -> wasmtime::Result> { + self.host + .node_runtime + .binary_path() + .await + .map(|path| path.to_string_lossy().to_string()) + .to_wasmtime_result() + } + + async fn npm_package_latest_version( + &mut self, + package_name: String, + ) -> wasmtime::Result> { + self.host + .node_runtime + .npm_package_latest_version(&package_name) + .await + .to_wasmtime_result() + } + + async fn npm_package_installed_version( + &mut self, + package_name: String, + ) -> wasmtime::Result, String>> { + self.host + .node_runtime + .npm_package_installed_version(&self.work_dir(), &package_name) + .await + .to_wasmtime_result() + } + + async fn npm_install_package( + &mut self, + package_name: String, + version: String, + ) -> wasmtime::Result> { + self.host + .node_runtime + .npm_install_packages(&self.work_dir(), &[(&package_name, &version)]) + .await + .to_wasmtime_result() + } +} + +#[async_trait] +impl lsp::Host for WasmState {} + +#[async_trait] +impl github::Host for WasmState { + async fn latest_github_release( + &mut self, + repo: String, + options: github::GithubReleaseOptions, + ) -> wasmtime::Result> { + maybe!(async { + let release = util::github::latest_github_release( + &repo, + options.require_assets, + options.pre_release, + self.host.http_client.clone(), + ) + .await?; + Ok(github::GithubRelease { + version: release.tag_name, + assets: release + .assets + .into_iter() + .map(|asset| github::GithubReleaseAsset { + name: asset.name, + download_url: asset.browser_download_url, + }) + .collect(), + }) + }) + .await + .to_wasmtime_result() + } +} + +#[async_trait] +impl platform::Host for WasmState { + async fn current_platform(&mut self) -> Result<(platform::Os, platform::Architecture)> { + Ok(( + match env::consts::OS { + "macos" => platform::Os::Mac, + "linux" => platform::Os::Linux, + "windows" => platform::Os::Windows, + _ => panic!("unsupported os"), + }, + match env::consts::ARCH { + "aarch64" => platform::Architecture::Aarch64, + "x86" => platform::Architecture::X86, + "x86_64" => platform::Architecture::X8664, + _ => panic!("unsupported architecture"), + }, + )) + } +} #[async_trait] impl ExtensionImports for WasmState { @@ -152,95 +253,6 @@ impl ExtensionImports for WasmState { .to_wasmtime_result() } - async fn node_binary_path(&mut self) -> wasmtime::Result> { - self.host - .node_runtime - .binary_path() - .await - .map(|path| path.to_string_lossy().to_string()) - .to_wasmtime_result() - } - - async fn npm_package_latest_version( - &mut self, - package_name: String, - ) -> wasmtime::Result> { - self.host - .node_runtime - .npm_package_latest_version(&package_name) - .await - .to_wasmtime_result() - } - - async fn npm_package_installed_version( - &mut self, - package_name: String, - ) -> wasmtime::Result, String>> { - self.host - .node_runtime - .npm_package_installed_version(&self.work_dir(), &package_name) - .await - .to_wasmtime_result() - } - - async fn npm_install_package( - &mut self, - package_name: String, - version: String, - ) -> wasmtime::Result> { - self.host - .node_runtime - .npm_install_packages(&self.work_dir(), &[(&package_name, &version)]) - .await - .to_wasmtime_result() - } - - async fn latest_github_release( - &mut self, - repo: String, - options: GithubReleaseOptions, - ) -> wasmtime::Result> { - maybe!(async { - let release = util::github::latest_github_release( - &repo, - options.require_assets, - options.pre_release, - self.host.http_client.clone(), - ) - .await?; - Ok(GithubRelease { - version: release.tag_name, - assets: release - .assets - .into_iter() - .map(|asset| GithubReleaseAsset { - name: asset.name, - download_url: asset.browser_download_url, - }) - .collect(), - }) - }) - .await - .to_wasmtime_result() - } - - async fn current_platform(&mut self) -> Result<(Os, Architecture)> { - Ok(( - match env::consts::OS { - "macos" => Os::Mac, - "linux" => Os::Linux, - "windows" => Os::Windows, - _ => panic!("unsupported os"), - }, - match env::consts::ARCH { - "aarch64" => Architecture::Aarch64, - "x86" => Architecture::X86, - "x86_64" => Architecture::X8664, - _ => panic!("unsupported architecture"), - }, - )) - } - async fn set_language_server_installation_status( &mut self, server_name: String, diff --git a/crates/extension_api/src/extension_api.rs b/crates/extension_api/src/extension_api.rs index a58c64e138..385537f0fd 100644 --- a/crates/extension_api/src/extension_api.rs +++ b/crates/extension_api/src/extension_api.rs @@ -13,11 +13,17 @@ pub use serde_json; // We explicitly enumerate the symbols we want to re-export, as there are some // that we may want to shadow to provide a cleaner Rust API. pub use wit::{ - current_platform, download_file, latest_github_release, make_file_executable, node_binary_path, - npm_install_package, npm_package_installed_version, npm_package_latest_version, Architecture, + download_file, make_file_executable, + zed::extension::github::{ + latest_github_release, GithubRelease, GithubReleaseAsset, GithubReleaseOptions, + }, + zed::extension::nodejs::{ + node_binary_path, npm_install_package, npm_package_installed_version, + npm_package_latest_version, + }, + zed::extension::platform::{current_platform, Architecture, Os}, CodeLabel, CodeLabelSpan, CodeLabelSpanLiteral, Command, DownloadedFileType, EnvVars, - GithubRelease, GithubReleaseAsset, GithubReleaseOptions, LanguageServerInstallationStatus, Os, - Range, Worktree, + LanguageServerInstallationStatus, Range, Worktree, }; // Undocumented WIT re-exports. diff --git a/crates/extension_api/src/settings.rs b/crates/extension_api/src/settings.rs index f7829263b5..6c56206f96 100644 --- a/crates/extension_api/src/settings.rs +++ b/crates/extension_api/src/settings.rs @@ -1,5 +1,5 @@ #[path = "../wit/since_v0.0.6/settings.rs"] -pub mod types; +mod types; use crate::{wit, Result, SettingsLocation, Worktree}; use serde_json; diff --git a/crates/extension_api/wit/since_v0.0.1/extension.wit b/crates/extension_api/wit/since_v0.0.1/extension.wit index fb268fe271..339a974169 100644 --- a/crates/extension_api/wit/since_v0.0.1/extension.wit +++ b/crates/extension_api/wit/since_v0.0.1/extension.wit @@ -1,35 +1,11 @@ package zed:extension; world extension { + use github.{github-release, github-release-options}; + use platform.{os, architecture}; + export init-extension: func(); - record github-release { - version: string, - assets: list, - } - - record github-release-asset { - name: string, - download-url: string, - } - - record github-release-options { - require-assets: bool, - pre-release: bool, - } - - enum os { - mac, - linux, - windows, - } - - enum architecture { - aarch64, - x86, - x8664, - } - enum downloaded-file-type { gzip, gzip-tar, diff --git a/crates/extension_api/wit/since_v0.0.1/github.wit b/crates/extension_api/wit/since_v0.0.1/github.wit new file mode 100644 index 0000000000..53ecacb720 --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.1/github.wit @@ -0,0 +1,28 @@ +interface github { + /// A GitHub release. + record github-release { + /// The version of the release. + version: string, + /// The list of assets attached to the release. + assets: list, + } + + /// An asset from a GitHub release. + record github-release-asset { + /// The name of the asset. + name: string, + /// The download URL for the asset. + download-url: string, + } + + /// The options used to filter down GitHub releases. + record github-release-options { + /// Whether releases without assets should be included. + require-assets: bool, + /// Whether pre-releases should be included. + pre-release: bool, + } + + /// Returns the latest release for the given GitHub repository. + latest-github-release: func(repo: string, options: github-release-options) -> result; +} diff --git a/crates/extension_api/wit/since_v0.0.1/platform.wit b/crates/extension_api/wit/since_v0.0.1/platform.wit new file mode 100644 index 0000000000..48472a99bc --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.1/platform.wit @@ -0,0 +1,24 @@ +interface platform { + /// An operating system. + enum os { + /// macOS. + mac, + /// Linux. + linux, + /// Windows. + windows, + } + + /// A platform architecture. + enum architecture { + /// AArch64 (e.g., Apple Silicon). + aarch64, + /// x86. + x86, + /// x86-64. + x8664, + } + + /// Gets the current operating system and architecture. + current-platform: func() -> tuple; +} diff --git a/crates/extension_api/wit/since_v0.0.4/extension.wit b/crates/extension_api/wit/since_v0.0.4/extension.wit index 735c921ee0..c6f3e73506 100644 --- a/crates/extension_api/wit/since_v0.0.4/extension.wit +++ b/crates/extension_api/wit/since_v0.0.4/extension.wit @@ -1,35 +1,11 @@ package zed:extension; world extension { + use github.{github-release, github-release-options}; + use platform.{os, architecture}; + export init-extension: func(); - record github-release { - version: string, - assets: list, - } - - record github-release-asset { - name: string, - download-url: string, - } - - record github-release-options { - require-assets: bool, - pre-release: bool, - } - - enum os { - mac, - linux, - windows, - } - - enum architecture { - aarch64, - x86, - x8664, - } - enum downloaded-file-type { gzip, gzip-tar, diff --git a/crates/extension_api/wit/since_v0.0.4/github.wit b/crates/extension_api/wit/since_v0.0.4/github.wit new file mode 100644 index 0000000000..53ecacb720 --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.4/github.wit @@ -0,0 +1,28 @@ +interface github { + /// A GitHub release. + record github-release { + /// The version of the release. + version: string, + /// The list of assets attached to the release. + assets: list, + } + + /// An asset from a GitHub release. + record github-release-asset { + /// The name of the asset. + name: string, + /// The download URL for the asset. + download-url: string, + } + + /// The options used to filter down GitHub releases. + record github-release-options { + /// Whether releases without assets should be included. + require-assets: bool, + /// Whether pre-releases should be included. + pre-release: bool, + } + + /// Returns the latest release for the given GitHub repository. + latest-github-release: func(repo: string, options: github-release-options) -> result; +} diff --git a/crates/extension_api/wit/since_v0.0.4/platform.wit b/crates/extension_api/wit/since_v0.0.4/platform.wit new file mode 100644 index 0000000000..48472a99bc --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.4/platform.wit @@ -0,0 +1,24 @@ +interface platform { + /// An operating system. + enum os { + /// macOS. + mac, + /// Linux. + linux, + /// Windows. + windows, + } + + /// A platform architecture. + enum architecture { + /// AArch64 (e.g., Apple Silicon). + aarch64, + /// x86. + x86, + /// x86-64. + x8664, + } + + /// Gets the current operating system and architecture. + current-platform: func() -> tuple; +} diff --git a/crates/extension_api/wit/since_v0.0.6/extension.wit b/crates/extension_api/wit/since_v0.0.6/extension.wit index bbae5b9477..68b5efe8f3 100644 --- a/crates/extension_api/wit/since_v0.0.6/extension.wit +++ b/crates/extension_api/wit/since_v0.0.6/extension.wit @@ -1,57 +1,15 @@ package zed:extension; world extension { - import lsp; + import github; + import platform; + import nodejs; use lsp.{completion, symbol}; /// Initializes the extension. export init-extension: func(); - /// A GitHub release. - record github-release { - /// The version of the release. - version: string, - /// The list of assets attached to the release. - assets: list, - } - - /// An asset from a GitHub release. - record github-release-asset { - /// The name of the asset. - name: string, - /// The download URL for the asset. - download-url: string, - } - - /// The options used to filter down GitHub releases. - record github-release-options { - /// Whether releases without assets should be included. - require-assets: bool, - /// Whether pre-releases should be included. - pre-release: bool, - } - - /// An operating system. - enum os { - /// macOS. - mac, - /// Linux. - linux, - /// Windows. - windows, - } - - /// A platform architecture. - enum architecture { - /// AArch64 (e.g., Apple Silicon). - aarch64, - /// x86. - x86, - /// x86-64. - x8664, - } - /// The type of a downloaded file. enum downloaded-file-type { /// A gzipped file (`.gz`). @@ -76,9 +34,6 @@ world extension { failed(string), } - /// Returns operating system and architecture for the current platform. - import current-platform: func() -> tuple; - record settings-location { worktree-id: u64, path: string, @@ -86,21 +41,6 @@ world extension { import get-settings: func(path: option, category: string, key: option) -> result; - /// Returns the path to the Node binary used by Zed. - import node-binary-path: func() -> result; - - /// Returns the latest version of the given NPM package. - import npm-package-latest-version: func(package-name: string) -> result; - - /// Returns the installed version of the given NPM package, if it exists. - import npm-package-installed-version: func(package-name: string) -> result, string>; - - /// Installs the specified NPM package. - import npm-install-package: func(package-name: string, version: string) -> result<_, string>; - - /// Returns the latest release for the given GitHub repository. - import latest-github-release: func(repo: string, options: github-release-options) -> result; - /// Downloads a file from the given URL and saves it to the given path within the extension's /// working directory. /// diff --git a/crates/extension_api/wit/since_v0.0.6/github.wit b/crates/extension_api/wit/since_v0.0.6/github.wit new file mode 100644 index 0000000000..53ecacb720 --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.6/github.wit @@ -0,0 +1,28 @@ +interface github { + /// A GitHub release. + record github-release { + /// The version of the release. + version: string, + /// The list of assets attached to the release. + assets: list, + } + + /// An asset from a GitHub release. + record github-release-asset { + /// The name of the asset. + name: string, + /// The download URL for the asset. + download-url: string, + } + + /// The options used to filter down GitHub releases. + record github-release-options { + /// Whether releases without assets should be included. + require-assets: bool, + /// Whether pre-releases should be included. + pre-release: bool, + } + + /// Returns the latest release for the given GitHub repository. + latest-github-release: func(repo: string, options: github-release-options) -> result; +} diff --git a/crates/extension_api/wit/since_v0.0.6/nodejs.wit b/crates/extension_api/wit/since_v0.0.6/nodejs.wit new file mode 100644 index 0000000000..c814548314 --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.6/nodejs.wit @@ -0,0 +1,13 @@ +interface nodejs { + /// Returns the path to the Node binary used by Zed. + node-binary-path: func() -> result; + + /// Returns the latest version of the given NPM package. + npm-package-latest-version: func(package-name: string) -> result; + + /// Returns the installed version of the given NPM package, if it exists. + npm-package-installed-version: func(package-name: string) -> result, string>; + + /// Installs the specified NPM package. + npm-install-package: func(package-name: string, version: string) -> result<_, string>; +} diff --git a/crates/extension_api/wit/since_v0.0.6/platform.wit b/crates/extension_api/wit/since_v0.0.6/platform.wit new file mode 100644 index 0000000000..48472a99bc --- /dev/null +++ b/crates/extension_api/wit/since_v0.0.6/platform.wit @@ -0,0 +1,24 @@ +interface platform { + /// An operating system. + enum os { + /// macOS. + mac, + /// Linux. + linux, + /// Windows. + windows, + } + + /// A platform architecture. + enum architecture { + /// AArch64 (e.g., Apple Silicon). + aarch64, + /// x86. + x86, + /// x86-64. + x8664, + } + + /// Gets the current operating system and architecture. + current-platform: func() -> tuple; +}