Stream: contributing

Topic: Add roc tree-sitter and lang_server to zed editor


view this post on Zulip Alf Richter (Feb 04 2024 at 22:57):

Short info: I'm started to integrate the roc tree-sitter and the lang_server into the Zed editor code base, after forking and fixing the tree-sitter from https://github.com/faldor20/tree-sitter-roc to work with rust. I'm in the middle of adding the lang server and testing the stuff. BTW. I'm a total rust and zed newbie :sweat_smile: ...

view this post on Zulip Isaac Van Doren (Feb 04 2024 at 23:24):

Sweet!

view this post on Zulip Alf Richter (Feb 05 2024 at 12:57):

image.png
First working version, zed needs to build from sources of my PR:
https://github.com/h2000/zed/tree/add-roc-lang%237378

view this post on Zulip Hannes Nevalainen (Feb 05 2024 at 22:14):

Amazing :) hope it will be accepted so I can ditch vscode for my roc adventures :)

view this post on Zulip Alf Richter (Feb 05 2024 at 23:34):

You can build it from my branch above in the meantime (rust and Xcode needed)

view this post on Zulip Alf Richter (Feb 06 2024 at 17:07):

The official build of zed with roc will take longer, they only want main stream languages directly in their code base, and will provide a plugin api for the others => which is a very good idea for both sides :) . Thats why they closed my PR. I'll port our roc lang stuff to the new plugin api, when they publish these.
(https://github.com/zed-industries/zed/pull/7379)

view this post on Zulip Alf Richter (Feb 06 2024 at 17:09):

In the meantime build zed from source is a option. When I have time I'll try generate an unoffical zed binary....

view this post on Zulip Alf Richter (Feb 08 2024 at 13:36):

Here the ticket for the language extension plugin infrastructure in ZED https://github.com/zed-industries/zed/issues/7096

view this post on Zulip Luke Boswell (Apr 21 2024 at 04:11):

@Alf Richter looks like the've just merged that language plugin extension :smiley:

view this post on Zulip Luke Boswell (Apr 21 2024 at 04:12):

https://zed.dev/blog/language-extensions-part-1

view this post on Zulip Eli Dowling (Apr 21 2024 at 21:32):

I took a little crack at it... because I didn't see this thread :sweat_smile:
https://github.com/faldor20/zed-roc
but zed is pretty broken on my linux laptop so I can't really test it sadly

view this post on Zulip Eli Dowling (Apr 21 2024 at 21:39):

I also found your extension @Alf Richter which is a bit further along than my attempt.

I took a look, I think you just need to update the command to run the roc lsp to "roc_langauage_server" and update the tree-sitter queries and commit Id. :)

view this post on Zulip Alf Richter (Apr 21 2024 at 21:56):

@Luke Boswell, cool finally.
@Eli Dowling thanks for looking into it. I'll continue with it in the next days and report back here, and will look into your attempt as well :)

view this post on Zulip Alf Richter (Apr 24 2024 at 15:01):

Here my current progress:
https://github.com/zed-industries/extensions/pull/432

view this post on Zulip Alf Richter (Apr 27 2024 at 13:49):

The extension for Zed is now working (syntax highlighting + language server) and pushed to zed/extensions github.
Until it is fully integrated with zed, it can be used:

  1. cloning:
git clone https://github.com/h2000/zed-roc
  1. open cloned folder under zed: extensions with the button 'Install Dev Extension' (top right corner).

view this post on Zulip Alf Richter (Apr 27 2024 at 13:51):

zed-roc-0.0.2.png

view this post on Zulip Richard Feldman (Apr 27 2024 at 14:16):

awesome, thanks so much for making this! I've been using Zed for Rust development and I'm stoked to use it for Roc too now! :heart_eyes:

view this post on Zulip Agus Zubiaga (Apr 27 2024 at 14:43):

Same! That’s awesome

view this post on Zulip Bryce Miller (Apr 27 2024 at 22:14):

Hey @Alf Richter, did I perhaps miss a step? When I open the directory with “load dev extension”, a target directory appears with a wasm build, but Zed doesn’t register the extension.

view this post on Zulip Alf Richter (Apr 28 2024 at 15:59):

The error reporting inside Zed for extensions is not really present at the moment.
See my question in github zed extensions roc PR:
image.png

view this post on Zulip Alf Richter (Apr 28 2024 at 16:03):

