fix: trace_path returns full caller set across .d.ts-duplicated symbol nodes#650
Open
mvanhorn wants to merge 1 commit into
Open
fix: trace_path returns full caller set across .d.ts-duplicated symbol nodes#650mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
…l nodes Fixes DeusData#546 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)