|
| 1 | +# Contributing to rescript-zed |
| 2 | + |
| 3 | +## Developing |
| 4 | + |
| 5 | +This guide covers local development for the rescript-zed extension. For more detailed information about Zed extension development, see the [official Zed documentation](https://zed.dev/docs/extensions/developing-extensions). |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +Before starting to develop this extension, make sure you have: |
| 10 | + |
| 11 | +- [Rust installed via rustup](https://rustup.rs/) (required for Zed extensions) |
| 12 | +- Zed editor installed |
| 13 | + |
| 14 | +**Note:** Rust must be installed via rustup. If you have Rust installed via homebrew or otherwise, installing dev extensions will not work. |
| 15 | + |
| 16 | +### Development Workflow |
| 17 | + |
| 18 | +When developing the extension, you can use it in Zed without needing to publish it by installing it as a _dev extension_. |
| 19 | + |
| 20 | +1. **Clone this repository** |
| 21 | + |
| 22 | +2. **Install the dev extension in Zed:** |
| 23 | + - Open Zed |
| 24 | + - Open the Extensions page (Cmd + Shift + P, then type "zed: extensions") |
| 25 | + - Click the `Install Dev Extension` button (or use the `zed: install dev extension` action) |
| 26 | + - Select the directory containing this extension |
| 27 | + |
| 28 | +3. **Making changes:** |
| 29 | + - Edit the extension code as needed |
| 30 | + - You do **not** need to build anything manually before installing/reinstalling |
| 31 | + - After making changes, use the "Reinstall" button from the Extensions menu to reload your changes |
| 32 | + |
| 33 | +4. **Sanity check (optional):** |
| 34 | + - You can run `cargo build` in the extension directory to verify the Rust code compiles |
| 35 | + - This is not required for (re)installing the extension, but can help catch compilation errors early |
| 36 | + |
| 37 | +### Debugging |
| 38 | + |
| 39 | +If you need to troubleshoot, here are some useful debugging tools: |
| 40 | + |
| 41 | +**View Zed logs:** |
| 42 | + |
| 43 | +```sh |
| 44 | +tail -f ~/Library/Logs/Zed/Zed.log |
| 45 | +``` |
| 46 | + |
| 47 | +Or use the `zed: open log` command from Zed. |
| 48 | + |
| 49 | +**For more verbose debug output (recommended):** |
| 50 | + |
| 51 | +Close Zed completely and relaunch it from the command line with: |
| 52 | + |
| 53 | +```sh |
| 54 | +zed --foreground |
| 55 | +``` |
| 56 | + |
| 57 | +This will show more verbose INFO level logging in your terminal, including `println!` and `dbg!` output from your extension code. This is the preferred way to debug extensions during development. |
| 58 | + |
| 59 | +**View language server logs:** |
| 60 | + |
| 61 | +Open Cmd + Shift + P and find: |
| 62 | + |
| 63 | +``` |
| 64 | +dev: open language server logs |
| 65 | +``` |
| 66 | + |
| 67 | +### Using a Local Language Server Build |
| 68 | + |
| 69 | +If you're also developing the ReScript language server locally, you can configure Zed to use your local build instead of the published version. |
| 70 | + |
| 71 | +Add the following to your Zed settings (`zed: open settings file`): |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "lsp": { |
| 76 | + "rescript-language-server": { |
| 77 | + "binary": { |
| 78 | + "path": "/absolute-path/to/your/node-or-bun", |
| 79 | + "arguments": [ |
| 80 | + "/path/to/your/rescript-vscode/server/out/cli.js", |
| 81 | + "--stdio" |
| 82 | + ] |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +Replace the paths with your actual local paths: |
| 90 | +- `path`: Path to your Node.js/Bun runtime (e.g., `/Users/username/.bun/bin/bun` or `/usr/local/bin/node`) |
| 91 | +- First argument: Path to your local language server CLI (e.g., `/Users/username/Projects/rescript-vscode/server/out/cli.js`) |
| 92 | + |
| 93 | +**Note:** Make sure your local language server is built before using it. For rescript-vscode, this typically means running the build command in that repository first. |
| 94 | + |
| 95 | +### Publishing Changes |
| 96 | + |
| 97 | +If you already have the published version of the extension installed, it will be uninstalled automatically when you install the dev extension. The Extensions page will indicate that the upstream extension is "Overridden by dev extension". |
| 98 | + |
| 99 | +To publish updates to the extension, follow the [Zed extension publishing guidelines](https://zed.dev/docs/extensions/developing-extensions#publishing-your-extension). |
0 commit comments