Please take a look at the Zed log file:

  1. from the commandline less ~/Library/Logs/Zed/Zed.log
  2. or from the ui action: Zed: open log
    Which version of Zed are you using and which OS?

view this post on Zulip Alf Richter (Apr 28 2024 at 16:06):

(deleted)

view this post on Zulip Bryce Miller (Apr 28 2024 at 17:26):

I'm using Zed 0.132.3. MacOS 14.4.1.

view this post on Zulip Bryce Miller (Apr 28 2024 at 17:26):

Thanks for reminding me to check the log. I am seeing a failure to link with clang

view this post on Zulip Bryce Miller (Apr 28 2024 at 17:27):

error: linking with `clang` failed: exit status: 1
      |
      = note: LC_ALL="C" PATH="/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/self-contained:/Users/bryce/.bun/bin:/Users/bryce/Library/pnpm:/Users/bryce/.deno/bin:/Users/bryce/.nvm/versions/node/v18.17.1/bin:/Users/bryce/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/bryce/.cargo/bin:/Users/bryce/.local/bin" VSLANG="1033" "clang" "-Wl,-z" "-Wl,stack-size=1048576" "-Wl,--stack-first" "-Wl,--allow-undefined" "-Wl,--no-demangle" "--target=wasm32-wasi" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.11plhyn6ipo7viar.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.1vei4rcn7kbe74ac.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.23yaky0p38ruxrxg.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.254r9n57ez343j56.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.2kmz0y3jv97t4r08.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.36di8uldlfvo4x6c.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.39fivxgqlqtbax5q.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.4urcaxw6v76vys02.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.5a8dm17b49z7ydzt.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.5bpkyd1aajky4dsu.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.5dsbjiiknb8b4mou.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.98l8zabvrjnako2.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.tlp9xsybxq6baya.rcgu.o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.14gw6g7p6hxl6dk0.rcgu.o" "-L" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps" "-L" "/Users/bryce/zed-roc/target/debug/deps" "-L" "/Users/bryce/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wit-bindgen-rt-0.22.0/src" "-L" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libzed_extension_api-4bc53ae7cc620fa7.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libwit_bindgen-b3845b82bf0c8a26.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libwit_bindgen_rt-4dbaedb4e9afa9b8.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libbitflags-1cd067e7651c61cd.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libserde_json-c8535d57a65918e3.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libitoa-63e76c004c10bfd5.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libryu-c70fca966f8d67f8.rlib" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/libserde-02e5f5569d41ac55.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libstd-de60da10c915f271.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libpanic_abort-2ff3720a26f3bfbc.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libwasi-a7797548ce4eeae6.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_demangle-2d2a6dd59c5cf747.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libstd_detect-256dfe82108a7561.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libhashbrown-0fe0478abf0490d0.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_std_workspace_alloc-d7e0e2199ba685f0.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libminiz_oxide-e3510031f5d59ded.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libadler-0a394d8b34770ed7.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libunwind-d5d9a1e3135ff952.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcfg_if-0c0c37c26cde79c3.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/liblibc-6bef7357988c68aa.rlib" "-lc" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/liballoc-8034fbd05189bdbb.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/librustc_std_workspace_core-c7c23a7c61c36be0.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcore-c236af2463ff1d9c.rlib" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcompiler_builtins-b7a1025e8669331b.rlib" "-lwit_bindgen_cabi_realloc" "-B/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/gcc-ld" "-fuse-ld=lld" "--target=wasm32-wasi" "-nostartfiles" "-L" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib" "-L" "/Users/bryce/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/self-contained" "-o" "/Users/bryce/zed-roc/target/wasm32-wasi/debug/deps/zed_roc.wasm" "-Wl,--gc-sections" "-static" "-shared" "-nodefaultlibs"
      = note: clang: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]
              rust-lld: error: entry symbol not defined (pass --no-entry to suppress): _start
              clang: error: linker command failed with exit code 1 (use -v to see invocation)


    error: could not compile `zed_roc` (lib) due to 1 previous error

view this post on Zulip Bryce Miller (Apr 28 2024 at 17:28):

(Also a lot of 'apple-m1' is not a recognized processor for this target (ignoring processor))

view this post on Zulip Alf Richter (Apr 28 2024 at 18:14):

@Bryce Miller: I had similar errors about apple-m1 before, my solution was to reinstall my rust installation:
e.g. (or using an other way)

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

view this post on Zulip Bryce Miller (Apr 28 2024 at 19:13):

