fix(query): include unresolved bare-name targets in references_to - #969
Open
nhuphuoc-bic wants to merge 1 commit into
Open
fix(query): include unresolved bare-name targets in references_to#969nhuphuoc-bic wants to merge 1 commit into
nhuphuoc-bic wants to merge 1 commit into
Conversation
A module that imports a symbol through a specifier the parser cannot resolve (npm workspace alias, tsconfig path mapping) gets a REFERENCES edge whose target is a bare name rather than "<file>::<Symbol>". references_to matched only fully-qualified targets, so those dependents were dropped without any signal — the caller reads the short result as proof that nothing else depends on the symbol. callers_of already carries the same fallback. Mirror it here, and merge bare-name edges only when the name identifies exactly one node so a name shared by two symbols is never attributed to both. Measured on a pnpm workspace monorepo: references_to for an interface returned 6 of 12 dependents, and 2 of 10 for another; the missing ones were all consumers importing across a package boundary.
Owner
|
Integrated on |
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.
Linked issue
No existing issue matched — I searched open and closed issues for
references_to, unresolved targets, and workspace aliases and found none. Happy to file one via the issue form if you'd prefer that first.What & why
references_toreturns only the dependents whose REFERENCES edge carries a fully-qualified target (<file>::<Symbol>).When a module imports a symbol through a specifier the parser cannot resolve — an npm/pnpm workspace alias such as
@core/ports, or a tsconfig path mapping — the edge is still recorded, but its target is stored as a bare name.references_tonever looks at those, so it drops the dependents silently. There is noconfidencenote on a non-empty result, so the short answer reads as a complete one.That failure mode is worse than an empty result: the caller gets a small, plausible number and concludes nothing else depends on the symbol.
Measured on a pnpm workspace monorepo (TypeScript,
apps/*+packages/*behind@core/*aliases):references_toIn both cases every missing dependent lived outside the defining package and imported through the alias. The edges were present in
graph.dbthe whole time, under the bare target name.callers_ofalready has exactly this fallback (theiter_edges_by_target_namepass that marks resultstarget_resolution: "unresolved"). This PR mirrors it forreferences_to, with one added guard: bare-name edges are merged only whencount_nodes_by_name(name) == 1, so a name shared by two symbols is never attributed to both. Edges carryingambiguous_targetsare skipped, as in the existing path.After the change the two queries above return 11 and 9 — the remainder in each case is the barrel
index.ts, which re-exports rather than references, so it legitimately produces no REFERENCES edge.How it was tested
The new test
test_references_to_includes_alias_imported_dependentsbuilds a fixture whose consumer imports through@core/ports, which the parser cannot resolve. Verified it is a real regression test: with thequery.pychange reverted it fails withassert 'usePort' in {}, and passes with the change applied.Checklist
uv run pytest tests/ --tb=short -qruff checkcleanmypyclean