zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.4k stars 1.16k forks source link

Tree-sitter support via WASM #3230

Open gdamore opened 3 months ago

gdamore commented 3 months ago

I know that there was another ticket about tree-sitter support -- but it looks like it got closed, probably because of cgo.

The good news is that with wasm and wazero, tree-sitter can be done entirely without cgo.

Basically, tree-sitter modules (not all, but most) can compile to wasm. Then you take that wasm file, and can use wazero to either compile it to native code (arm64 or amd64), or you can use it in interpreter mode to run it (will obviously be slower).

This may offer a nice cgo-free path. Note that the wasm stuff is used by zed.dev for their isolation of the tree-sitter into a separate space, preventing a bad tree-sitter grammar from taking down the process.

I am not a user of micro, although you're using my Tcell package, and I'm also the author of a couple of tree-sitter grammars (notably the D one) and I'm keen to help the ecosystem for D -- and thought this might help. Feel free to close if utterly non-interesting.