Skip to content

feat(symbols): bind TypeScript references with the engine's checker - #487

Merged
byronwall merged 13 commits into
mainfrom
claude/checker-symbol-index-plan
Nov 28, 2026
Merged

byronwall merged 13 commits into
mainfrom
claude/checker-symbol-index-plan

Conversation

@byronwall

@byronwall byronwall commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

srcly refs, Symbols mode and Show references now bind TypeScript names with the data-flow engine's TypeScript checker, not by name. Member calls through parameters, props, inferred and union receivers now reach their methods and fields. Name guesses that pointed at the wrong symbol are gone. Show references in the code viewer opens the symbol bound at the caret, not the first search hit.

What you'll see

  • srcly refs and the Symbols status line say which binder ran: "bound by the TypeScript checker", or "bound by tree-sitter names (reason)" when Node, the engine or a tsconfig is missing.
  • More callers. On explorEDA, SavedDataStructure goes from 189 to 252 references; most of the new ones are member reads through types tree-sitter could not see.
  • Show references on a use of a name that is both a type and a value opens the side that position uses. On a name the checker binds to nothing, it says so ("No symbol is bound to …").
  • Ids do not change. Tree-sitter still makes every declaration and id (file#Name, file#Class.member, file#Name@type), so links, at= and the Imports graph are the same.

How it works

  • A new engine op, symbolRefs, walks every identifier and reports the declaration the checker binds it to: its file, name, name position and meaning (value or type). Python joins that to the tree-sitter symbol whose name is at the same position. An unbound name stays out of the graph, counted by reason.
  • Engine details:
    • A tsconfig that resolves modules differently from the primary one (paths, baseUrl, moduleResolution, conditions) gets its own Program.
    • A workspace package imported through its built .d.ts is followed to its source: through the declaration map, else dist/x.d.ts → src/x.ts.
    • A union's member counts once for each member type that declares it.
  • Fallback: with no Node, no engine, no tsconfig, or a Python-only root, the index is today's tree-sitter index with the reason. Python files, and files outside the engine's Program (tests), keep tree-sitter references.
  • The Symbols routes and srcly refs start the engine. Nothing else does, so the base scan is unchanged.

Proof

Show references on Row in export let typed: import("./m").Row: the focus is Row@type, referenced by typed (line 8) and by the JSX type argument in tag (line 9). #486 missed that JSX type argument. The typeof use opens the value instead (second e2e case).

Show references by position lands on Row@type

Every TypeScript reference in two repos, both binders. cd server && SRCLY_ENGINE_DEV=1 uv run python scripts/compare_binders.py <root>. A reference is (source file, line, target id).

Repo Tree-sitter refs Checker refs Agree Mismatched ids
srcly (this branch) 40,736 61,653 39,141 (96.1%) 11
explorEDA f44a5c63 49,092 85,223 47,451 (96.7%) 3
  • The checker adds member references through receivers tree-sitter cannot type (35,343 read → type on explorEDA), calls through re-exports and closures, and interface method calls.
  • What tree-sitter alone has is mostly guesses the checker refuses. One example is a TS call bound by name to the Python method BodyWalker.literal. Others are JSX tags (<span>, <line>) bound to locals of the same name.
  • Mismatched ids are declare function declarations (the index keeps no symbol for them), untracked engine/tmp output, and one tree-sitter parse gap in explorEDA's FieldListRow.tsx.
  • The buckets and the spot checks are in docs/intent/checker-symbol-index/README.md ("Proof result").

srcly refs on the #486 cases:

AnalysisSourceRow: 1 declaration · bound by the TypeScript checker
## packages/explorEDA/src/types/AnalysisProject.ts:6 · type AnalysisSourceRow (exported)
84 references from 60 symbols        (same as #486, analysisWorker.ts included)

EvidenceCollector: 2 declarations · bound by the TypeScript checker
## engine/src/analysis/program-evidence.ts:325 · variable EvidenceCollector (exported)
2 references from 1 symbol: collectProgramEvidence · instantiate exact
## engine/src/analysis/program-evidence.ts:326 · type EvidenceCollector@type (exported)
No references.

Cost of symbolRefs, one cold run each. Command: cd engine && node --expose-gc --max-old-space-size=4096 --import tsx scripts/symbol-refs-probe.ts --root <repo>. Heap is measured after a full GC; development Mac.

Root Build Walk Heap after JSON
srcly 2.1 s 4.1 s 783 MB 18.5 MB
visual-notes 3.4 s 5.0 s 1,051 MB 6 MB
explorEDA (two extra Programs for its apps) 3.0 s 10.8 s 1,389 MB 21 MB

These were measured before the round-2 and round-3 fixes, which add a union walk and clause names. The final compare_binders runs took 21 s (srcly) and 18 s (explorEDA) for the whole checker index, including Python's join.

Tests:

Survey moves: corpus edits only, with no analysis change. This PR adds new server and client code (server/app/services/symbols/checker.py, index.py, models.py, the symbols router; CodeModal.tsx, SymbolsView.tsx, symbols/api.ts). The sampled server traces move by +3 traces, +3 partial, +2 budget-exhausted stops and +92 external-code stops. Client and value-flow-basics do not move.

Review

Codex ran three rounds (gpt-6.2-sol). Round 3 ended with no P0.

  • Round 1 (7 P1, 3 P2): all fixed. Changes:

    • The join matches the declaration name, not the body.
    • Show references sends the identifier's first column.
    • Built .d.ts files map by path.
    • Every module-resolution option is routed.
    • implements and interface extends bind the type side.
    • x["run"]() is a reference.
    • The cache checks the engine's program hash.
    • export default () => … is file#default.
    • A member id passes through Show references.
  • Round 2 (8 P1, 2 P2): all fixed. Changes:

    • The join is exact by column.
    • A union keeps every member.
    • Import and export clause names and recursive calls are positions, not edges.
    • A covered class takes its bases from checker edges.
    • Config edits refresh the engine.
    • baseUrl precedence.
    • Declaration maps.
    • satisfies.
    • The fixture is tracked.
  • Round 3 (9 P1, 2 P2): fixed after the round, without a further review:

    • The fixture's lint.
    • Anonymous default functions.
    • A union with an external member first.
    • Python position lookups.
    • Type-only clauses.
    • Windows path spelling.
    • Module-level sources.
    • A refresh on any source change.
    • A declaration map's sourceRoot.

    The rest are listed below.

  • Round 3 architecture note: build the checker index as one project-aware snapshot. TypeScript would supply project ownership, declaration identity and enclosing declarations, and both graph edges and Show references would come from the same records. This PR is close to that, except for project ownership (the first open finding).

  • Close step: it asked only for tests. Most are in the two fixtures and the join tests. The cross-project ones (an app alone compared with the monorepo) are not added.

Limits

  • Files outside the engine's Program (tests, configs) keep tree-sitter references. Their callers are still listed, with tree-sitter's quality.
  • The Symbols view waits for the engine on first use (about 5 to 20 s on a big repo). It does not show the tree-sitter answer first.
  • A union member's call adds one reference per member type, so read → type counts grow on union-heavy code.

Open findings

  • P1 · diff · engine/src/srcly/ops/symbol-refs.ts:101 — A non-solution root tsconfig that includes an app's files hides the app's own tsconfig, so the app's ~/x alias binds through the root's paths. Open: needs per-file config ownership in the engine's tsconfig discovery, which every op shares.
  • P1 · diff · engine/src/srcly/ops/symbol-refs.ts:176 — A built .d.ts with no declaration map maps by the dist → src convention, so a same-named export in an unrelated src/x.ts can take the caller. Declined for now: without the convention, explorEDA's app → package callers disappear, and tree-sitter's Imports graph makes the same guess.
  • P2 · diff · server/app/services/symbols/checker.py:70 — After the registry records an engine crash, Symbols stays on tree-sitter until the failure clears. Open: needs a retry policy that does not restart a crashing engine on every search.
  • P2 · base · server/app/services/findings/listing.py:54 — A mixed-language ast-grep pack reports 0, not N/A, for a filtered rule that checked no files. Pre-existing: from feat(cli): srcly findings lists findings by rule with a count #485.

🤖 Generated with Claude Code

byronwall and others added 8 commits November 28, 2026 00:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… to tree-sitter ids

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecker after a passing failure

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall
byronwall force-pushed the claude/checker-symbol-index-plan branch from 1a99821 to 0dfc8a4 Compare November 28, 2026 05:28
byronwall and others added 2 commits November 28, 2026 00:38
…e every resolution option

Codex round 1: join a declaration by the line of its name, not its body; Show references
sends the identifier's first column and matches a declaration at its name; a workspace
package's built .d.ts follows its own path to src and the export path there (namespace and
member uses too); a config that resolves modules differently binds in its own Program;
implements and an interface's extends bind the type side; x["run"]() is a reference;
a cached checker index holds only while the engine's program hash matches; an anonymous
export default function is file#default; a member id passes through Show references.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lause names, track configs

Codex round 2: the checker sends each target's name column and the join matches it exactly;
a union's member binds every class's own member; import and export clause names and
recursive calls are positions for Show references, not edges; a checked class takes its
bases from checker extends edges only; config edits join the cache key and refresh the
engine, and a cached fallback holds only while the engine is still missing; baseUrl wins
over an inherited paths base; a declaration map beats the dist→src convention; satisfies
keeps a callee a call; the workspace fixture is tracked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall
byronwall enabled auto-merge (squash) November 28, 2026 06:00
byronwall and others added 2 commits November 28, 2026 01:03
…efault anchors, Python lookups

Codex round 3: a type-only import or export clause names the type side; a reference with
no enclosing declaration is module code; a union keeps its local members when an external
one comes first; an anonymous default function anchors after 'default' in both binders;
Python files keep tree-sitter's position lookup in a checker index; file names compare in
TypeScript's '/' spelling; the workspace fixture's imports come first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall byronwall changed the title docs: plan a checker-bound TypeScript symbol index feat(symbols): bind TypeScript references with the engine's checker Nov 28, 2026
…ration map's sourceRoot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant