12 releases (breaking)

0.9.0 Jul 10, 2024
0.8.1 Mar 6, 2024
0.7.1 Jul 27, 2023
0.6.0 Jan 13, 2023
0.2.0 Jun 29, 2022

#415 in Text processing

Download history 85/week @ 2024-07-22 119/week @ 2024-07-29 101/week @ 2024-08-05 143/week @ 2024-08-12 109/week @ 2024-08-19 66/week @ 2024-08-26 42/week @ 2024-09-02 64/week @ 2024-09-09 941/week @ 2024-09-16 440/week @ 2024-09-23 82/week @ 2024-09-30 109/week @ 2024-10-07 101/week @ 2024-10-14 114/week @ 2024-10-21 83/week @ 2024-10-28 65/week @ 2024-11-04

367 downloads per month
Used in 5 crates

MIT/Apache

1MB
17K SLoC

tree-sitter-stack-graphs

The tree-sitter-stack-graphs crate lets you create stack graphs using the tree-sitter grammar for a language.

Using the API

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

[dependencies]
tree-sitter-stack-graphs = "0.9"

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

Using the Command-line Program

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

The CLI can be run as follows:

  1. (Installed) Install the CLI using Cargo as follows:

    cargo install --features cli tree-sitter-stack-graphs
    

    After this, the CLI should be available as tree-sitter-stack-graphs.

  2. (From source) Instead of installing the CLI, it can also be run directly from the crate directory, as a replacement for a tree-sitter-stack-graphs invocation, as follows:

    cargo run --features cli --
    

The basic CLI workflow for the command-line program is to index source code and issue queries against the resulting database:

  1. Index a source folder as follows:

    tree-sitter-stack-graphs index SOURCE_DIR
    

    Indexing will skip any files that have already be indexed. To force a re-index, add the -f flag.

    To check the status if a source folder, run:

    tree-sitter-stack-graphs status SOURCE_DIR
    

    To clean the database and start with a clean slate, run:

    tree-sitter-stack-graphs clean
    

    Pass the --delete flag to not just empty the database, but also delete it. This is useful to resolve unsupported database version errors that may occur after a version update.

  2. Run a query to find the definition(s) for a reference on a given line and column, run:

    tree-sitter-stack-graphs query definition SOURCE_PATH:LINE:COLUMN
    

    Resulting definitions are printed, including a source line if the source file is available.

Discover all available commands and flags by passing the -h flag to the CLI directly, or to any of the subcommands.

Getting Started on a new Language

Starting a new project to develop stack graph definitions for your favourite language is as easy as running the init command:

tree-sitter-stack-graphs init PROJECT_DIR

Answer the questions to provide information about the language, the grammar dependency, and the project and hit Generate to generate the new project. Check out PROJECT_DIR/README.md to find out how to start developing.

Check out examples of stack graph rules for typical language features.

Development

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

Build the project by running:

cargo build

Run the tests by running:

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

License

Licensed under either of

at your option.

Dependencies

~8–24MB
~361K SLoC