Fix issues with extension API that come up when moving Svelte into an extension (#9611)
We're doing it. Svelte support is moving into an extension. This PR fixes some issues that came up along the way. Notes * extensions need to be able to retrieve the path the `node` binary installed by Zed * previously we were silently swallowing any errors that occurred while loading a grammar * npm commands ran by extensions weren't run in the right directory * Tree-sitter's WASM stdlib didn't support a C function (`strncmp`) needed by the Svelte parser's external scanner * the way that LSP installation status was reported was unnecessarily complex Release Notes: - Removed built-in support for the Svelte and Gleam languages, because full support for those languages is now available via extensions. These extensions will be suggested for download when you open a `.svelte` or `.gleam` file. --------- Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
4459eacc98
commit
6ebe599c98
70 changed files with 1278 additions and 1223 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "zed_extension_api"
|
||||
version = "0.0.1"
|
||||
version = "0.0.4"
|
||||
description = "APIs for creating Zed extensions in Rust"
|
||||
repository = "https://github.com/zed-industries/zed"
|
||||
documentation = "https://docs.rs/zed_extension_api"
|
||||
|
@ -15,7 +15,7 @@ workspace = true
|
|||
path = "src/extension_api.rs"
|
||||
|
||||
[dependencies]
|
||||
wit-bindgen = "0.18"
|
||||
wit-bindgen = "0.22"
|
||||
|
||||
[package.metadata.component]
|
||||
target = { path = "wit" }
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
pub struct Guest;
|
||||
pub use wit::*;
|
||||
|
||||
pub type Result<T, E = String> = core::result::Result<T, E>;
|
||||
|
||||
pub trait Extension: Send + Sync {
|
||||
|
@ -10,14 +8,14 @@ pub trait Extension: Send + Sync {
|
|||
|
||||
fn language_server_command(
|
||||
&mut self,
|
||||
config: wit::LanguageServerConfig,
|
||||
worktree: &wit::Worktree,
|
||||
config: LanguageServerConfig,
|
||||
worktree: &Worktree,
|
||||
) -> Result<Command>;
|
||||
|
||||
fn language_server_initialization_options(
|
||||
&mut self,
|
||||
_config: wit::LanguageServerConfig,
|
||||
_worktree: &wit::Worktree,
|
||||
_config: LanguageServerConfig,
|
||||
_worktree: &Worktree,
|
||||
) -> Result<Option<String>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -54,11 +52,13 @@ pub static ZED_API_VERSION: [u8; 6] = *include_bytes!(concat!(env!("OUT_DIR"), "
|
|||
|
||||
mod wit {
|
||||
wit_bindgen::generate!({
|
||||
exports: { world: super::Component },
|
||||
skip: ["init-extension"]
|
||||
skip: ["init-extension"],
|
||||
path: "./wit/0.0.4",
|
||||
});
|
||||
}
|
||||
|
||||
wit::export!(Component);
|
||||
|
||||
struct Component;
|
||||
|
||||
impl wit::Guest for Component {
|
||||
|
|
|
@ -48,6 +48,9 @@ world extension {
|
|||
/// Gets the current operating system and architecture
|
||||
import current-platform: func() -> tuple<os, architecture>;
|
||||
|
||||
/// Get the path to the node binary used by Zed.
|
||||
import node-binary-path: func() -> result<string, string>;
|
||||
|
||||
/// Gets the latest version of the given NPM package.
|
||||
import npm-package-latest-version: func(package-name: string) -> result<string, string>;
|
||||
|
93
crates/extension_api/wit/0.0.4/extension.wit
Normal file
93
crates/extension_api/wit/0.0.4/extension.wit
Normal file
|
@ -0,0 +1,93 @@
|
|||
package zed:extension;
|
||||
|
||||
world extension {
|
||||
export init-extension: func();
|
||||
|
||||
record github-release {
|
||||
version: string,
|
||||
assets: list<github-release-asset>,
|
||||
}
|
||||
|
||||
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,
|
||||
zip,
|
||||
uncompressed,
|
||||
}
|
||||
|
||||
variant language-server-installation-status {
|
||||
none,
|
||||
downloading,
|
||||
checking-for-update,
|
||||
failed(string),
|
||||
}
|
||||
|
||||
/// Gets the current operating system and architecture
|
||||
import current-platform: func() -> tuple<os, architecture>;
|
||||
|
||||
/// Get the path to the node binary used by Zed.
|
||||
import node-binary-path: func() -> result<string, string>;
|
||||
|
||||
/// Gets the latest version of the given NPM package.
|
||||
import npm-package-latest-version: func(package-name: string) -> result<string, string>;
|
||||
|
||||
/// Returns the installed version of the given NPM package, if it exists.
|
||||
import npm-package-installed-version: func(package-name: string) -> result<option<string>, string>;
|
||||
|
||||
/// Installs the specified NPM package.
|
||||
import npm-install-package: func(package-name: string, version: string) -> result<_, string>;
|
||||
|
||||
/// Gets the latest release for the given GitHub repository.
|
||||
import latest-github-release: func(repo: string, options: github-release-options) -> result<github-release, string>;
|
||||
|
||||
/// Downloads a file from the given url, and saves it to the given filename within the extension's
|
||||
/// working directory. Extracts the file according to the given file type.
|
||||
import download-file: func(url: string, output-filename: string, file-type: downloaded-file-type) -> result<_, string>;
|
||||
|
||||
/// Updates the installation status for the given language server.
|
||||
import set-language-server-installation-status: func(language-server-name: string, status: language-server-installation-status);
|
||||
|
||||
type env-vars = list<tuple<string, string>>;
|
||||
|
||||
record command {
|
||||
command: string,
|
||||
args: list<string>,
|
||||
env: env-vars,
|
||||
}
|
||||
|
||||
resource worktree {
|
||||
read-text-file: func(path: string) -> result<string, string>;
|
||||
which: func(binary-name: string) -> option<string>;
|
||||
shell-env: func() -> env-vars;
|
||||
}
|
||||
|
||||
record language-server-config {
|
||||
name: string,
|
||||
language-name: string,
|
||||
}
|
||||
|
||||
export language-server-command: func(config: language-server-config, worktree: borrow<worktree>) -> result<command, string>;
|
||||
export language-server-initialization-options: func(config: language-server-config, worktree: borrow<worktree>) -> result<option<string>, string>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue