fred/extensions/slash-commands-example
Chris Boette aef25a3bc3
slash_commands_example: Improve setup instructions in README (#26217)
This PR improves the setup instructions for the slash-commands-example
extension by:

1. Replacing the `sed` command with a more reliable approach that
completely replaces the Cargo.toml file.

2. Explicitly showing how to create a standalone extension with a
properly configured Cargo.toml file that:
   - Uses `edition = "2021"` instead of `edition.workspace = true`
   - Doesn't include `publish.workspace = true`
   - Doesn't include the `[lints]` section

This change addresses an issue where the extension wouldn't work when
copied as a standalone project due to workspace references that are only
valid when the extension is built as part of the main Zed repository.

The updated instructions provide a clear, reliable path for developers
to create their own Zed extensions based on the slash commands example.

Release Notes:

- N/A
2025-03-06 10:56:17 -05:00
..

Slash Commands Example Extension

This is an example extension showcasing how to write slash commands.

See: Extensions: Slash Commands in the Zed Docs.

Pre-requisites

Install Rust Toolchain:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Setup

git clone https://github.com/zed-industries/zed.git
cp -RL zed/extensions/slash-commands-example .

cd slash-commands-example/

# Update Cargo.toml to make it standalone
cat > Cargo.toml << EOF
[package]
name = "slash_commands_example"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"

[lib]
path = "src/slash_commands_example.rs"
crate-type = ["cdylib"]

[dependencies]
zed_extension_api = "0.1.0"
EOF

curl -O https://raw.githubusercontent.com/rust-lang/rust/master/LICENSE-APACHE
echo "# Zed Slash Commands Example Extension" > README.md
echo "Cargo.lock" > .gitignore
echo "target/" >> .gitignore
echo "*.wasm" >> .gitignore

git init
git add .
git commit -m "Initial commit"

cd ..
mv slash-commands-example MY-SUPER-COOL-ZED-EXTENSION
zed $_

Installation

  1. Open the command palette (cmd-shift-p or ctrl-shift-p).
  2. Launch zed: install dev extension
  3. Select the extension folder created above

Test

Open the assistant and type /echo and /pick-one at the beginning of a line.

Customization

Open the extensions.toml file and set the id, name, description, authors and repository fields.

Rename slash-commands-example.rs you'll also have to update Cargo.toml

Rebuild

Rebuild to see these changes reflected:

  1. Open Zed Extensions (cmd-shift-x or ctrl-shift-x).
  2. Click Rebuild next to your Dev Extension (formerly "Slash Command Example")

Troubleshooting / Logs

  • MacOS: tail -f ~/Library/Logs/Zed/Zed.log
  • Linux: tail -f ~/.local/share/zed/logs/Zed.log

Documentation