@@ -412,6 +412,7 @@ namespace ts.server {
412
412
let progress = false ;
413
413
perProjectResults . forEach ( ( referencedSymbols , project ) => {
414
414
if ( updatedProjects . has ( project ) ) return ;
415
+ if ( ! referencedSymbols ) return ;
415
416
const updated = project . getLanguageService ( ) . updateIsDefinitionOfReferencedSymbols ( referencedSymbols , knownSymbolSpans ) ;
416
417
if ( updated ) {
417
418
updatedProjects . add ( project ) ;
@@ -423,6 +424,7 @@ namespace ts.server {
423
424
424
425
perProjectResults . forEach ( ( referencedSymbols , project ) => {
425
426
if ( updatedProjects . has ( project ) ) return ;
427
+ if ( ! referencedSymbols ) return ;
426
428
for ( const referencedSymbol of referencedSymbols ) {
427
429
for ( const ref of referencedSymbol . references ) {
428
430
ref . isDefinition = false ;
@@ -441,27 +443,29 @@ namespace ts.server {
441
443
// Otherwise, it just ends up attached to the first corresponding def we happen to process. The others may or may not be
442
444
// dropped later when we check for defs with ref-count 0.
443
445
perProjectResults . forEach ( ( projectResults , project ) => {
444
- for ( const referencedSymbol of projectResults ) {
445
- const mappedDefinitionFile = getMappedLocationForProject ( documentSpanLocation ( referencedSymbol . definition ) , project ) ;
446
- const definition : ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ?
447
- referencedSymbol . definition :
448
- {
449
- ...referencedSymbol . definition ,
450
- textSpan : createTextSpan ( mappedDefinitionFile . pos , referencedSymbol . definition . textSpan . length ) , // Why would the length be the same in the original?
451
- fileName : mappedDefinitionFile . fileName ,
452
- contextSpan : getMappedContextSpanForProject ( referencedSymbol . definition , project )
453
- } ;
446
+ if ( projectResults ) {
447
+ for ( const referencedSymbol of projectResults ) {
448
+ const mappedDefinitionFile = getMappedLocationForProject ( documentSpanLocation ( referencedSymbol . definition ) , project ) ;
449
+ const definition : ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ?
450
+ referencedSymbol . definition :
451
+ {
452
+ ...referencedSymbol . definition ,
453
+ textSpan : createTextSpan ( mappedDefinitionFile . pos , referencedSymbol . definition . textSpan . length ) , // Why would the length be the same in the original?
454
+ fileName : mappedDefinitionFile . fileName ,
455
+ contextSpan : getMappedContextSpanForProject ( referencedSymbol . definition , project )
456
+ } ;
454
457
455
- let symbolToAddTo = find ( results , o => documentSpansEqual ( o . definition , definition ) ) ;
456
- if ( ! symbolToAddTo ) {
457
- symbolToAddTo = { definition, references : [ ] } ;
458
- results . push ( symbolToAddTo ) ;
459
- }
458
+ let symbolToAddTo = find ( results , o => documentSpansEqual ( o . definition , definition ) ) ;
459
+ if ( ! symbolToAddTo ) {
460
+ symbolToAddTo = { definition, references : [ ] } ;
461
+ results . push ( symbolToAddTo ) ;
462
+ }
460
463
461
- for ( const ref of referencedSymbol . references ) {
462
- if ( ! seenRefs . has ( ref ) && ! getMappedLocationForProject ( documentSpanLocation ( ref ) , project ) ) {
463
- seenRefs . add ( ref ) ;
464
- symbolToAddTo . references . push ( ref ) ;
464
+ for ( const ref of referencedSymbol . references ) {
465
+ if ( ! seenRefs . has ( ref ) && ! getMappedLocationForProject ( documentSpanLocation ( ref ) , project ) ) {
466
+ seenRefs . add ( ref ) ;
467
+ symbolToAddTo . references . push ( ref ) ;
468
+ }
465
469
}
466
470
}
467
471
}
@@ -504,9 +508,9 @@ namespace ts.server {
504
508
isForRename : boolean ,
505
509
getResultsForPosition : ( project : Project , location : DocumentPosition ) => readonly TResult [ ] | undefined ,
506
510
forPositionInResult : ( result : TResult , cb : ( location : DocumentPosition ) => void ) => void ,
507
- ) : readonly TResult [ ] | ESMap < Project , readonly TResult [ ] > {
511
+ ) : readonly TResult [ ] | ESMap < Project , undefined | readonly TResult [ ] > {
508
512
// If `getResultsForPosition` returns results for a project, they go in here
509
- const resultsMap = new Map < Project , readonly TResult [ ] > ( ) ;
513
+ const resultsMap = new Map < Project , undefined | readonly TResult [ ] > ( ) ;
510
514
511
515
const queue : ProjectAndLocation [ ] = [ ] ;
512
516
@@ -588,7 +592,8 @@ namespace ts.server {
588
592
// it easier for the caller to skip post-processing.
589
593
if ( resultsMap . size === 1 ) {
590
594
const it = resultsMap . values ( ) . next ( ) ;
591
- return it . done ? emptyArray : it . value ; // There may not be any results at all
595
+ Debug . assert ( ! it . done ) ;
596
+ return it . value ?? emptyArray ;
592
597
}
593
598
594
599
return resultsMap ;
0 commit comments