From 4bdfc12b79e2c760abcb72a2dccbd9295afa7f1f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 8 Apr 2024 07:16:12 -0700 Subject: [PATCH] Remove duplicated code for unchanged parts of different extension API versions (#10218) Release Notes: - N/A --------- Co-authored-by: Marshall Co-authored-by: Marshall Bowers --- .../src/wasm_host/wit/since_v0_0_1.rs | 67 +------- .../src/wasm_host/wit/since_v0_0_4.rs | 67 +------- .../src/wasm_host/wit/since_v0_0_6.rs | 152 ++++++++++-------- crates/extension_api/src/extension_api.rs | 14 +- crates/extension_api/src/settings.rs | 2 +- .../wit/since_v0.0.1/extension.wit | 30 +--- .../extension_api/wit/since_v0.0.1/github.wit | 28 ++++ .../wit/since_v0.0.1/platform.wit | 24 +++ .../wit/since_v0.0.4/extension.wit | 30 +--- .../extension_api/wit/since_v0.0.4/github.wit | 28 ++++ .../wit/since_v0.0.4/platform.wit | 24 +++ .../wit/since_v0.0.6/extension.wit | 66 +------- .../extension_api/wit/since_v0.0.6/github.wit | 28 ++++ .../extension_api/wit/since_v0.0.6/nodejs.wit | 13 ++ .../wit/since_v0.0.6/platform.wit | 24 +++ 15 files changed, 287 insertions(+), 310 deletions(-) create mode 100644 crates/extension_api/wit/since_v0.0.1/github.wit create mode 100644 crates/extension_api/wit/since_v0.0.1/platform.wit create mode 100644 crates/extension_api/wit/since_v0.0.4/github.wit create mode 100644 crates/extension_api/wit/since_v0.0.4/platform.wit create mode 100644 crates/extension_api/wit/since_v0.0.6/github.wit create mode 100644 crates/extension_api/wit/since_v0.0.6/nodejs.wit create mode 100644 crates/extension_api/wit/since_v0.0.6/platform.wit 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 3fd76eaaf98df4a5ff403f36eec9827630e80578..1dab4a6eaeab45dedb66f3911f9e8e04ee6159de 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 6020f34263d0683fef60d1772b6719cef4b1b866..86b3a3986066a71e3fee0d99bc836514afb3ac1b 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 27c08e2d4478f77c8e4499da422ece0c233e406e..2c201169a0e98c6b96b25bc02297db16a894576b 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,62 +98,8 @@ impl HostWorktree for WasmState { } } -impl self::zed::extension::lsp::Host for WasmState {} - #[async_trait] -impl ExtensionImports for WasmState { - async fn get_settings( - &mut self, - location: Option, - category: String, - key: Option, - ) -> wasmtime::Result> { - self.on_main_thread(|cx| { - async move { - let location = location - .as_ref() - .map(|location| ::settings::SettingsLocation { - worktree_id: location.worktree_id as usize, - path: Path::new(&location.path), - }); - - cx.update(|cx| match category.as_str() { - "language" => { - let settings = - AllLanguageSettings::get(location, cx).language(key.as_deref()); - Ok(serde_json::to_string(&settings::LanguageSettings { - tab_size: settings.tab_size, - })?) - } - "lsp" => { - let settings = key - .and_then(|key| { - ProjectSettings::get_global(cx) - .lsp - .get(&Arc::::from(key)) - }) - .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() - }) - .await? - .to_wasmtime_result() - } - +impl nodejs::Host for WasmState { async fn node_binary_path(&mut self) -> wasmtime::Result> { self.host .node_runtime @@ -194,12 +142,18 @@ impl ExtensionImports for WasmState { .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: GithubReleaseOptions, - ) -> wasmtime::Result> { + options: github::GithubReleaseOptions, + ) -> wasmtime::Result> { maybe!(async { let release = util::github::latest_github_release( &repo, @@ -208,12 +162,12 @@ impl ExtensionImports for WasmState { self.host.http_client.clone(), ) .await?; - Ok(GithubRelease { + Ok(github::GithubRelease { version: release.tag_name, assets: release .assets .into_iter() - .map(|asset| GithubReleaseAsset { + .map(|asset| github::GithubReleaseAsset { name: asset.name, download_url: asset.browser_download_url, }) @@ -223,23 +177,81 @@ impl ExtensionImports for WasmState { .await .to_wasmtime_result() } +} - async fn current_platform(&mut self) -> Result<(Os, Architecture)> { +#[async_trait] +impl platform::Host for WasmState { + async fn current_platform(&mut self) -> Result<(platform::Os, platform::Architecture)> { Ok(( match env::consts::OS { - "macos" => Os::Mac, - "linux" => Os::Linux, - "windows" => Os::Windows, + "macos" => platform::Os::Mac, + "linux" => platform::Os::Linux, + "windows" => platform::Os::Windows, _ => panic!("unsupported os"), }, match env::consts::ARCH { - "aarch64" => Architecture::Aarch64, - "x86" => Architecture::X86, - "x86_64" => Architecture::X8664, + "aarch64" => platform::Architecture::Aarch64, + "x86" => platform::Architecture::X86, + "x86_64" => platform::Architecture::X8664, _ => panic!("unsupported architecture"), }, )) } +} + +#[async_trait] +impl ExtensionImports for WasmState { + async fn get_settings( + &mut self, + location: Option, + category: String, + key: Option, + ) -> wasmtime::Result> { + self.on_main_thread(|cx| { + async move { + let location = location + .as_ref() + .map(|location| ::settings::SettingsLocation { + worktree_id: location.worktree_id as usize, + path: Path::new(&location.path), + }); + + cx.update(|cx| match category.as_str() { + "language" => { + let settings = + AllLanguageSettings::get(location, cx).language(key.as_deref()); + Ok(serde_json::to_string(&settings::LanguageSettings { + tab_size: settings.tab_size, + })?) + } + "lsp" => { + let settings = key + .and_then(|key| { + ProjectSettings::get_global(cx) + .lsp + .get(&Arc::::from(key)) + }) + .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() + }) + .await? + .to_wasmtime_result() + } async fn set_language_server_installation_status( &mut self, diff --git a/crates/extension_api/src/extension_api.rs b/crates/extension_api/src/extension_api.rs index a58c64e138d51790da516aa3fc2e72e71b655ed5..385537f0fdb9f5c789c56086433867c7113f2517 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 f7829263b5b7f8b9d6577e4a62de431101464749..6c56206f96d6a2d05bccdda58bff8a748fdc44b5 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 fb268fe27179dae5dafee264f76084f4e34d1645..339a974169b05e149074a314ab3bf56ba880f142 100644 --- a/crates/extension_api/wit/since_v0.0.1/extension.wit +++ b/crates/extension_api/wit/since_v0.0.1/extension.wit @@ -1,34 +1,10 @@ package zed:extension; world extension { - export init-extension: func(); - - record github-release { - version: string, - assets: list, - } - - record github-release-asset { - name: string, - download-url: string, - } + use github.{github-release, github-release-options}; + use platform.{os, architecture}; - record github-release-options { - require-assets: bool, - pre-release: bool, - } - - enum os { - mac, - linux, - windows, - } - - enum architecture { - aarch64, - x86, - x8664, - } + export init-extension: func(); enum downloaded-file-type { gzip, 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 0000000000000000000000000000000000000000..53ecacb7208b5fbf603d0adc147ee4ce77b9d164 --- /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 0000000000000000000000000000000000000000..48472a99bc175fdc24231a690db021433d5a2505 --- /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 735c921ee00f89ea655f21dc0fc019edb8fc4c40..c6f3e73506e1195be945cfb2486d9221650f4f2c 100644 --- a/crates/extension_api/wit/since_v0.0.4/extension.wit +++ b/crates/extension_api/wit/since_v0.0.4/extension.wit @@ -1,34 +1,10 @@ package zed:extension; world extension { - export init-extension: func(); - - record github-release { - version: string, - assets: list, - } - - record github-release-asset { - name: string, - download-url: string, - } + use github.{github-release, github-release-options}; + use platform.{os, architecture}; - record github-release-options { - require-assets: bool, - pre-release: bool, - } - - enum os { - mac, - linux, - windows, - } - - enum architecture { - aarch64, - x86, - x8664, - } + export init-extension: func(); enum downloaded-file-type { gzip, 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 0000000000000000000000000000000000000000..53ecacb7208b5fbf603d0adc147ee4ce77b9d164 --- /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 0000000000000000000000000000000000000000..48472a99bc175fdc24231a690db021433d5a2505 --- /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 bbae5b9477fd0bd83c4c2db4eafca597887386f2..68b5efe8f326448dd2b759a9fb52c353edf06562 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 0000000000000000000000000000000000000000..53ecacb7208b5fbf603d0adc147ee4ce77b9d164 --- /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 0000000000000000000000000000000000000000..c814548314162c862e81a98b3fba6950dc2a7f41 --- /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 0000000000000000000000000000000000000000..48472a99bc175fdc24231a690db021433d5a2505 --- /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; +}