@@ -504,18 +504,18 @@ namespace ts.server {
504504 // If `getResultsForPosition` returns results for a project, they go in here
505505 const resultsMap = new Map < Project , readonly TResult [ ] > ( ) ;
506506
507- const queue : ProjectAndLocation [ ] = [ ] ;
507+ const queue = createQueue < ProjectAndLocation > ( ) ;
508508
509509 // In order to get accurate isDefinition values for `defaultProject`,
510510 // we need to ensure that it is searched from `initialLocation`.
511511 // 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 } ) ;
513513
514514 // This will queue `defaultProject` a second time, but it will be dropped
515515 // as a dup when it is dequeued.
516516 forEachProjectInProjects ( projects , initialLocation . fileName , ( project , path ) => {
517517 const location = { fileName : path ! , pos : initialLocation . pos } ;
518- queue . push ( { project, location } ) ;
518+ queue . enqueue ( { project, location } ) ;
519519 } ) ;
520520
521521 const projectService = defaultProject . projectService ;
@@ -536,25 +536,13 @@ namespace ts.server {
536536 const searchedProjectKeys = new Set < string > ( ) ;
537537
538538 onCancellation:
539- while ( queue . length ) {
540- while ( queue . length ) {
539+ while ( ! queue . isEmpty ( ) ) {
540+ while ( ! queue . isEmpty ( ) ) {
541541 if ( cancellationToken . isCancellationRequested ( ) ) break onCancellation;
542542
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 ( ) ;
557544
545+ if ( resultsMap . has ( project ) ) continue ;
558546 if ( isLocationProjectReferenceRedirect ( project , location ) ) continue ;
559547
560548 const projectResults = searchPosition ( project , location ) ;
@@ -574,7 +562,7 @@ namespace ts.server {
574562 if ( resultsMap . has ( project ) ) return ; // Can loop forever without this (enqueue here, dequeue above, repeat)
575563 const location = mapDefinitionInProject ( defaultDefinition , project , getGeneratedDefinition , getSourceDefinition ) ;
576564 if ( location ) {
577- queue . push ( { project, location } ) ;
565+ queue . enqueue ( { project, location } ) ;
578566 }
579567 } ) ;
580568 }
@@ -604,7 +592,7 @@ namespace ts.server {
604592
605593 for ( const project of originalScriptInfo . containingProjects ) {
606594 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 } ) ;
608596 }
609597 }
610598
@@ -613,7 +601,7 @@ namespace ts.server {
613601 symlinkedProjectsMap . forEach ( ( symlinkedProjects , symlinkedPath ) => {
614602 for ( const symlinkedProject of symlinkedProjects ) {
615603 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 } } ) ;
617605 }
618606 }
619607 } ) ;
0 commit comments