GitHub

Symbols & References

Structural lookup is the exact, graph-shaped side of RCE Code. Instead of ranking text it answers precise questions about definitions and the edges between them: where is this symbol defined, who refers to it, who calls it, and what does it call. These come from tree-sitter extraction plus a heuristic resolver that links references back to the symbols they name.

Everything here is keyed off the symbols and refs tables. A Symbol is a definition (its name, qualified name, kind, file, line/column span, parent, and signature). A Reference is a call or import site, with the name it targets and — once resolved — the symbol id it points to plus a confidence.

By-name vs. resolved

The single most important distinction is whether a query works purely on names or on the resolved reference graph. Resolution is a best-effort, name-based heuristic — not a type checker — so resolved queries are higher precision but only cover references the resolver was confident about.

  • find_references(name) — every reference whose target name matches, resolved or not. Broadest recall; finds all the call/import sites that mention a name.
  • get_references_from(symbol_id) — outgoing references that originate inside a symbol's body, by name. These may be unresolved (the target symbol id can be None).
  • get_references(symbol_id) — incoming references that the resolver linked to this symbol. Resolved only; these are the confident inbound edges.
  • get_callers(symbol_id) / get_callees(symbol_id) — the resolved call graph. Callers are symbols whose body contains a resolved reference to this symbol; callees are symbols this one resolves a reference to. Both return Symbols, not References.

Resolution confidence

The resolver writes a resolution_confidence on each reference. A target found in the same file scores 0.9; a target that is unique across the project scores 0.5; an ambiguous name with several candidate definitions is left unresolved (target id NULL). The resolved-graph queries — get_references, get_callers, get_callees — only see edges where a target was assigned.

Finding definitions

Several methods locate Symbol definitions. find_symbol(name, kind=None) returns every definition with that exact name, optionally filtered by SymbolKind (e.g. FUNCTION, CLASS, METHOD). get_definitions(file) lists every definition in a file in source order. get_definition_at(file, line, col) returns the innermost symbol whose span contains a position (column is 0-indexed), and get_symbols_in_chunk(chunk_id) returns the definitions that belong to a given chunk — handy for bridging a search hit back to its symbols.

definitions.py
from rce.code import CodeEngine
from rce.code.types import SymbolKind
engine = CodeEngine.open_or_create("/path/to/repo")
engine.index()
# every definition named "authenticate"
for sym in engine.find_symbol("authenticate"):
print(sym.kind, sym.qualified_name, f"{sym.file_path}:{sym.start_line}")
# only the class definitions named "Session"
classes = engine.find_symbol("Session", kind=SymbolKind.CLASS)
# all definitions in one file, in source order
for sym in engine.get_definitions("src/auth/session.py"):
print(sym.start_line, sym.kind, sym.qualified_name)
# the innermost symbol at a cursor position (col is 0-indexed)
here = engine.get_definition_at("src/auth/session.py", 42, 8)
engine.close()

Walking the reference graph

With a symbol's id you can traverse edges in both directions. The example below finds a function, lists who calls it and what it calls, and shows the difference between by-name and resolved reference queries.

graph.py
(sym,) = engine.find_symbol("charge_card") # assume a single match
# resolved call graph (returns Symbols)
callers = engine.get_callers(sym.id) # who calls charge_card
callees = engine.get_callees(sym.id) # what charge_card calls
# resolved incoming references (returns References linked to this symbol)
incoming = engine.get_references(sym.id)
# outgoing references by name from this symbol's body (may be unresolved)
outgoing = engine.get_references_from(sym.id)
for ref in outgoing:
status = "resolved" if ref.to_symbol_id is not None else "unresolved"
print(ref.to_name, status, round(ref.resolution_confidence, 2))
# every reference site that names "charge_card", regardless of resolution
all_sites = engine.find_references("charge_card")
# imports only
imports = engine.find_references("requests", is_import=True)

Query-to-method map

You want…Python methodCLI command
Definitions in a fileengine.get_definitions(file)rce-code symbols <file>
Definitions by name (anywhere)engine.find_symbol(name)rce-code find <name>
Definition at a positionengine.get_definition_at(file, line, col)Python only
Definitions in a chunkengine.get_symbols_in_chunk(chunk_id)Python only
All references to a name (any resolution)engine.find_references(name)rce-code refs <name>
Outgoing refs from a symbol (by name)engine.get_references_from(symbol_id)Python only
Resolved incoming refs to a symbolengine.get_references(symbol_id)Python only
Resolved callers of a symbolengine.get_callers(symbol_id)rce-code callers <name>
Resolved callees of a symbolengine.get_callees(symbol_id)rce-code callees <name>

The CLI resolves names for you

The Python call-graph and reference methods take a numeric symbol_id. The CLI's callers and callees commands take a name: they call find_symbol first and then walk the graph for each matching symbol, so a name with several definitions reports edges for all of them.

CLI

terminal
# list every definition in a file (line, kind, qualified name)
rce-code symbols src/auth/session.py
# find definitions named "authenticate" across the repo
rce-code find authenticate
# references to a name (calls + imports; unresolved included)
rce-code refs charge_card
rce-code refs requests --imports # only import references
# resolved call graph by name
rce-code callers charge_card
rce-code callees charge_card

Pair with hybrid search

Use hybrid or lexical search to discover a symbol when you only half-remember its name, then switch to these exact structural methods to pin down its definition and trace its call graph.