@@ -504,18 +504,18 @@ namespace ts.server {
504
504
// If `getResultsForPosition` returns results for a project, they go in here
505
505
const resultsMap = new Map < Project , readonly TResult [ ] > ( ) ;
506
506
507
- const queue : ProjectAndLocation [ ] = [ ] ;
507
+ const queue = createQueue < ProjectAndLocation > ( ) ;
508
508
509
509
// In order to get accurate isDefinition values for `defaultProject`,
510
510
// we need to ensure that it is searched from `initialLocation`.
511
511
// The easiest way to do this is to search it first.
512
- queue . push ( { project : defaultProject , location : initialLocation } ) ;
512
+ queue . enqueue ( { project : defaultProject , location : initialLocation } ) ;
513
513
514
514
// This will queue `defaultProject` a second time, but it will be dropped
515
515
// as a dup when it is dequeued.
516
516
forEachProjectInProjects ( projects , initialLocation . fileName , ( project , path ) => {
517
517
const location = { fileName : path ! , pos : initialLocation . pos } ;
518
- queue . push ( { project, location } ) ;
518
+ queue . enqueue ( { project, location } ) ;
519
519
} ) ;
520
520
521
521
const projectService = defaultProject . projectService ;
@@ -536,25 +536,13 @@ namespace ts.server {
536
536
const searchedProjectKeys = new Set < string > ( ) ;
537
537
538
538
onCancellation:
539
- while ( queue . length ) {
540
- while ( queue . length ) {
539
+ while ( ! queue . isEmpty ( ) ) {
540
+ while ( ! queue . isEmpty ( ) ) {
541
541
if ( cancellationToken . isCancellationRequested ( ) ) break onCancellation;
542
542
543
- let skipCount = 0 ;
544
- for ( ; skipCount < queue . length && resultsMap . has ( queue [ skipCount ] . project ) ; skipCount ++ ) ;
545
-
546
- if ( skipCount === queue . length ) {
547
- queue . length = 0 ;
548
- break ;
549
- }
550
-
551
- if ( skipCount > 0 ) {
552
- queue . splice ( 0 , skipCount ) ;
553
- }
554
-
555
- // NB: we may still skip if it's a project reference redirect
556
- const { project, location } = queue . shift ( ) ! ;
543
+ const { project, location } = queue . dequeue ( ) ;
557
544
545
+ if ( resultsMap . has ( project ) ) continue ;
558
546
if ( isLocationProjectReferenceRedirect ( project , location ) ) continue ;
559
547
560
548
const projectResults = searchPosition ( project , location ) ;
@@ -574,7 +562,7 @@ namespace ts.server {
574
562
if ( resultsMap . has ( project ) ) return ; // Can loop forever without this (enqueue here, dequeue above, repeat)
575
563
const location = mapDefinitionInProject ( defaultDefinition , project , getGeneratedDefinition , getSourceDefinition ) ;
576
564
if ( location ) {
577
- queue . push ( { project, location } ) ;
565
+ queue . enqueue ( { project, location } ) ;
578
566
}
579
567
} ) ;
580
568
}
@@ -604,7 +592,7 @@ namespace ts.server {
604
592
605
593
for ( const project of originalScriptInfo . containingProjects ) {
606
594
if ( ! project . isOrphan ( ) && ! resultsMap . has ( project ) ) { // Optimization: don't enqueue if will be discarded
607
- queue . push ( { project, location : originalLocation } ) ;
595
+ queue . enqueue ( { project, location : originalLocation } ) ;
608
596
}
609
597
}
610
598
@@ -613,7 +601,7 @@ namespace ts.server {
613
601
symlinkedProjectsMap . forEach ( ( symlinkedProjects , symlinkedPath ) => {
614
602
for ( const symlinkedProject of symlinkedProjects ) {
615
603
if ( ! symlinkedProject . isOrphan ( ) && ! resultsMap . has ( symlinkedProject ) ) { // Optimization: don't enqueue if will be discarded
616
- queue . push ( { project : symlinkedProject , location : { fileName : symlinkedPath as string , pos : originalLocation . pos } } ) ;
604
+ queue . enqueue ( { project : symlinkedProject , location : { fileName : symlinkedPath as string , pos : originalLocation . pos } } ) ;
617
605
}
618
606
}
619
607
} ) ;
0 commit comments