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    config.toml
 36    highlights.scm
 37  themes/
 38    my-theme.json
 39```
 40
 41## WebAssembly
 42
 43Procedural 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:
 44
 45```toml
 46[package]
 47name = "my-extension"
 48version = "0.0.1"
 49edition = "2021"
 50
 51[lib]
 52crate-type = ["cdylib"]
 53
 54[dependencies]
 55zed_extension_api = "0.0.6"
 56```
 57
 58Make sure to use the latest version of the [`zed_extension_api`](https://crates.io/crates/zed_extension_api) available on crates.io.
 59
 60In 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:
 61
 62```rs
 63use zed_extension_api as zed;
 64
 65struct MyExtension {
 66    // ... state
 67}
 68
 69impl zed::Extension for MyExtension {
 70    // ...
 71}
 72
 73zed::register_extension!(MyExtension);
 74```
 75
 76## Developing an Extension Locally
 77
 78When developing an extension, you can use it in Zed without needing to publish it by installing it as a _dev extension_.
 79
 80From the extensions page, click the `Install Dev Extension` button and select the directory containing your extension.
 81
 82If you already have a published extension with the same name installed, your dev extension will override it.
 83
 84## Publishing your extension
 85
 86To publish an extension, open a PR to [this repo](https://github.com/zed-industries/extensions).
 87
 88In your PR, do the following:
 89
 901. Add your extension as a Git submodule within the `extensions/` directory
 912. Add a new entry to the top-level `extensions.toml` file containing your extension:
 92
 93```toml
 94[my-extension]
 95submodule = "extensions/my-extension"
 96version = "0.0.1"
 97```
 98
 993. Run `pnpm sort-extensions` to ensure `extensions.toml` and `.gitmodules` are sorted
100
101Once your PR is merged, the extension will be packaged and published to the Zed extension registry.