@@ -52,12 +52,12 @@ namespace ts.FindAllReferences {
52
52
export function getImplementationsAtPosition ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , sourceFile : SourceFile , position : number ) : ImplementationLocation [ ] {
53
53
// A node in a JSDoc comment can't have an implementation anyway.
54
54
const node = getTouchingPropertyName ( sourceFile , position , /*includeJsDocComment*/ false ) ;
55
- const referenceEntries = getImplementationReferenceEntries ( program , cancellationToken , sourceFiles , node ) ;
55
+ const referenceEntries = getImplementationReferenceEntries ( program , cancellationToken , sourceFiles , node , position ) ;
56
56
const checker = program . getTypeChecker ( ) ;
57
57
return map ( referenceEntries , entry => toImplementationLocation ( entry , checker ) ) ;
58
58
}
59
59
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 {
61
61
if ( node . kind === SyntaxKind . SourceFile ) {
62
62
return undefined ;
63
63
}
@@ -78,7 +78,7 @@ namespace ts.FindAllReferences {
78
78
}
79
79
else {
80
80
// 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 } ) ;
82
82
}
83
83
}
84
84
@@ -87,13 +87,13 @@ namespace ts.FindAllReferences {
87
87
return map ( x , toReferenceEntry ) ;
88
88
}
89
89
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 ) ) ;
92
92
}
93
93
94
94
function findAllReferencedSymbols ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , sourceFile : SourceFile , position : number , options ?: Options ) : SymbolAndEntries [ ] | undefined {
95
95
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 ) ;
97
97
}
98
98
99
99
function flattenEntries ( referenceSymbols : SymbolAndEntries [ ] ) : Entry [ ] {
@@ -242,9 +242,10 @@ namespace ts.FindAllReferences {
242
242
/* @internal */
243
243
namespace ts . FindAllReferences . Core {
244
244
/** 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 ) ;
248
249
}
249
250
250
251
if ( ! options . implementations ) {
@@ -260,11 +261,7 @@ namespace ts.FindAllReferences.Core {
260
261
// Could not find a symbol e.g. unknown identifier
261
262
if ( ! symbol ) {
262
263
// 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 ;
268
265
}
269
266
270
267
if ( symbol . flags & SymbolFlags . Module && isModuleReferenceLocation ( node ) ) {
0 commit comments