Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Install Zed extension target
run: rustup target add wasm32-wasip2
- name: Check formatting
run: cargo fmt -- --check
- name: Lint
run: cargo clippy --all-targets -- -D warnings
- name: Build extension
run: cargo build --target wasm32-wasip2 --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "zed_roc"
version = "0.1.1"
version = "0.1.2"
authors = ["Alf Richter <kuehlboxen.vorgemisch0e@icloud.com>"]
edition = "2021"

[dependencies]
zed_extension_api = "0.0.6"
zed_extension_api = "0.7.0"

[lib]
crate-type = ["cdylib"]
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ An extension for Zed that adds Roc language support:
- Install Roc from the [roc-lang](https://roc-lang.org) website
- Ensure the `roc` binary is in your PATH
- Install Zed from the [Zed](https://zed.dev) website
- Install the Zed extension WebAssembly target for development:
```sh
rustup target add wasm32-wasip2
```

## ROC

Expand All @@ -26,7 +30,7 @@ An extension for Zed that adds Roc language support:
3. Select this repository folder
4. Click "Rebuild" if prompted

**Note:** The version shown in Zed's Extensions panel may display the marketplace version (e.g., v0.0.6) even when the dev extension is active. This is a Zed caching behavior when the extension ID matches a marketplace extension.
**Note:** The version shown in Zed's Extensions panel may display the marketplace version even when the dev extension is active. This is a Zed caching behavior when the extension ID matches a marketplace extension.

### Verifying the Dev Extension is Running

Expand All @@ -42,22 +46,29 @@ If the path points to your local repository (not `~/Library/Application Support/
- `extension.toml` - Extension manifest (id, version, grammar source, language config)
- `languages/roc/config.toml` - Language configuration (file extensions, comments, brackets)
- `languages/roc/*.scm` - Tree-sitter queries (highlights, indents, etc.)
- `grammars/roc/` - Git clone of tree-sitter-roc (must match repository in extension.toml)
- `src/lib.rs` - Rust extension entry point that launches `roc experimental-lsp --stdio`

### Validating Changes

```sh
cargo fmt -- --check
cargo clippy --all-targets -- -D warnings
cargo test
cargo build --target wasm32-wasip2
```

### Updating the Tree-sitter Grammar

The `grammars/roc/` directory must be a git clone of the repository specified in `extension.toml`. To update:
Zed fetches the grammar from the repository and commit in `extension.toml`. The local `grammars/roc/` directory is ignored and only used as a working checkout when syncing query files.

To update:

1. Update the commit hash in `extension.toml` under `[grammars.roc]`
2. Update the grammar submodule:
2. Sync query files:
```sh
cd grammars/roc
git fetch origin
git checkout <commit-hash>
just sync-queries
```
3. Sync query files: `cp grammars/roc/queries/*.scm languages/roc/`
4. Delete cached wasm to force recompilation: `rm grammars/roc.wasm`
5. In Zed, click "Rebuild" on the extension
3. In Zed, click "Rebuild" on the extension

### Troubleshooting

Expand All @@ -73,20 +84,22 @@ The `grammars/roc/` directory must be a git clone of the repository specified in
- Linux: `~/.local/share/zed/extensions/`

**Grammar compilation errors:**
- Ensure `grammars/roc/` is a git clone of the repository URL in `extension.toml`
- The git remote origin must match the repository URL exactly
- Check that `[grammars.roc]` in `extension.toml` points to a valid repository and commit
- Remove any cached `grammars/roc.wasm` or `extension.wasm`, then rebuild the extension

### Useful Commands

```sh
# Sync query files from grammar to languages
cp grammars/roc/queries/*.scm languages/roc/
just sync-queries

# Clean build artifacts
rm -f grammars/roc.wasm extension.wasm
just clean

# Check Zed logs (macOS)
tail -f ~/Library/Logs/Zed/Zed.log | grep -i roc
```

The `just` recipes are optional conveniences. The validation commands above only require Rust.

![Zed Example](https://github.com/h2000/zed-roc/assets/187650/1ec0cda3-3679-4223-bc5e-3272babde364)
2 changes: 1 addition & 1 deletion extension.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id = "roc"
name = "Roc"
description = "Roc language support for Zed"
version = "0.1.1"
version = "0.1.2"
schema_version = 1
authors = ["Alf Richter <kuehlboxen.vorgemisch0e@icloud.com>"]
repository = "https://github.com/h2000/zed-roc"
Expand Down
20 changes: 18 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# Sync query files from tree-sitter-roc to languages/roc
grammar_repository := `sed -n '/^\[grammars\.roc\]/,/^\[/s/^repository = "\(.*\)"/\1/p' extension.toml | head -n 1`
grammar_commit := `sed -n '/^\[grammars\.roc\]/,/^\[/s/^commit = "\(.*\)"/\1/p' extension.toml | head -n 1`

check:
cargo fmt -- --check
cargo clippy --all-targets -- -D warnings
cargo test
cargo build --target wasm32-wasip2

# Sync query files from the tree-sitter-roc commit in extension.toml.
sync-queries:
mkdir -p grammars
if [ ! -d grammars/roc/.git ]; then git clone {{grammar_repository}} grammars/roc; fi
cd grammars/roc && git remote set-url origin {{grammar_repository}}
cd grammars/roc && git fetch origin && git checkout {{grammar_commit}}
cp -v grammars/roc/queries/*.scm languages/roc/

# Update grammar to a specific commit and sync queries
update-grammar COMMIT:
mkdir -p grammars
if [ ! -d grammars/roc/.git ]; then git clone {{grammar_repository}} grammars/roc; fi
cd grammars/roc && git remote set-url origin {{grammar_repository}}
cd grammars/roc && git fetch origin && git checkout {{COMMIT}}
just sync-queries
cp -v grammars/roc/queries/*.scm languages/roc/
rm -f grammars/roc.wasm
@echo "Done. Click 'Rebuild' in Zed to recompile the grammar."

Expand Down
15 changes: 15 additions & 0 deletions languages/roc/outline.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
(file
(nominal_type_def
(apply_type
(concrete_type) @name)) @item)

(file
(opaque_type_def
(apply_type
Expand All @@ -18,3 +23,13 @@
(decl_left
(identifier_pattern
(identifier) @name))) @item)

(file
(var_declaration
name: (identifier) @name) @item)

(nominal_methods
(value_declaration
(decl_left
(identifier_pattern
(identifier) @name))) @item)
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl zed::Extension for RocExtension {

Ok(zed::Command {
command: path,
args: vec!["experimental-lsp".to_string()],
args: vec!["experimental-lsp".to_string(), "--stdio".to_string()],
env: Default::default(),
})
}
Expand Down
206 changes: 0 additions & 206 deletions src/roc.rs

This file was deleted.

Loading