|
1 | 1 | # tree-sitter-stack-graphs definition for TypeScript |
2 | 2 |
|
3 | | -This project defines tree-sitter-stack-graphs rules for TypeScript using the [tree-sitter-typescript](https://www.npmjs.com/package/tree-sitter-typescript) grammar. |
| 3 | +This project defines tree-sitter-stack-graphs rules for TypeScript using the [tree-sitter-typescript][] grammar. |
| 4 | + |
| 5 | +[tree-sitter-typescript]: https://crates.io/crates/tree-sitter-typescript |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +To use this library, add the following to your `Cargo.toml`: |
| 10 | + |
| 11 | +``` toml |
| 12 | +[dependencies] |
| 13 | +tree-sitter-stack-graphs-typescript = "0.1" |
| 14 | +``` |
| 15 | + |
| 16 | +Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs-typescript/*/) for |
| 17 | +more details on how to use this library. |
| 18 | + |
| 19 | +## Command-line Program |
| 20 | + |
| 21 | +The command-line program for `tree-sitter-stack-graphs-typescript` lets you do |
| 22 | +stack graph based analysis and lookup from the command line. |
| 23 | + |
| 24 | +Install the program using `cargo install` as follows: |
| 25 | + |
| 26 | +``` sh |
| 27 | +$ cargo install --features cli tree-sitter-stack-graphs-typescript |
| 28 | +$ tree-sitter-stack-graphs-typescript --help |
| 29 | +``` |
4 | 30 |
|
5 | 31 | ## Development |
6 | 32 |
|
| 33 | +The project is written in Rust, and requires a recent version installed. |
| 34 | +Rust can be installed and updated using [rustup][]. |
| 35 | + |
| 36 | +[rustup]: https://rustup.rs/ |
| 37 | + |
| 38 | + |
7 | 39 | The project is organized as follows: |
8 | 40 |
|
9 | 41 | - The stack graph rules are defined in `src/stack-graphs.tsg`. |
10 | 42 | - Builtins sources and configuration are defined in `src/builtins.ts` and `builtins.cfg` respectively. |
11 | 43 | - Tests are put into the `test` directory. |
12 | 44 |
|
13 | | -Make sure all development dependencies are installed by running: |
| 45 | +Build the project by running: |
14 | 46 |
|
15 | | - npm install |
| 47 | +``` sh |
| 48 | +$ cargo build |
| 49 | +``` |
16 | 50 |
|
17 | | -Run all tests in the project by executing the following: |
| 51 | +Run the tests as follows: |
18 | 52 |
|
19 | | - npm test |
| 53 | +``` sh |
| 54 | +$ cargo test |
| 55 | +``` |
20 | 56 |
|
21 | | -Parse and test a single file by executing the following commands: |
| 57 | +The project consists of a library and a CLI. |
| 58 | +By default, running `cargo` only applies to the library. |
| 59 | +To run `cargo` commands on the CLI as well, add `--features cli` or `--all-features`. |
22 | 60 |
|
23 | | - npm run parse-file test/test.ts |
24 | | - npm run test-file test/test.ts |
| 61 | +Run the CLI from source as follows: |
25 | 62 |
|
26 | | -Additional flags can be passed to these commands as well. For example, to generate a visualization for the test, execute: |
| 63 | +``` sh |
| 64 | +$ cargo run --features cli -- ARGS |
| 65 | +``` |
27 | 66 |
|
28 | | - npm run test-file -- -V test/test.ts |
| 67 | +Sources are formatted using the standard Rust formatted, which is applied by running: |
29 | 68 |
|
30 | | -To generate the visualization regardless of test outcome, execute: |
| 69 | +``` sh |
| 70 | +$ cargo fmt |
| 71 | +``` |
| 72 | + |
| 73 | +The stack graph rules are written in [tree-sitter-graph][], which provides a VSCode |
| 74 | +extension for syntax highlighting. |
| 75 | + |
| 76 | +[tree-sitter-graph]: https://github.com/tree-sitter/tree-sitter-graph |
31 | 77 |
|
32 | | - npm run test-file -- -V --output-mode=always test/test.ts |
| 78 | +Parse and test a single file by executing the following commands: |
| 79 | + |
| 80 | +``` sh |
| 81 | +$ cargo run -- parse FILES... |
| 82 | +$ cargo run -- test TESTFILES... |
| 83 | +``` |
| 84 | + |
| 85 | +Additional flags can be passed to these commands as well. For example, to generate |
| 86 | +a visualization for the test, execute: |
33 | 87 |
|
34 | | -These commands should be enough for regular development. If necessary, the `tree-sitter-stack-graphs` command can be invoked directly as well, by executing: |
| 88 | +``` sh |
| 89 | +$ cargo run -- test -V TESTFILES... |
| 90 | +``` |
| 91 | + |
| 92 | +To generate the visualization regardless of test outcome, execute: |
35 | 93 |
|
36 | | - npx tree-sitter-stack-graphs |
| 94 | +``` sh |
| 95 | +$ cargo run -- test -V --output-mode=always TESTFILES... |
| 96 | +``` |
37 | 97 |
|
38 | 98 | Go to https://crates.io/crates/tree-sitter-stack-graphs for links to examples and documentation. |
0 commit comments