@@ -14,7 +14,7 @@ import { getAuthUrlForTokenPage } from "./control-plane/auth/index";
14
14
import { getControlPlaneEnv } from "./control-plane/env" ;
15
15
import { DevDataSqliteDb } from "./data/devdataSqlite" ;
16
16
import { DataLogger } from "./data/log" ;
17
- import { CodebaseIndexer , PauseToken } from "./indexing/CodebaseIndexer" ;
17
+ import { CodebaseIndexer } from "./indexing/CodebaseIndexer" ;
18
18
import DocsService from "./indexing/docs/DocsService" ;
19
19
import { countTokens } from "./llm/countTokens" ;
20
20
import Ollama from "./llm/llms/Ollama" ;
@@ -40,8 +40,7 @@ import {
40
40
RangeInFile ,
41
41
type ContextItem ,
42
42
type ContextItemId ,
43
- type IDE ,
44
- type IndexingProgressUpdate ,
43
+ type IDE
45
44
} from "." ;
46
45
47
46
import { ConfigYaml } from "@continuedev/config-yaml" ;
@@ -56,7 +55,6 @@ import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton";
56
55
import { streamDiffLines } from "./edit/streamDiffLines" ;
57
56
import { shouldIgnore } from "./indexing/shouldIgnore" ;
58
57
import { walkDirCache } from "./indexing/walkDir" ;
59
- import { LLMError } from "./llm" ;
60
58
import { LLMLogger } from "./llm/logger" ;
61
59
import { llmStreamChat } from "./llm/streamChat" ;
62
60
import type { FromCoreProtocol , ToCoreProtocol } from "./protocol" ;
@@ -65,18 +63,13 @@ import { StreamAbortManager } from "./util/abortManager";
65
63
66
64
export class Core {
67
65
configHandler : ConfigHandler ;
68
- codebaseIndexerPromise : Promise < CodebaseIndexer > ;
66
+ codeBaseIndexer : CodebaseIndexer ;
69
67
completionProvider : CompletionProvider ;
70
- continueServerClientPromise : Promise < ContinueServerClient > ;
71
- codebaseIndexingState : IndexingProgressUpdate ;
68
+ continueServerClientPromise : Promise < ContinueServerClient > ;
72
69
private docsService : DocsService ;
73
70
private globalContext = new GlobalContext ( ) ;
74
71
llmLogger = new LLMLogger ( ) ;
75
72
76
- private readonly indexingPauseToken = new PauseToken (
77
- this . globalContext . get ( "indexingPaused" ) === true ,
78
- ) ;
79
-
80
73
private messageAbortControllers = new Map < string , AbortController > ( ) ;
81
74
private addMessageAbortController ( id : string ) : AbortController {
82
75
const controller = new AbortController ( ) ;
@@ -114,12 +107,6 @@ export class Core {
114
107
// Ensure .continue directory is created
115
108
migrateV1DevDataFiles ( ) ;
116
109
117
- this . codebaseIndexingState = {
118
- status : "loading" ,
119
- desc : "loading" ,
120
- progress : 0 ,
121
- } ;
122
-
123
110
const ideInfoPromise = messenger . request ( "getIdeInfo" , undefined ) ;
124
111
const ideSettingsPromise = messenger . request ( "getIdeSettings" , undefined ) ;
125
112
const sessionInfoPromise = messenger . request ( "getControlPlaneSessionInfo" , {
@@ -144,6 +131,13 @@ export class Core {
144
131
await this . configHandler . reloadConfig ( ) ;
145
132
} ;
146
133
134
+ this . codeBaseIndexer = new CodebaseIndexer (
135
+ this . configHandler ,
136
+ this . ide ,
137
+ this . messenger ,
138
+ this . globalContext . get ( "indexingPaused" ) ,
139
+ ) ;
140
+
147
141
this . configHandler . onConfigUpdate ( async ( result ) => {
148
142
const serializedResult = await this . configHandler . getSerializedConfig ( ) ;
149
143
this . messenger . send ( "configUpdate" , {
@@ -170,38 +164,24 @@ export class Core {
170
164
dataLogger . ideInfoPromise = ideInfoPromise ;
171
165
dataLogger . ideSettingsPromise = ideSettingsPromise ;
172
166
173
- // Codebase Indexer and ContinueServerClient depend on IdeSettings
174
- let codebaseIndexerResolve : ( _ : any ) => void | undefined ;
175
- this . codebaseIndexerPromise = new Promise (
176
- async ( resolve ) => ( codebaseIndexerResolve = resolve ) ,
177
- ) ;
178
-
179
167
let continueServerClientResolve : ( _ : any ) => void | undefined ;
180
168
this . continueServerClientPromise = new Promise (
181
169
( resolve ) => ( continueServerClientResolve = resolve ) ,
182
170
) ;
183
171
172
+
184
173
void ideSettingsPromise . then ( ( ideSettings ) => {
185
- const continueServerClient = new ContinueServerClient (
174
+ const continueServerClient = new ContinueServerClient (
186
175
ideSettings . remoteConfigServerUrl ,
187
176
ideSettings . userToken ,
188
177
) ;
189
178
continueServerClientResolve ( continueServerClient ) ;
190
179
191
- codebaseIndexerResolve (
192
- new CodebaseIndexer (
193
- this . configHandler ,
194
- this . ide ,
195
- this . indexingPauseToken ,
196
- continueServerClient ,
197
- ) ,
198
- ) ;
199
-
200
180
// Index on initialization
201
181
void this . ide . getWorkspaceDirs ( ) . then ( async ( dirs ) => {
202
182
// Respect pauseCodebaseIndexOnStart user settings
203
183
if ( ideSettings . pauseCodebaseIndexOnStart ) {
204
- this . indexingPauseToken . paused = true ;
184
+ this . codeBaseIndexer . paused = true ;
205
185
void this . messenger . request ( "indexProgress" , {
206
186
progress : 0 ,
207
187
desc : "Initial Indexing Skipped" ,
@@ -210,7 +190,7 @@ export class Core {
210
190
return ;
211
191
}
212
192
213
- void this . refreshCodebaseIndex ( dirs ) ;
193
+ await this . codeBaseIndexer . refreshCodebaseIndex ( dirs ) ;
214
194
} ) ;
215
195
} ) ;
216
196
@@ -551,25 +531,24 @@ export class Core {
551
531
}
552
532
walkDirCache . invalidate ( ) ;
553
533
if ( data ?. shouldClearIndexes ) {
554
- const codebaseIndexer = await this . codebaseIndexerPromise ;
555
- await codebaseIndexer . clearIndexes ( ) ;
534
+ await this . codeBaseIndexer . clearIndexes ( ) ;
556
535
}
557
536
558
537
const dirs = data ?. dirs ?? ( await this . ide . getWorkspaceDirs ( ) ) ;
559
- await this . refreshCodebaseIndex ( dirs ) ;
538
+ await this . codeBaseIndexer . refreshCodebaseIndex ( dirs ) ;
560
539
} ) ;
561
540
on ( "index/setPaused" , ( msg ) => {
562
541
this . globalContext . update ( "indexingPaused" , msg . data ) ;
563
- this . indexingPauseToken . paused = msg . data ;
542
+ // Update using the new setter instead of token
543
+ this . codeBaseIndexer . paused = msg . data ;
564
544
} ) ;
565
545
on ( "index/indexingProgressBarInitialized" , async ( msg ) => {
566
546
// Triggered when progress bar is initialized.
567
547
// If a non-default state has been stored, update the indexing display to that state
568
- if ( this . codebaseIndexingState . status !== "loading" ) {
569
- void this . messenger . request (
570
- "indexProgress" ,
571
- this . codebaseIndexingState ,
572
- ) ;
548
+ const currentState = this . codeBaseIndexer . currentIndexingState ;
549
+
550
+ if ( currentState . status !== "loading" ) {
551
+ void this . messenger . request ( "indexProgress" , currentState ) ;
573
552
}
574
553
} ) ;
575
554
@@ -589,7 +568,7 @@ export class Core {
589
568
} ) ;
590
569
const { config } = await this . configHandler . loadConfig ( ) ;
591
570
if ( config && ! config . disableIndexing ) {
592
- await this . refreshCodebaseIndexFiles ( toRefresh ) ;
571
+ await this . codeBaseIndexer . refreshCodebaseIndexFiles ( toRefresh ) ;
593
572
}
594
573
}
595
574
} ;
@@ -853,7 +832,7 @@ export class Core {
853
832
// Reindex the file
854
833
const ignore = await shouldIgnore ( uri , this . ide ) ;
855
834
if ( ! ignore ) {
856
- await this . refreshCodebaseIndexFiles ( [ uri ] ) ;
835
+ await this . codeBaseIndexer . refreshCodebaseIndexFiles ( [ uri ] ) ;
857
836
}
858
837
}
859
838
}
@@ -1024,100 +1003,4 @@ export class Core {
1024
1003
return [ ] ;
1025
1004
}
1026
1005
} ;
1027
-
1028
- private indexingCancellationController : AbortController | undefined ;
1029
- private async sendIndexingErrorTelemetry ( update : IndexingProgressUpdate ) {
1030
- console . debug (
1031
- "Indexing failed with error: " ,
1032
- update . desc ,
1033
- update . debugInfo ,
1034
- ) ;
1035
- void Telemetry . capture (
1036
- "indexing_error" ,
1037
- {
1038
- error : update . desc ,
1039
- stack : update . debugInfo ,
1040
- } ,
1041
- false ,
1042
- ) ;
1043
- }
1044
-
1045
- private async refreshCodebaseIndex ( paths : string [ ] ) {
1046
- if ( this . indexingCancellationController ) {
1047
- this . indexingCancellationController . abort ( ) ;
1048
- }
1049
- this . indexingCancellationController = new AbortController ( ) ;
1050
- try {
1051
- for await ( const update of (
1052
- await this . codebaseIndexerPromise
1053
- ) . refreshDirs ( paths , this . indexingCancellationController . signal ) ) {
1054
- let updateToSend = { ...update } ;
1055
-
1056
- void this . messenger . request ( "indexProgress" , updateToSend ) ;
1057
- this . codebaseIndexingState = updateToSend ;
1058
-
1059
- if ( update . status === "failed" ) {
1060
- void this . sendIndexingErrorTelemetry ( update ) ;
1061
- }
1062
- }
1063
- } catch ( e : any ) {
1064
- console . log ( `Failed refreshing codebase index directories : ${ e } ` ) ;
1065
- this . handleIndexingError ( e ) ;
1066
- }
1067
-
1068
- this . messenger . send ( "refreshSubmenuItems" , {
1069
- providers : "dependsOnIndexing" ,
1070
- } ) ;
1071
- this . indexingCancellationController = undefined ;
1072
- }
1073
-
1074
- private async refreshCodebaseIndexFiles ( files : string [ ] ) {
1075
- // Can be cancelled by codebase index but not vice versa
1076
- if (
1077
- this . indexingCancellationController &&
1078
- ! this . indexingCancellationController . signal . aborted
1079
- ) {
1080
- return ;
1081
- }
1082
- this . indexingCancellationController = new AbortController ( ) ;
1083
- try {
1084
- for await ( const update of (
1085
- await this . codebaseIndexerPromise
1086
- ) . refreshFiles ( files ) ) {
1087
- let updateToSend = { ...update } ;
1088
-
1089
- void this . messenger . request ( "indexProgress" , updateToSend ) ;
1090
- this . codebaseIndexingState = updateToSend ;
1091
-
1092
- if ( update . status === "failed" ) {
1093
- void this . sendIndexingErrorTelemetry ( update ) ;
1094
- }
1095
- }
1096
- } catch ( e : any ) {
1097
- console . log ( `Failed refreshing codebase index files : ${ e } ` ) ;
1098
- this . handleIndexingError ( e ) ;
1099
- }
1100
-
1101
- this . messenger . send ( "refreshSubmenuItems" , {
1102
- providers : "dependsOnIndexing" ,
1103
- } ) ;
1104
- this . indexingCancellationController = undefined ;
1105
- }
1106
-
1107
- // private
1108
- handleIndexingError ( e : any ) {
1109
- if ( e instanceof LLMError ) {
1110
- // Need to report this specific error to the IDE for special handling
1111
- void this . messenger . request ( "reportError" , e ) ;
1112
- }
1113
- // broadcast indexing error
1114
- let updateToSend : IndexingProgressUpdate = {
1115
- progress : 0 ,
1116
- status : "failed" ,
1117
- desc : e . message ,
1118
- } ;
1119
- void this . messenger . request ( "indexProgress" , updateToSend ) ;
1120
- this . codebaseIndexingState = updateToSend ;
1121
- void this . sendIndexingErrorTelemetry ( updateToSend ) ;
1122
- }
1123
1006
}
0 commit comments