treequery
is a CLI for executing Tree-sitter queries on source code files.
It uses enry
to detect a language and apply the right Tree-sitter parser.
The default output includes a list of line number locations where there's a query match, followed by a snippet of the matching code.
It will eventually be integrated into askgit
.
Install with homebrew:
brew tap askgitdev/treequery
brew install treequery
Or by running make
in the root of this repo, which will produce a tq
binary.
> tq testdata/TriestBase.java "(method_declaration name: (identifier) @method_name)"
./treequery/testdata/TriestBase.java:20
handleEdge
./treequery/testdata/TriestBase.java:48
swapIn
./treequery/testdata/TriestBase.java:53
addEdge
./treequery/testdata/TriestBase.java:88
removeEdge
./treequery/testdata/TriestBase.java:119
getEstimate
The above example shows a way to select all method names in the testdata/TriestBase.java
file.
To exclude file names and line locations, use the -q
(quiet) flag:
handleEdge
swapIn
addEdge
removeEdge
getEstimate
- bash
- c
- cpp
- csharp
- css
- elm
- golang
- html
- java
- javascript
- lua
- ocaml
- php
- python
- ruby
- rust
- scala
- svelte
- toml
- typescript
- yaml