fix(exports): discriminate file-level from symbol-level consumer entries#1974
Open
carlos-alm wants to merge 1 commit into
Conversation
consumers[] entries returned by exportsData (codegraph exports CLI, file_exports MCP tool) conflated two different shapes: a real caller (calls edge, source = function/method/class node) and a whole-file import-type reference (imports-type edge, source = the importing file node itself, line fixed at 0). Renderers had no way to tell them apart, so a type-only import rendered as if it were a real call-site, e.g. "consumer.ts (consumer.ts:0)". Add a consumerKind: 'file' | 'symbol' discriminator derived from the consumer's source node kind, and update the CLI renderer to print file-level entries as "<file> (type-only import)" instead of a fabricated call-site line.
Contributor
Greptile SummaryThis PR separates file-level type imports from real symbol consumers in export reporting. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(exports): discriminate file-level fr..." | Re-trigger Greptile |
Contributor
Codegraph Impact Analysis11 functions changed → 9 callers affected across 3 files
|
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.
Summary
consumers[]entries returned byexportsData(used by thecodegraph exportsCLI and thefile_exportsMCP tool) conflated two different shapes under one struct:callsedge — source is a function/method/class node,lineis a genuine call-site), andimport type { X }reference (imports-typeedge — source is the importing file node itself,lineis always0since there's no calling symbol).Renderers had no way to distinguish them, so a type-only import showed up looking like a real call-site, e.g.
consumer.ts (consumer.ts:0)instead ofsomeFunction (consumer.ts:42).Deferred from #1814's review (originally raised by Greptile), tracked as #1830.
Fix
src/domain/analysis/exports.ts—exportsData's consumer query now also selects the source node'skind; eachconsumers[]entry gets aconsumerKind: 'file' | 'symbol'discriminator derived from it.src/types.ts— addedFileExportConsumerdocumenting the two shapes;FileExportEntry.consumersnow uses it.src/presentation/queries-cli/exports.ts—codegraph exportsnow renders file-level entries as<file> (type-only import)instead of fabricating a:0call-site line.docs/examples/MCP.md— documented the newconsumerKindfield forfile_exports.Tests
tests/integration/exports.test.ts— asserts real callers getconsumerKind: 'symbol'; the existingimport typeregression (codegraph exports/dead-role consumer counting ignores type-only (import type) usages #1724) now also assertsconsumerKind: 'file'.tests/presentation/queries-cli.test.ts— new case asserting the CLI rendersconsumer.ts (type-only import)and never a fabricatedconsumer.ts:0.Out of scope
Filed #1973: the same
imports-type/callsconflation exists incheckNoDeletedExportsInUse(src/features/check.ts/src/presentation/check.ts), a separate CI-predicate output surface — left for a follow-up PR.Fixes #1830
Test plan
npx vitest run tests/integration/exports.test.ts tests/presentation/queries-cli.test.ts— passnpm test— full suite green (228 test files, 3763 passed, 30 skipped, 2 todo)npm run lint/npx tsc --noEmit— cleancodegraph diff-impact --staged -T— impact confined toexports.tsand its direct callers, as expected