@@ -52,12 +52,12 @@ namespace ts.FindAllReferences {
5252 export function getImplementationsAtPosition ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , sourceFile : SourceFile , position : number ) : ImplementationLocation [ ] {
5353 // A node in a JSDoc comment can't have an implementation anyway.
5454 const node = getTouchingPropertyName ( sourceFile , position , /*includeJsDocComment*/ false ) ;
55- const referenceEntries = getImplementationReferenceEntries ( program , cancellationToken , sourceFiles , node ) ;
55+ const referenceEntries = getImplementationReferenceEntries ( program , cancellationToken , sourceFiles , node , position ) ;
5656 const checker = program . getTypeChecker ( ) ;
5757 return map ( referenceEntries , entry => toImplementationLocation ( entry , checker ) ) ;
5858 }
5959
60- function getImplementationReferenceEntries ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , node : Node ) : Entry [ ] | undefined {
60+ function getImplementationReferenceEntries ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , node : Node , position : number ) : Entry [ ] | undefined {
6161 if ( node . kind === SyntaxKind . SourceFile ) {
6262 return undefined ;
6363 }
@@ -78,7 +78,7 @@ namespace ts.FindAllReferences {
7878 }
7979 else {
8080 // Perform "Find all References" and retrieve only those that are implementations
81- return getReferenceEntriesForNode ( node , program , sourceFiles , cancellationToken , { implementations : true } ) ;
81+ return getReferenceEntriesForNode ( position , node , program , sourceFiles , cancellationToken , { implementations : true } ) ;
8282 }
8383 }
8484
@@ -87,13 +87,13 @@ namespace ts.FindAllReferences {
8787 return map ( x , toReferenceEntry ) ;
8888 }
8989
90- export function getReferenceEntriesForNode ( node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : Entry [ ] | undefined {
91- return flattenEntries ( Core . getReferencedSymbolsForNode ( node , program , sourceFiles , cancellationToken , options ) ) ;
90+ export function getReferenceEntriesForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : Entry [ ] | undefined {
91+ return flattenEntries ( Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options ) ) ;
9292 }
9393
9494 function findAllReferencedSymbols ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , sourceFile : SourceFile , position : number , options ?: Options ) : SymbolAndEntries [ ] | undefined {
9595 const node = getTouchingPropertyName ( sourceFile , position , /*includeJsDocComment*/ true ) ;
96- return Core . getReferencedSymbolsForNode ( node , program , sourceFiles , cancellationToken , options ) ;
96+ return Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options ) ;
9797 }
9898
9999 function flattenEntries ( referenceSymbols : SymbolAndEntries [ ] ) : Entry [ ] {
@@ -242,9 +242,10 @@ namespace ts.FindAllReferences {
242242/* @internal */
243243namespace ts . FindAllReferences . Core {
244244 /** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */
245- export function getReferencedSymbolsForNode ( node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : SymbolAndEntries [ ] | undefined {
246- if ( node . kind === ts . SyntaxKind . SourceFile ) {
247- return undefined ;
245+ export function getReferencedSymbolsForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : SymbolAndEntries [ ] | undefined {
246+ if ( isSourceFile ( node ) ) {
247+ const reference = GoToDefinition . getReferenceAtPosition ( node , position , program ) ;
248+ return reference && getReferencedSymbolsForModule ( program , program . getTypeChecker ( ) . getMergedSymbol ( reference . file . symbol ) , sourceFiles ) ;
248249 }
249250
250251 if ( ! options . implementations ) {
@@ -260,11 +261,7 @@ namespace ts.FindAllReferences.Core {
260261 // Could not find a symbol e.g. unknown identifier
261262 if ( ! symbol ) {
262263 // String literal might be a property (and thus have a symbol), so do this here rather than in getReferencedSymbolsSpecial.
263- if ( ! options . implementations && node . kind === SyntaxKind . StringLiteral ) {
264- return getReferencesForStringLiteral ( < StringLiteral > node , sourceFiles , cancellationToken ) ;
265- }
266- // Can't have references to something that we have no symbol for.
267- return undefined ;
264+ return ! options . implementations && isStringLiteral ( node ) ? getReferencesForStringLiteral ( node , sourceFiles , cancellationToken ) : undefined ;
268265 }
269266
270267 if ( symbol . flags & SymbolFlags . Module && isModuleReferenceLocation ( node ) ) {
0 commit comments