Callers
callers
Caller/usage analysis via tree-sitter call-site detection.
Parses call-sites from tree-sitter AST to answer "who calls this
function?" — traversing call nodes to find every function/method
invocation across a package.
Example
from axm_ast.core.callers import find_callers results = find_callers(pkg, "greet") for r in results: ... print(f"{r.module}:{r.line} — {r.call_expression}")
extract_calls(mod, module_name=None)
Extract all function/method call-sites from a module.
Traverses the tree-sitter AST to find every call node
and extracts the called symbol name, location, and context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mod
|
ModuleInfo
|
Parsed module info (with path to source). |
required |
module_name
|
str | None
|
Dotted module name for CallSite.module. |
None
|
Returns:
| Type | Description |
|---|---|
list[CallSite]
|
List of CallSite objects for each call in the module. |
Source code in packages/axm-ast/src/axm_ast/core/callers.py
extract_references(mod)
Extract symbol names used as references (not direct calls).
Detects identifiers that appear as:
- Dict values: {"key": my_func}
- List elements: [func_a, func_b]
- Tuple elements: (func_a, func_b)
- Set elements: {func_a, func_b}
- Keyword arguments: DataLoader(collate_fn=my_func)
- Default parameters: def foo(callback=my_func)
This catches dynamic dispatch patterns where functions are stored in data structures, passed as keyword arguments, or used as default parameter values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mod
|
ModuleInfo
|
Parsed module info (with path to source). |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of symbol names referenced in non-call positions. |
Source code in packages/axm-ast/src/axm_ast/core/callers.py
find_callers(pkg, symbol)
Find all call-sites of a given symbol across a package.
Searches every module in the package for calls matching the given symbol name. Uses cached call-sites when available to avoid re-parsing files on repeated queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
symbol
|
str
|
Name of the function/method to search for. |
required |
Returns:
| Type | Description |
|---|---|
list[CallSite]
|
List of CallSite objects where the symbol is called. |
Example
results = find_callers(pkg, "greet") results[0].module 'cli'
Source code in packages/axm-ast/src/axm_ast/core/callers.py
find_callers_workspace(ws, symbol)
Find all call-sites of a symbol across a workspace.
Searches every package in the workspace for calls matching
the given symbol name. Module names are prefixed with
pkg_name:: for disambiguation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws
|
WorkspaceInfo
|
Analyzed workspace info. |
required |
symbol
|
str
|
Name of the function/method to search for. |
required |
Returns:
| Type | Description |
|---|---|
list[CallSite]
|
List of CallSite objects where the symbol is called. |
Example
results = find_callers_workspace(ws, "ToolResult") results[0].module 'axm_mcp::server'