developing-extensions.md

  1# Developing Extensions
  2
  3## Extension Capabilities
  4
  5Extensions can add the following capabilities to Zed:
  6
  7- [Languages](./languages.md)
  8- [Themes](./themes.md)
  9- [Slash Commands](./slash-commands.md)
 10
 11## Directory Structure of a Zed Extension
 12
 13A Zed extension is a Git repository that contains an `extension.toml`. This file must contain some
 14basic information about the extension:
 15
 16```toml
 17id = "my-extension"
 18name = "My extension"
 19version = "0.0.1"
 20schema_version = 1
 21authors = ["Your Name <you@example.com>"]
 22description = "My cool extension"
 23repository = "https://github.com/your-name/my-zed-extension"
 24```
 25
 26In addition to this, there are several other optional files and directories that can be used to add functionality to a Zed extension. An example directory structure of an extension that provides all capabilities is as follows:
 27
 28```
 29my-extension/
 30  extension.toml
 31  Cargo.toml
 32  src/
 33    lib.rs
 34  languages/
 35    my-language/
 36      config.toml
 37      highlights.scm
 38  themes/
 39    my-theme.json
 40```
 41
 42## WebAssembly
 43
 44Procedural parts of extensions are written in Rust and compiled to WebAssembly. To develop an extension that includes custom code, include a `Cargo.toml` like this:
 45
 46```toml
 47[package]
 48name = "my-extension"
 49version = "0.0.1"
 50edition = "2021"
 51
 52[lib]
 53crate-type = ["cdylib"]
 54
 55[dependencies]
 56zed_extension_api = "0.0.6"
 57```
 58
 59Make sure to use the latest version of the [`zed_extension_api`](https://crates.io/crates/zed_extension_api) available on crates.io.
 60
 61In the `src/lib.rs` file in your Rust crate you will need to define a struct for your extension and implement the `Extension` trait, as well as use the `register_extension!` macro to register your extension:
 62
 63```rs
 64use zed_extension_api as zed;
 65
 66struct MyExtension {
 67    // ... state
 68}
 69
 70impl zed::Extension for MyExtension {
 71    // ...
 72}
 73
 74zed::register_extension!(MyExtension);
 75```
 76
 77## Developing an Extension Locally
 78
 79When developing an extension, you can use it in Zed without needing to publish it by installing it as a _dev extension_.
 80
 81From the extensions page, click the `Install Dev Extension` button and select the directory containing your extension.
 82
 83If you already have a published extension with the same name installed, your dev extension will override it.
 84
 85## Publishing your extension
 86
 87To publish an extension, open a PR to [this repo](https://github.com/zed-industries/extensions).
 88
 89In your PR, do the following:
 90
 911. Add your extension as a Git submodule within the `extensions/` directory
 922. Add a new entry to the top-level `extensions.toml` file containing your extension:
 93
 94```toml
 95[my-extension]
 96submodule = "extensions/my-extension"
 97version = "0.0.1"
 98```
 99
1003. Run `pnpm sort-extensions` to ensure `extensions.toml` and `.gitmodules` are sorted
101
102Once your PR is merged, the extension will be packaged and published to the Zed extension registry.