zed_extension_api: Fork new version of extension API (#27390)

This PR forks a new version of the `zed_extension_api` in preparation
for new changes.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-03-24 17:06:05 -04:00 committed by GitHub
parent a469c0e261
commit 920eda07a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1437 additions and 647 deletions

View file

@ -4,11 +4,12 @@ mod since_v0_0_6;
mod since_v0_1_0;
mod since_v0_2_0;
mod since_v0_3_0;
mod since_v0_4_0;
use extension::{KeyValueStoreDelegate, WorktreeDelegate};
use language::LanguageName;
use lsp::LanguageServerName;
use release_channel::ReleaseChannel;
use since_v0_3_0 as latest;
use since_v0_4_0 as latest;
use super::{wasm_engine, WasmState};
use anyhow::{anyhow, Context as _, Result};
@ -59,7 +60,7 @@ pub fn wasm_api_version_range(release_channel: ReleaseChannel) -> RangeInclusive
let max_version = match release_channel {
ReleaseChannel::Dev | ReleaseChannel::Nightly => latest::MAX_VERSION,
ReleaseChannel::Stable | ReleaseChannel::Preview => latest::MAX_VERSION,
ReleaseChannel::Stable | ReleaseChannel::Preview => since_v0_3_0::MAX_VERSION,
};
since_v0_0_1::MIN_VERSION..=max_version
@ -89,6 +90,7 @@ pub fn authorize_access_to_unreleased_wasm_api_version(
}
pub enum Extension {
V040(since_v0_4_0::Extension),
V030(since_v0_3_0::Extension),
V020(since_v0_2_0::Extension),
V010(since_v0_1_0::Extension),
@ -108,10 +110,21 @@ impl Extension {
let _ = release_channel;
if version >= latest::MIN_VERSION {
authorize_access_to_unreleased_wasm_api_version(release_channel)?;
let extension =
latest::Extension::instantiate_async(store, component, latest::linker())
.await
.context("failed to instantiate wasm extension")?;
Ok(Self::V040(extension))
} else if version >= since_v0_3_0::MIN_VERSION {
let extension = since_v0_3_0::Extension::instantiate_async(
store,
component,
since_v0_3_0::linker(),
)
.await
.context("failed to instantiate wasm extension")?;
Ok(Self::V030(extension))
} else if version >= since_v0_2_0::MIN_VERSION {
let extension = since_v0_2_0::Extension::instantiate_async(
@ -163,6 +176,7 @@ impl Extension {
pub async fn call_init_extension(&self, store: &mut Store<WasmState>) -> Result<()> {
match self {
Extension::V040(ext) => ext.call_init_extension(store).await,
Extension::V030(ext) => ext.call_init_extension(store).await,
Extension::V020(ext) => ext.call_init_extension(store).await,
Extension::V010(ext) => ext.call_init_extension(store).await,
@ -180,6 +194,10 @@ impl Extension {
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<Command, String>> {
match self {
Extension::V040(ext) => {
ext.call_language_server_command(store, &language_server_id.0, resource)
.await
}
Extension::V030(ext) => {
ext.call_language_server_command(store, &language_server_id.0, resource)
.await
@ -230,6 +248,14 @@ impl Extension {
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<Option<String>, String>> {
match self {
Extension::V040(ext) => {
ext.call_language_server_initialization_options(
store,
&language_server_id.0,
resource,
)
.await
}
Extension::V030(ext) => {
ext.call_language_server_initialization_options(
store,
@ -295,6 +321,14 @@ impl Extension {
resource: Resource<Arc<dyn WorktreeDelegate>>,
) -> Result<Result<Option<String>, String>> {
match self {
Extension::V040(ext) => {
ext.call_language_server_workspace_configuration(
store,
&language_server_id.0,
resource,
)
.await
}
Extension::V030(ext) => {
ext.call_language_server_workspace_configuration(
store,
@ -338,10 +372,23 @@ impl Extension {
completions: Vec<latest::Completion>,
) -> Result<Result<Vec<Option<CodeLabel>>, String>> {
match self {
Extension::V030(ext) => {
Extension::V040(ext) => {
ext.call_labels_for_completions(store, &language_server_id.0, &completions)
.await
}
Extension::V030(ext) => Ok(ext
.call_labels_for_completions(
store,
&language_server_id.0,
&completions.into_iter().collect::<Vec<_>>(),
)
.await?
.map(|labels| {
labels
.into_iter()
.map(|label| label.map(Into::into))
.collect()
})),
Extension::V020(ext) => Ok(ext
.call_labels_for_completions(
store,
@ -392,10 +439,23 @@ impl Extension {
symbols: Vec<latest::Symbol>,
) -> Result<Result<Vec<Option<CodeLabel>>, String>> {
match self {
Extension::V030(ext) => {
Extension::V040(ext) => {
ext.call_labels_for_symbols(store, &language_server_id.0, &symbols)
.await
}
Extension::V030(ext) => Ok(ext
.call_labels_for_symbols(
store,
&language_server_id.0,
&symbols.into_iter().collect::<Vec<_>>(),
)
.await?
.map(|labels| {
labels
.into_iter()
.map(|label| label.map(Into::into))
.collect()
})),
Extension::V020(ext) => Ok(ext
.call_labels_for_symbols(
store,
@ -446,6 +506,10 @@ impl Extension {
arguments: &[String],
) -> Result<Result<Vec<SlashCommandArgumentCompletion>, String>> {
match self {
Extension::V040(ext) => {
ext.call_complete_slash_command_argument(store, command, arguments)
.await
}
Extension::V030(ext) => {
ext.call_complete_slash_command_argument(store, command, arguments)
.await
@ -470,6 +534,10 @@ impl Extension {
resource: Option<Resource<Arc<dyn WorktreeDelegate>>>,
) -> Result<Result<SlashCommandOutput, String>> {
match self {
Extension::V040(ext) => {
ext.call_run_slash_command(store, command, arguments, resource)
.await
}
Extension::V030(ext) => {
ext.call_run_slash_command(store, command, arguments, resource)
.await
@ -495,6 +563,10 @@ impl Extension {
project: Resource<ExtensionProject>,
) -> Result<Result<Command, String>> {
match self {
Extension::V040(ext) => {
ext.call_context_server_command(store, &context_server_id, project)
.await
}
Extension::V030(ext) => {
ext.call_context_server_command(store, &context_server_id, project)
.await
@ -517,6 +589,7 @@ impl Extension {
provider: &str,
) -> Result<Result<Vec<String>, String>> {
match self {
Extension::V040(ext) => ext.call_suggest_docs_packages(store, provider).await,
Extension::V030(ext) => ext.call_suggest_docs_packages(store, provider).await,
Extension::V020(ext) => ext.call_suggest_docs_packages(store, provider).await,
Extension::V010(ext) => ext.call_suggest_docs_packages(store, provider).await,
@ -534,6 +607,10 @@ impl Extension {
kv_store: Resource<Arc<dyn KeyValueStoreDelegate>>,
) -> Result<Result<(), String>> {
match self {
Extension::V040(ext) => {
ext.call_index_docs(store, provider, package_name, kv_store)
.await
}
Extension::V030(ext) => {
ext.call_index_docs(store, provider, package_name, kv_store)
.await