Did you ever want to host your own custom version of a tree-sitter playground?
May be you wanted to:
- Demo the fruits of your labor to others more conveniently, or
- Switch between similar grammars when developing an alternative, or
- Provide a convenient way for others to investigate an issue, or
...for some other reason (^^;
The tree-sitter
cli's playground
subcommand starts a web server
that serves files that are "baked in" to the cli binary [1]. Although
this is convenient for local development, the arrangement does not
lend itself to easy hosting of those files nor to using multiple
grammars.
The following are some known approaches to ending up with a suitable tree of files and directories for hosting:
-
Manually determine the relevant files by studying
cli/src/playground.rs
and related resources in the tree-sitter repository . Then prepare the necessary files to live in an appropriate directory. -
Copy-modify the content which aheber prepared for tree-sitter-sfapex or the tree-sitter website's playground content.
On a side note, for each desired grammar, a corresponding .wasm
file
is needed. See the official
instructions
and/or this
question
for more details.
A link to treeground was posted to the tree-sitter Discord server recently. It looks interesting and might be relevant, but the author of this document doesn't know enough about it yet to say much more (^^;
[1] The tree-sitter playground
subcommand can also serve files from
a clone of the tree-sitter
repository if the environment variable
TREE_SITTER_BASE_DIR
is pointed at it. See cli/src/playground.rs
in the tree-sitter repository for details. Note that the grammar's
.wasm
file is read from the grammar's repository directory.