@@ -5,13 +5,14 @@ namespace ts.FindAllReferences {
55 readonly references : readonly Entry [ ] ;
66 }
77
8- export const enum DefinitionKind { Symbol , Label , Keyword , This , String }
8+ export const enum DefinitionKind { Symbol , Label , Keyword , This , String , TripleSlashReference }
99 export type Definition =
1010 | { readonly type : DefinitionKind . Symbol ; readonly symbol : Symbol }
1111 | { readonly type : DefinitionKind . Label ; readonly node : Identifier }
1212 | { readonly type : DefinitionKind . Keyword ; readonly node : Node }
1313 | { readonly type : DefinitionKind . This ; readonly node : Node }
14- | { readonly type : DefinitionKind . String ; readonly node : StringLiteralLike } ;
14+ | { readonly type : DefinitionKind . String ; readonly node : StringLiteralLike }
15+ | { readonly type : DefinitionKind . TripleSlashReference ; readonly reference : FileReference , readonly file : SourceFile } ;
1516
1617 export const enum EntryKind { Span , Node , StringLiteral , SearchedLocalFoundProperty , SearchedPropertyFoundLocal }
1718 export type NodeEntryKind = EntryKind . Node | EntryKind . StringLiteral | EntryKind . SearchedLocalFoundProperty | EntryKind . SearchedPropertyFoundLocal ;
@@ -298,17 +299,16 @@ namespace ts.FindAllReferences {
298299 }
299300
300301 function definitionToReferencedSymbolDefinitionInfo ( def : Definition , checker : TypeChecker , originalNode : Node ) : ReferencedSymbolDefinitionInfo {
301- const info = ( ( ) => {
302+ const info = ( ( ) : { sourceFile : SourceFile , textSpan : TextSpan , name : string , kind : ScriptElementKind , displayParts : SymbolDisplayPart [ ] , context ?: Node | ContextWithStartAndEndNode } => {
302303 switch ( def . type ) {
303304 case DefinitionKind . Symbol : {
304305 const { symbol } = def ;
305306 const { displayParts, kind } = getDefinitionKindAndDisplayParts ( symbol , checker , originalNode ) ;
306307 const name = displayParts . map ( p => p . text ) . join ( "" ) ;
307308 const declaration = symbol . declarations && firstOrUndefined ( symbol . declarations ) ;
309+ const node = declaration ? ( getNameOfDeclaration ( declaration ) || declaration ) : originalNode ;
308310 return {
309- node : declaration ?
310- getNameOfDeclaration ( declaration ) || declaration :
311- originalNode ,
311+ ...getFileAndTextSpanFromNode ( node ) ,
312312 name,
313313 kind,
314314 displayParts,
@@ -317,32 +317,44 @@ namespace ts.FindAllReferences {
317317 }
318318 case DefinitionKind . Label : {
319319 const { node } = def ;
320- return { node, name : node . text , kind : ScriptElementKind . label , displayParts : [ displayPart ( node . text , SymbolDisplayPartKind . text ) ] } ;
320+ return { ... getFileAndTextSpanFromNode ( node ) , name : node . text , kind : ScriptElementKind . label , displayParts : [ displayPart ( node . text , SymbolDisplayPartKind . text ) ] } ;
321321 }
322322 case DefinitionKind . Keyword : {
323323 const { node } = def ;
324324 const name = tokenToString ( node . kind ) ! ;
325- return { node, name, kind : ScriptElementKind . keyword , displayParts : [ { text : name , kind : ScriptElementKind . keyword } ] } ;
325+ return { ... getFileAndTextSpanFromNode ( node ) , name, kind : ScriptElementKind . keyword , displayParts : [ { text : name , kind : ScriptElementKind . keyword } ] } ;
326326 }
327327 case DefinitionKind . This : {
328328 const { node } = def ;
329329 const symbol = checker . getSymbolAtLocation ( node ) ;
330330 const displayParts = symbol && SymbolDisplay . getSymbolDisplayPartsDocumentationAndSymbolKind (
331331 checker , symbol , node . getSourceFile ( ) , getContainerNode ( node ) , node ) . displayParts || [ textPart ( "this" ) ] ;
332- return { node, name : "this" , kind : ScriptElementKind . variableElement , displayParts } ;
332+ return { ... getFileAndTextSpanFromNode ( node ) , name : "this" , kind : ScriptElementKind . variableElement , displayParts } ;
333333 }
334334 case DefinitionKind . String : {
335335 const { node } = def ;
336- return { node, name : node . text , kind : ScriptElementKind . variableElement , displayParts : [ displayPart ( getTextOfNode ( node ) , SymbolDisplayPartKind . stringLiteral ) ] } ;
336+ return {
337+ ...getFileAndTextSpanFromNode ( node ) ,
338+ name : node . text ,
339+ kind : ScriptElementKind . variableElement ,
340+ displayParts : [ displayPart ( getTextOfNode ( node ) , SymbolDisplayPartKind . stringLiteral ) ]
341+ } ;
342+ }
343+ case DefinitionKind . TripleSlashReference : {
344+ return {
345+ textSpan : createTextSpanFromRange ( def . reference ) ,
346+ sourceFile : def . file ,
347+ name : def . reference . fileName ,
348+ kind : ScriptElementKind . string ,
349+ displayParts : [ displayPart ( `"${ def . reference . fileName } "` , SymbolDisplayPartKind . stringLiteral ) ]
350+ } ;
337351 }
338352 default :
339353 return Debug . assertNever ( def ) ;
340354 }
341355 } ) ( ) ;
342356
343- const { node, name, kind, displayParts, context } = info ;
344- const sourceFile = node . getSourceFile ( ) ;
345- const textSpan = getTextSpan ( isComputedPropertyName ( node ) ? node . expression : node , sourceFile ) ;
357+ const { sourceFile, textSpan, name, kind, displayParts, context } = info ;
346358 return {
347359 containerKind : ScriptElementKind . unknown ,
348360 containerName : "" ,
@@ -355,6 +367,14 @@ namespace ts.FindAllReferences {
355367 } ;
356368 }
357369
370+ function getFileAndTextSpanFromNode ( node : Node ) {
371+ const sourceFile = node . getSourceFile ( ) ;
372+ return {
373+ sourceFile,
374+ textSpan : getTextSpan ( isComputedPropertyName ( node ) ? node . expression : node , sourceFile )
375+ } ;
376+ }
377+
358378 function getDefinitionKindAndDisplayParts ( symbol : Symbol , checker : TypeChecker , node : Node ) : { displayParts : SymbolDisplayPart [ ] , kind : ScriptElementKind } {
359379 const meaning = Core . getIntersectingMeaningFromDeclarations ( node , symbol ) ;
360380 const enclosingDeclaration = symbol . declarations && firstOrUndefined ( symbol . declarations ) || node ;
@@ -603,9 +623,22 @@ namespace ts.FindAllReferences {
603623 node = getAdjustedRenameLocation ( node ) ;
604624 }
605625 if ( isSourceFile ( node ) ) {
606- const reference = GoToDefinition . getReferenceAtPosition ( node , position , program ) ;
607- const moduleSymbol = reference && program . getTypeChecker ( ) . getMergedSymbol ( reference . file . symbol ) ;
608- return moduleSymbol && getReferencedSymbolsForModule ( program , moduleSymbol , /*excludeImportTypeOfExportEquals*/ false , sourceFiles , sourceFilesSet ) ;
626+ const resolvedRef = GoToDefinition . getReferenceAtPosition ( node , position , program ) ;
627+ if ( ! resolvedRef ) {
628+ return undefined ;
629+ }
630+ const moduleSymbol = program . getTypeChecker ( ) . getMergedSymbol ( resolvedRef . file . symbol ) ;
631+ if ( moduleSymbol ) {
632+ return getReferencedSymbolsForModule ( program , moduleSymbol , /*excludeImportTypeOfExportEquals*/ false , sourceFiles , sourceFilesSet ) ;
633+ }
634+ const fileIncludeReasons = program . getFileIncludeReasons ( ) ;
635+ if ( ! fileIncludeReasons ) {
636+ return undefined ;
637+ }
638+ return [ {
639+ definition : { type : DefinitionKind . TripleSlashReference , reference : resolvedRef . reference , file : node } ,
640+ references : getReferencesForNonModule ( resolvedRef . file , fileIncludeReasons , program ) || emptyArray
641+ } ] ;
609642 }
610643
611644 if ( ! options . implementations ) {
0 commit comments