Skip to content

fix(exports): discriminate file-level from symbol-level consumer entries#1974

Open
carlos-alm wants to merge 1 commit into
fix/issue-1827-native-build-pipeline-silently-swallows-edgefrom
fix/issue-1830-follow-up-document-or-discriminate-file-level
Open

fix(exports): discriminate file-level from symbol-level consumer entries#1974
carlos-alm wants to merge 1 commit into
fix/issue-1827-native-build-pipeline-silently-swallows-edgefrom
fix/issue-1830-follow-up-document-or-discriminate-file-level

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

consumers[] entries returned by exportsData (used by the codegraph exports CLI and the file_exports MCP tool) conflated two different shapes under one struct:

  • a real caller (calls edge — source is a function/method/class node, line is a genuine call-site), and
  • a whole-file import type { X } reference (imports-type edge — source is the importing file node itself, line is always 0 since 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 of someFunction (consumer.ts:42).

Deferred from #1814's review (originally raised by Greptile), tracked as #1830.

Fix

  • src/domain/analysis/exports.tsexportsData's consumer query now also selects the source node's kind; each consumers[] entry gets a consumerKind: 'file' | 'symbol' discriminator derived from it.
  • src/types.ts — added FileExportConsumer documenting the two shapes; FileExportEntry.consumers now uses it.
  • src/presentation/queries-cli/exports.tscodegraph exports now renders file-level entries as <file> (type-only import) instead of fabricating a :0 call-site line.
  • docs/examples/MCP.md — documented the new consumerKind field for file_exports.

Tests

Out of scope

Filed #1973: the same imports-type/calls conflation exists in checkNoDeletedExportsInUse (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 — pass
  • npm test — full suite green (228 test files, 3763 passed, 30 skipped, 2 todo)
  • npm run lint / npx tsc --noEmit — clean
  • codegraph diff-impact --staged -T — impact confined to exports.ts and its direct callers, as expected

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.
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR separates file-level type imports from real symbol consumers in export reporting. The main changes are:

  • Adds consumerKind to exportsData consumer entries.
  • Renders type-only imports in the CLI without a fake :0 call-site.
  • Updates exported types, MCP docs, and regression tests for both consumer shapes.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/domain/analysis/exports.ts Adds sourceKind to the consumer query and maps it into the new consumerKind discriminator.
src/presentation/queries-cli/exports.ts Formats file-level type imports separately from symbol-level call-site consumers.
src/types.ts Adds the FileExportConsumer shape and uses it for FileExportEntry.consumers.
docs/examples/MCP.md Documents the new consumerKind field in file_exports output.
tests/integration/exports.test.ts Covers symbol-level callers and file-level import type consumers.
tests/presentation/queries-cli.test.ts Checks that the CLI prints type-only imports without consumer.ts:0.

Reviews (1): Last reviewed commit: "fix(exports): discriminate file-level fr..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

11 functions changed9 callers affected across 3 files

  • exportsFileImpl in src/domain/analysis/exports.ts:146 (3 transitive callers)
  • buildSymbolResult in src/domain/analysis/exports.ts:206 (4 transitive callers)
  • ExportConsumer.consumerKind in src/presentation/queries-cli/exports.ts:14 (0 transitive callers)
  • formatConsumer in src/presentation/queries-cli/exports.ts:18 (6 transitive callers)
  • printExportSymbols in src/presentation/queries-cli/exports.ts:73 (2 transitive callers)
  • printReexportSymbol in src/presentation/queries-cli/exports.ts:98 (3 transitive callers)
  • FileExportEntry.consumers in src/types.ts:2027 (0 transitive callers)
  • FileExportConsumer.name in src/types.ts:2041 (0 transitive callers)
  • FileExportConsumer.file in src/types.ts:2042 (0 transitive callers)
  • FileExportConsumer.line in src/types.ts:2043 (0 transitive callers)
  • FileExportConsumer.consumerKind in src/types.ts:2044 (0 transitive callers)

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