Repository navigation
Conversation
…l nodes Fixes DeusData#546 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
|
Huge thanks for opening this PR and for the work you put into it. The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime. |
|
Thanks, this is nicely focused. Since it changes |
|
Thank you @mvanhorn — this is a genuinely sharp piece of work, and your diagnosis of #546 is exactly right (a Two things happened in parallel. First, #546's under-report was independently fixed on Second — and this is the valuable part — reviewing your PR surfaced that the shipped fix has a real flaw your approach avoids: I've distilled exactly that into #748 ( Closing this as superseded by the distilled follow-up, with full credit to you. The separate #546 issue is being closed as already-fixed by |
The DeusData#546 fix (bfs_union_same_name) BFSs from every graph node sharing the resolved name and merges the results, so a symbol split across a real implementation and a body-less ambient .d.ts stub reports a complete caller set. But pick_resolved_node flagged ambiguity only on an exact score tie, and node_resolution_score adds the body span, so two genuinely-DIFFERENT functions that share a name but differ in body length score differently, dodge the tie, and get their caller sets unioned into one confidently-conflated answer -- the mirror of the DeusData#546 under-report. Complete the ambiguity rule: two or more *real* callable definitions sharing a name (callable label + non-empty body span) are ambiguous and routed to the existing disambiguation (snippet_suggestions) path. A body-less span==start node is an ambient declaration / signature stub -- a fragment of one logical symbol -- so a real implementation plus its .d.ts stub stays non-ambiguous and still unions, preserving the DeusData#546 behavior. Reproduce-first: tool_trace_call_path_distinct_defs_not_over_unioned (two unrelated same-named functions with different spans -> merged caller set on the old code = RED; ambiguous on the fix = GREEN) plus tool_trace_call_path_dts_stub_unions_with_impl guarding that the stub+impl union still works. Full suite green. Distilled from DeusData#650 (thanks @mvanhorn); its trace_-prefixed reimplementation collided with main's already-landed bfs_union_same_name and could not merge. Refs DeusData#546, DeusData#650 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com> Co-Authored-By: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
What does this PR do?
Root cause is in the
trace_pathhandler insrc/mcp/mcp.c:cbm_store_find_nodes_by_namereturns all same-named nodes, thenpick_resolved_nodeselects exactly one (sel) vianode_resolution_score= label_rank*weight + (end_line - start_line). A body-less.d.tsdeclaration has span 0, so it always scores below the real implementation, loses the pick, is NOT flagged as a tie, and its callers are dropped — BFS runs only fromnodes[sel].id. Fix per the issue's option 2 ("union nodes that share name + signature"): afterpick_resolved_nodechooses the canonical node, gather the sibling node ids that represent the same logical symbol — samename, callable label (Function/Method), and body-less span (start_line == end_line, the ambient-declaration signal) — and run the inbound/outbound BFS from each, mergingcbm_traverse_result_tsets deduplicated by node id before serialization.When an exported symbol is defined in real source AND re-declared (signature only, no body) in an ambient
.d.tsfile, the indexer creates two distinct callable nodes for the same logical symbol.CALLSedges from consumers get partitioned across the two nodes by import style: consumers importing via thetsconfigpath alias point at the.d.tsstub node, consumers importing via the relative path point at the implementation node.trace_path(function_name, mode=calls)then resolves the name to a single node and returns only that node's callers, silently omitting the rest. Reverse-dependency / blast-radius analysis (the tool's core use case) thus returns a confidently partial answer with no warning.Fixes #546
Checklist
git commit -s) — required, CI rejectsmake -f Makefile.cbm test)make -f Makefile.cbm lint-ci)