microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101k stars 12.48k forks source link

Suggestion: ability to find imports for module #22374

Open OliverJAsh opened 6 years ago

OliverJAsh commented 6 years ago

Find references is a very useful feature, however sometimes I need to be able to find all imports of a given module:

This is sometimes necessary when a module has side effects, and you want to see which files imported it.

This might also be useful for dynamic imports. In one project we have several dynamic imports (for code splitting) that never explicitly reference the module exports, so if I use find references on those module exports, I will not be shown the dynamic import. For example, here is a dynamic import:

image

When I activate find references on the exports of that module, I am not shown the import:

image

mhegazy commented 6 years ago

Find all refs on the module path should show you all imports to it:

image

mhegazy commented 6 years ago

Is that not sufficient for your scenarios?

OliverJAsh commented 6 years ago

I'm after the opposite—to find all imports for the currently focused module. E.g.:

// a.ts
// "find imports" used in this module will list the imports in `b.ts` and `c.ts`
export const foo = 'bar';
// b.ts
import('./a');
// c.ts
import './a';
mhegazy commented 6 years ago

I see.. I suppose we can expose this on the export keyword. though it is kinda weird.. possibly another command on the server..

@andy-ms, @amcasey and @DanielRosenwasser thoughts?

amcasey commented 6 years ago

@OliverJAsh to confirm, you're not looking for consumers of foo, you're looking for consumers of a.ts?

OliverJAsh commented 6 years ago

That's right

On Wed, 7 Mar 2018, 22:27 Andrew Casey, notifications@github.com wrote:

@OliverJAsh https://github.com/oliverjash to confirm, you're not looking for consumers of foo, you're looking for consumers of a.ts?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/TypeScript/issues/22374#issuecomment-371307222, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4QCWKI5foGTNg543095IQbHt6XsMphks5tcF54gaJpZM4Sgc09 .

amcasey commented 6 years ago

@mhegazy I agree that it's not clear how we would trigger such a search. Personally, I would expect invoking Find All References on the export keyword to list references to that exported symbol.

mhegazy commented 6 years ago

Personally, I would expect invoking Find All References on the export keyword to list references to that exported symbol.

yeah.. then a new command is needed, but it wounder if that will be discoverable.