4.7 KiB
| title | permalink |
|---|---|
| Contributing | contributing |
Contributing
Code of Conduct
Contributors to Tree-sitter should abide by the Contributor Covenant.
Developing Tree-sitter
Prerequisites
To make changes to Tree-sitter, you should have:
- A C compiler, for compiling the core library and the generated parsers.
- A Rust toolchain, for compiling the Rust bindings, the highlighting library, and the CLI.
- Node.js and NPM, for generating parsers from
grammar.jsfiles. - Either Emscripten, Docker, or podman for compiling the library to WASM.
Building
Clone the repository:
git clone https://github.com/tree-sitter/tree-sitter
cd tree-sitter
Optionally, build the WASM library. If you skip this step, then the tree-sitter playground command will require an internet connection. If you have emscripten installed, this will use your emcc compiler. Otherwise, it will use Docker or Podman:
cargo xtask build-wasm
Build the Rust libraries and the CLI:
cargo build --release
This will create the tree-sitter CLI executable in the target/release folder.
Testing
Before you can run the tests, you need to clone some grammars that are used for testing:
cargo xtask fetch-fixtures
To test any changes you've made to the CLI, you can regenerate these parsers using your current CLI code:
cargo xtask generate-fixtures
Then you can run the tests:
cargo xtask test
Similarly, to test the WASM binding, you need to compile these parsers to WASM:
cargo xtask generate-fixtures --wasm
cargo xtask test-wasm
Debugging
The test script has a number of useful flags. You can list them all by running cargo xtask test -h. Here are some of the main flags:
If you want to run a specific unit test, pass its name (or part of its name) as an argument:
cargo xtask test test_does_something
You can run the tests under the debugger (either lldb or gdb) using the -g flag:
cargo xtask test -g test_does_something
Published Packages
The main tree-sitter/tree-sitter repository contains the source code for several packages that are published to package registries for different languages:
- Rust crates on crates.io:
tree-sitter- A Rust binding to the core librarytree-sitter-highlight- The syntax-highlighting librarytree-sitter-cli- The command-line tool
- JavaScript modules on npmjs.com:
web-tree-sitter- A WASM-based JavaScript binding to the core librarytree-sitter-cli- The command-line tool
There are also several other dependent repositories that contain other published packages:
tree-sitter/node-tree-sitter- Node.js bindings to the core library, published astree-sitteron npmjs.comtree-sitter/py-tree-sitter- Python bindings to the core library, published astree-sitteron PyPI.org.
Publishing New Releases
Publishing a new release of the CLI requires these steps:
-
Commit and push all outstanding changes and verify that CI passes:
git commit -m "Fix things" git push -
Create a new tag:
script/version patchThis will determine the current version, increment the patch version number, and update the
Cargo.tomlandpackage.jsonfiles for the Rust and Node CLI packages. It will then create a commit and a tag for the new version. For more information about the arguments that are allowed, see the documentation for thenpm versioncommand. -
Push the commit and the tag:
git push git push --tags -
Wait for CI to pass. Because of the git tag, the CI jobs will publish artifacts to a GitHub release. The npm module of
tree-sitter-cliworks by downloading the appropriate binary from the corresponding GitHub release during installation. So it's best not to publish the npm package until the binaries are uploaded. -
Publish the npm package:
cd cli/npm npm publish