#tree-sitter #stack-graphs #typescript

bin+lib tree-sitter-stack-graphs-typescript

Stack graphs definition for TypeScript using tree-sitter-typescript

1 unstable release

0.1.0 Feb 8, 2023

#2 in #stack-graphs

MIT/Apache

79KB
2K SLoC

TypeScript 1K SLoC // 0.4% comments Rust 694 SLoC // 0.1% comments GNU Style Assembly 8 SLoC // 0.5% comments

tree-sitter-stack-graphs definition for TypeScript

This project defines tree-sitter-stack-graphs rules for TypeScript using the tree-sitter-typescript grammar.

Usage

To use this library, add the following to your Cargo.toml:

[dependencies]
tree-sitter-stack-graphs-typescript = "0.1"

Check out our documentation for more details on how to use this library.

Command-line Program

The command-line program for tree-sitter-stack-graphs-typescript lets you do stack graph based analysis and lookup from the command line.

Install the program using cargo install as follows:

$ cargo install --features cli tree-sitter-stack-graphs-typescript
$ tree-sitter-stack-graphs-typescript --help

Development

The project is written in Rust, and requires a recent version installed. Rust can be installed and updated using rustup.

The project is organized as follows:

  • The stack graph rules are defined in src/stack-graphs.tsg.
  • Builtins sources and configuration are defined in src/builtins.ts and builtins.cfg respectively.
  • Tests are put into the test directory.

Build the project by running:

$ cargo build

Run the tests as follows:

$ cargo test

The project consists of a library and a CLI. By default, running cargo only applies to the library. To run cargo commands on the CLI as well, add --features cli or --all-features.

Run the CLI from source as follows:

$ cargo run --features cli -- ARGS

Sources are formatted using the standard Rust formatted, which is applied by running:

$ cargo fmt

The stack graph rules are written in tree-sitter-graph, which provides a VSCode extension for syntax highlighting.

Parse and test a single file by executing the following commands:

$ cargo run --features cli -- parse FILES...
$ cargo run --features cli -- test TESTFILES...

Additional flags can be passed to these commands as well. For example, to generate a visualization for the test, execute:

$ cargo run --features cli -- test -V TESTFILES...

To generate the visualization regardless of test outcome, execute:

$ cargo run --features cli -- test -V --output-mode=always TESTFILES...

Go to https://crates.io/crates/tree-sitter-stack-graphs for links to examples and documentation.

Dependencies

~27MB
~690K SLoC