tree-sitter-queries
Skill4 starsChanged 5 months agoMITView on GitHub
Use when working on tree-sitter extraction — any task touching queries/**/*.scm or tags.scm files, adding language support, fixing missing or wrong symbols in the map, writing snapshot tests for queries, or looking up grammar node names.
In this repository8 other files it gives its agents.
- examples/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adr-writingSkill
- benchmark-protocolSkill
- release-processSkill
- atlas-orientSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Every pattern has a two-level shape:
- Distinctive: line 32
Never guess. In order of convenience:
- Very specific: line 41
Add or extend a construct in tests/queries/fixtures/<lang>.<ext> that exercises exactly what you changed.
- Very specific: line 42
Add or update a test named query_* in tests/queries/ (the query_ prefix is what the post-edit hook runs on .scm edits).
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing tree-sitter extraction queries for atlas
Anatomy of a tags.scm
Each queries/<lang>/tags.scm is a tree-sitter query file: S-expression patterns matched against the parse tree, with @capture names marking what to extract. Patterns are independent — a node can match several. The files are embedded at compile time via include_str! in src/lang/<lang>.rs, so an .scm edit requires a recompile to take effect (the query tests do this for you).
Every pattern has a two-level shape:
(declaration_node
name: (identifier_node) @name) @definition.kindThe outer capture (@definition.* / @reference.*) marks the whole node — its source span becomes the signature text. The inner @name marks the identifier. Both are required: a definition without @name is dropped by src/parse.rs.
The capture-name contract (what src/parse.rs expects)
@definition.<kind>where<kind>∈function,method,class,interface,enum,type,constant,module. Cross-language normalization: Ruststruct→class,trait→interface.@reference.call— call site; becomes a caller → callee graph edge.@reference.import— import; becomes a file → file graph edge.@name— the identifier inside the enclosing capture.
Any other capture name is silently ignored — the contract test (cargo test query_) rejects unknown names so this fails loudly instead.
Finding node names
Never guess. In order of convenience:
cargo run --example dump-ast path/to/file.py— prints the named AST for any source file (wired in M0).- The grammar crate's
node-types.json(vendored source under~/.cargo/registry/src/). - The tree-sitter playground (https://tree-sitter.github.io/tree-sitter/playground) for interactive experimenting.
- Aider's published query files — the reference baseline (PRD §10), but our capture contract differs; translate, don't paste.
Snapshot-test workflow (required for every query change)
- Add or extend a construct in
tests/queries/fixtures/<lang>.<ext>that exercises exactly what you changed. - Add or update a test named
query_*intests/queries/(thequery_prefix is what the post-edit hook runs on .scm edits). cargo test query_— green before you report done. The hook re-runs this automatically whenever aqueries/**/*.scmfile is edited.
Worked example: Python functions, classes, imports
; Functions (module-level and nested; `async def` shares this node kind).
(function_definition
name: (identifier) @name) @definition.function
; Methods: a function_definition directly inside a class body — matched
; separately so parse.rs can qualify the name as Class.method.
(class_definition
body: (block
(function_definition
name: (identifier) @name) @definition.method))
; Decorated definitions: tree-sitter wraps the def in decorated_definition,
; so a bare (function_definition) pattern still matches the inner node, but
; capturing through the wrapper keeps the decorator in the signature span.
(decorated_definition
definition: (function_definition
name: (identifier) @name) @definition.function)
; Classes.
(class_definition
name: (identifier) @name) @definition.class
; Imports: both forms. The captured @name is the module path — link.rs
; resolves it to a file, best-effort.
(import_statement
name: (dotted_name) @name) @reference.import
(import_from_statement
module_name: (dotted_name) @name) @reference.import
; Call sites: bare calls and attribute calls (obj.method(...)).
(call
function: (identifier) @name) @reference.call
(call
function: (attribute
attribute: (identifier) @name)) @reference.callThe live version of this is queries/python/tags.scm; its fixture is tests/queries/fixtures/python.py.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