Reinstalling rustup and the stable toolchain fixed the problem! Thanks!

view this post on Zulip Alf Richter (May 02 2024 at 07:15):

Roc has (in Zed 0.133.5) an officially zed extension now:
image.png

view this post on Zulip Alf Richter (May 02 2024 at 07:24):

I did not found a good zentral place to add zed to the official editors list. For the best onboarding experience I'd expect it near/in the installation guide? Should I make a PR to update the GettingStarted.md in roc-lang github, and add an editor section with links to all editors? Or here https://www.roc-lang.org/install ?

view this post on Zulip Eli Dowling (May 02 2024 at 10:42):

Go ahead and make a pr to that page :)

view this post on Zulip Richard Feldman (May 02 2024 at 11:07):

amazing, thank you so much for making this happen!!! :heart_eyes:

view this post on Zulip Alf Richter (May 02 2024 at 17:05):

My PR for adding an editor section to the getting started readme is ready for review:
https://github.com/roc-lang/roc/pull/6706/files?short_path=15e1597#diff-15e15974446c709f371ea5c1041c2a5fb944f3f8de6ddfbae91a05ae93041255

view this post on Zulip Richard Feldman (May 04 2024 at 23:56):

I found a funny bug in the grammar: it doesn't know crash is a keyword, but it does know as is a keyword, resulting in...

Screenshot-2024-05-04-at-7.55.54PM.png

view this post on Zulip Richard Feldman (May 05 2024 at 00:00):

also it doesn't know about import and exposing but that's not surprising given how recently the PR for those landed! :big_smile:

view this post on Zulip Eli Dowling (May 05 2024 at 11:41):

I'll take a look at updating to the new suntax in the next week.
If I could get a heads up about when a new syntax is coming a week in advance I should be able to co-ordinate to get a change in so people have an immediate upgrade path :)

view this post on Zulip Alf Richter (May 08 2024 at 13:12):

@Anton
I've created a new PR to update a second place for new editor exts (this page is linked to the roc website directly). Why do we've two different install pages :) , the tutorial pages links to both?
https://github.com/roc-lang/roc/pull/6735

view this post on Zulip Anton (May 08 2024 at 13:29):

Thanks @Alf Richter, I'll try to take a look today :)

view this post on Zulip Luke Boswell (May 08 2024 at 14:08):

Is there a way to turn off the auto formatting in zed for roc files?

There's a few issues that are kind of a pain rn. At some point I'd like to submit a fix for them, but if I can just turn of the auto formatting for now that would be nice.

view this post on Zulip Agus Zubiaga (May 08 2024 at 14:18):

Yes, you can have language-specific config, like:

// ...
"languages": {
    "Roc": {
      "format_on_save": "off"
    },
 }
// ...

view this post on Zulip Luke Boswell (May 08 2024 at 14:26):

Thank you

view this post on Zulip Agus Zubiaga (May 08 2024 at 14:29):

With Zed, I'd also recommend using a monospace font for the UI, because they use the UI font for LSP diagnostics and things don't line up otherwise.

view this post on Zulip Agus Zubiaga (May 08 2024 at 14:31):

Ideally, they would use the buffer_font_family for diagnostics or have a distinct setting that defaults to it, so you can still use a proportional font in the rest of the UI.

view this post on Zulip Richard Feldman (May 08 2024 at 15:00):

@Agus Zubiaga can you open an issue on zed for that?

view this post on Zulip Agus Zubiaga (May 08 2024 at 15:35):

Done: https://github.com/zed-industries/zed/issues/11564

view this post on Zulip Agus Zubiaga (May 08 2024 at 15:46):

It’s a little subjective because ideally our diagnostics shouldn’t be trying to highlight things that are already visible in the buffer.

view this post on Zulip Agus Zubiaga (May 08 2024 at 15:47):

However, I still think monospace diagnostics allow more flexibility.

view this post on Zulip Anton (May 10 2024 at 17:36):

Why do we've two different install pages :) , the tutorial pages links to both?

Thanks for bringing this up @Alf Richter. I'm in favor of avoiding duplication and putting all getting started/install stuff on the Roc website only. Anybody have concerns with that?

view this post on Zulip Andrea Bueide (Sep 09 2024 at 04:50):

does anyone know how to build the roc extension on nixos? am trying to learn how to contribute on zed extensions, can't find anything about building on nix though


Last updated: Jul 06 2025 at 12:14 UTC