@@ -56,7 +56,7 @@ export class CodebaseIndexer {
5656 // and only need to `await` it for tests.
5757 public initPromise : Promise < void > ;
5858 private config ! : ContinueConfig ;
59- private indexingCancellationController : AbortController | undefined ;
59+ private indexingCancellationController : AbortController ;
6060 private codebaseIndexingState : IndexingProgressUpdate ;
6161 private readonly pauseToken : PauseToken ;
6262
@@ -97,6 +97,9 @@ export class CodebaseIndexer {
9797 this . pauseToken = new PauseToken ( initialPaused ) ;
9898
9999 this . initPromise = this . init ( configHandler ) ;
100+
101+ this . indexingCancellationController = new AbortController ( ) ;
102+ this . indexingCancellationController . abort ( ) ; // initialize and abort so that a new one can be created
100103 }
101104
102105 // Initialization - load config and attach config listener
@@ -693,7 +696,7 @@ export class CodebaseIndexer {
693696 }
694697
695698 public async refreshCodebaseIndex ( paths : string [ ] ) {
696- if ( this . indexingCancellationController ) {
699+ if ( ! this . indexingCancellationController . signal . aborted ) {
697700 this . indexingCancellationController . abort ( ) ;
698701 }
699702 const localController = new AbortController ( ) ;
@@ -735,17 +738,13 @@ export class CodebaseIndexer {
735738 } ) ;
736739 }
737740 if ( this . indexingCancellationController === localController ) {
738- this . indexingCancellationController . abort ( ) ; // abort before clearing to prevent race condition (multiple starts)
739- this . indexingCancellationController = undefined ;
741+ this . indexingCancellationController . abort ( ) ;
740742 }
741743 }
742744
743745 public async refreshCodebaseIndexFiles ( files : string [ ] ) {
744746 // Can be cancelled by codebase index but not vice versa
745- if (
746- this . indexingCancellationController &&
747- ! this . indexingCancellationController . signal . aborted
748- ) {
747+ if ( ! this . indexingCancellationController . signal . aborted ) {
749748 return ;
750749 }
751750 const localController = new AbortController ( ) ;
@@ -771,7 +770,7 @@ export class CodebaseIndexer {
771770 } ) ;
772771 }
773772 if ( this . indexingCancellationController === localController ) {
774- this . indexingCancellationController = undefined ;
773+ this . indexingCancellationController . abort ( ) ;
775774 }
776775 }
777776
0 commit comments