Restrict v0.0.7 of the zed_extension_api to dev builds, for now (#12170)

This PR restricts usage of v0.0.7 of the `zed_extension_api` to dev
builds, for now.

As we're still making changes to it, we don't want to ship a version of
Zed to Preview/Stable that claims to support a yet-unreleased version of
the extension API.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-05-22 19:45:34 -04:00 committed by GitHub
parent 80bd40cfa3
commit 85ff80f3c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 48 additions and 15 deletions

View file

@ -30,6 +30,7 @@ log.workspace = true
lsp.workspace = true
node_runtime.workspace = true
project.workspace = true
release_channel.workspace = true
schemars.workspace = true
semantic_version.workspace = true
serde.workspace = true

View file

@ -34,6 +34,7 @@ use language::{
};
use node_runtime::NodeRuntime;
use project::ContextProviderWithTasks;
use release_channel::ReleaseChannel;
use semantic_version::SemanticVersion;
use serde::{Deserialize, Serialize};
use settings::Settings;
@ -70,7 +71,10 @@ pub fn schema_version_range() -> RangeInclusive<SchemaVersion> {
}
/// Returns whether the given extension version is compatible with this version of Zed.
pub fn is_version_compatible(extension_version: &ExtensionMetadata) -> bool {
pub fn is_version_compatible(
release_channel: ReleaseChannel,
extension_version: &ExtensionMetadata,
) -> bool {
let schema_version = extension_version.manifest.schema_version.unwrap_or(0);
if CURRENT_SCHEMA_VERSION.0 < schema_version {
return false;
@ -82,7 +86,7 @@ pub fn is_version_compatible(extension_version: &ExtensionMetadata) -> bool {
.as_ref()
.and_then(|wasm_api_version| SemanticVersion::from_str(wasm_api_version).ok())
{
if !is_supported_wasm_api_version(wasm_api_version) {
if !is_supported_wasm_api_version(release_channel, wasm_api_version) {
return false;
}
}
@ -428,7 +432,7 @@ impl ExtensionStore {
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<ExtensionMetadata>>> {
let schema_versions = schema_version_range();
let wasm_api_versions = wasm_api_version_range();
let wasm_api_versions = wasm_api_version_range(ReleaseChannel::global(cx));
let extension_settings = ExtensionSettings::get_global(cx);
let extension_ids = self
.extension_index
@ -681,7 +685,7 @@ impl ExtensionStore {
log::info!("installing extension {extension_id} latest version");
let schema_versions = schema_version_range();
let wasm_api_versions = wasm_api_version_range();
let wasm_api_versions = wasm_api_version_range(ReleaseChannel::global(cx));
let Some(url) = self
.http_client

View file

@ -714,6 +714,7 @@ fn init_test(cx: &mut TestAppContext) {
cx.update(|cx| {
let store = SettingsStore::test(cx);
cx.set_global(store);
release_channel::init("0.0.0", cx);
theme::init(theme::LoadThemes::JustBase, cx);
Project::init_settings(cx);
ExtensionSettings::register(cx);

View file

@ -16,6 +16,7 @@ use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task};
use http::HttpClient;
use language::LanguageRegistry;
use node_runtime::NodeRuntime;
use release_channel::ReleaseChannel;
use semantic_version::SemanticVersion;
use std::{
path::{Path, PathBuf},
@ -30,6 +31,7 @@ use wit::Extension;
pub(crate) struct WasmHost {
engine: Engine,
release_channel: ReleaseChannel,
http_client: Arc<dyn HttpClient>,
node_runtime: Arc<dyn NodeRuntime>,
pub(crate) language_registry: Arc<LanguageRegistry>,
@ -96,6 +98,7 @@ impl WasmHost {
http_client,
node_runtime,
language_registry,
release_channel: ReleaseChannel::global(cx),
_main_thread_message_task: task,
main_thread_message_tx: tx,
})
@ -124,8 +127,13 @@ impl WasmHost {
},
);
let (mut extension, instance) =
Extension::instantiate_async(&mut store, zed_api_version, &component).await?;
let (mut extension, instance) = Extension::instantiate_async(
&mut store,
this.release_channel,
zed_api_version,
&component,
)
.await?;
extension
.call_init_extension(&mut store)

View file

@ -2,6 +2,7 @@ mod since_v0_0_1;
mod since_v0_0_4;
mod since_v0_0_6;
mod since_v0_0_7;
use release_channel::ReleaseChannel;
use since_v0_0_7 as latest;
use super::{wasm_engine, WasmState};
@ -36,14 +37,23 @@ fn wasi_view(state: &mut WasmState) -> &mut WasmState {
}
/// Returns whether the given Wasm API version is supported by the Wasm host.
pub fn is_supported_wasm_api_version(version: SemanticVersion) -> bool {
wasm_api_version_range().contains(&version)
pub fn is_supported_wasm_api_version(
release_channel: ReleaseChannel,
version: SemanticVersion,
) -> bool {
wasm_api_version_range(release_channel).contains(&version)
}
/// Returns the Wasm API version range that is supported by the Wasm host.
#[inline(always)]
pub fn wasm_api_version_range() -> RangeInclusive<SemanticVersion> {
since_v0_0_1::MIN_VERSION..=latest::MAX_VERSION
pub fn wasm_api_version_range(release_channel: ReleaseChannel) -> RangeInclusive<SemanticVersion> {
let max_version = if release_channel == ReleaseChannel::Dev {
latest::MAX_VERSION
} else {
since_v0_0_6::MAX_VERSION
};
since_v0_0_1::MIN_VERSION..=max_version
}
pub enum Extension {
@ -56,10 +66,11 @@ pub enum Extension {
impl Extension {
pub async fn instantiate_async(
store: &mut Store<WasmState>,
release_channel: ReleaseChannel,
version: SemanticVersion,
component: &Component,
) -> Result<(Self, Instance)> {
if version >= latest::MIN_VERSION {
if release_channel == ReleaseChannel::Dev && version >= latest::MIN_VERSION {
let (extension, instance) =
latest::Extension::instantiate_async(store, &component, latest::linker())
.await

View file

@ -8,6 +8,7 @@ use std::sync::{Arc, OnceLock};
use wasmtime::component::{Linker, Resource};
pub const MIN_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 6);
pub const MAX_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 6);
wasmtime::component::bindgen!({
async: true,