豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 74475c3

Browse files
authored
Fix possible race with external ingest not seeing code search repos (#4796)
* Fix possible race with external ingest not seeing code search repos Also improve message for status in this case * Update test file
1 parent f21049d commit 74475c3

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/extension/workspaceChunkSearch/vscode-node/workspaceIndexingStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ export class ChatStatusWorkspaceIndexingStatus extends Disposable {
217217
},
218218
});
219219
} else if (typeof state.remoteIndexState.externalIngestState !== 'undefined') {
220-
// External indexing is enabled but not yet built
220+
// External indexing is enabled but not yet fully built
221221
return this._writeStatusItem({
222222
title: {
223-
title: t('Index not yet built'),
223+
title: t('Codebase index out of date'),
224224
learnMoreLink: 'https://aka.ms/vscode-copilot-workspace-remote-index',
225225
},
226226
details: {
227-
message: `[${t`Build index`}](command:${buildRemoteIndexCommandId} "${t('Build Codebase Index')}")`,
227+
message: `[${t`Update index`}](command:${buildRemoteIndexCommandId} "${t('Build Codebase Index')}")`,
228228
busy: false,
229229
}
230230
});

src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class CodeSearchChunkSearch extends Disposable {
155155
this._repoTracker = this._register(instantiationService.createInstance(CodeSearchRepoTracker));
156156
this._externalIngestIndex = new Lazy(() => {
157157
const client = instantiationService.createInstance(ExternalIngestClient);
158-
return this._register(instantiationService.createInstance(ExternalIngestIndex, client));
158+
return this._register(instantiationService.createInstance(ExternalIngestIndex, client, this.getExternalIngestRoots()));
159159
});
160160

161161
this._register(this._repoTracker.onDidAddOrUpdateRepo(info => {
@@ -243,10 +243,6 @@ export class CodeSearchChunkSearch extends Disposable {
243243
// Update external ingest index with the code search repo roots (if external ingest is enabled)
244244
if (this.isExternalIngestEnabled()) {
245245
this.updateExternalIngestRoots();
246-
}
247-
248-
// Initialize external ingest index if enabled
249-
if (this.isExternalIngestEnabled()) {
250246
this._register(this._externalIngestIndex.value.onDidChangeState(() => {
251247
this._onDidChangeIndexState.fire();
252248
}));
@@ -262,15 +258,14 @@ export class CodeSearchChunkSearch extends Disposable {
262258
await this._initializePromise;
263259
}
264260

265-
/**
266-
* Updates the external ingest index with the current code search repo roots.
267-
* Files under these roots will be excluded from external ingest indexing.
268-
*/
269-
private updateExternalIngestRoots(): void {
270-
const readyRepos = Array.from(this._codeSearchRepos.values())
261+
private getExternalIngestRoots(): URI[] {
262+
return Array.from(this._codeSearchRepos.values())
271263
.filter(entry => entry.repo.status === CodeSearchRepoStatus.Ready)
272264
.map(entry => entry.repo.repoInfo.rootUri);
273-
this._externalIngestIndex.rawValue?.updateCodeSearchRoots(readyRepos);
265+
}
266+
267+
private updateExternalIngestRoots(): void {
268+
this._externalIngestIndex.rawValue?.updateCodeSearchRoots(this.getExternalIngestRoots());
274269
}
275270

276271
private isInitializing(): boolean {

src/platform/workspaceChunkSearch/node/codeSearch/externalIngestIndex.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class ExternalIngestIndex extends Disposable {
145145

146146
constructor(
147147
client: IExternalIngestClient,
148+
initialCodeSearchRoots: URI[],
148149
@IEnvService private readonly _envService: IEnvService,
149150
@IFileSystemService private readonly _fileSystemService: IFileSystemService,
150151
@IIgnoreService private readonly _ignoreService: IIgnoreService,
@@ -160,6 +161,10 @@ export class ExternalIngestIndex extends Disposable {
160161
this._client = client;
161162
this.workspaceFolderIdMap = new WorkspaceFolderIdMap(this._vsExtensionContext.workspaceState);
162163

164+
for (const root of initialCodeSearchRoots) {
165+
this._codeSearchRepoRoots.add(root);
166+
}
167+
163168
let dbPath: string;
164169
if (debug || !this._vsExtensionContext.storageUri || this._vsExtensionContext.storageUri.scheme !== Schemas.file) {
165170
dbPath = ':memory:';

src/platform/workspaceChunkSearch/test/node/externalIngest.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function createExternalIngestIndex(
175175
client?: IExternalIngestClient,
176176
): ExternalIngestIndex {
177177
const resolvedClient = client ?? instantiationService.createInstance(ExternalIngestClient);
178-
return instantiationService.createInstance(ExternalIngestIndex, resolvedClient);
178+
return instantiationService.createInstance(ExternalIngestIndex, resolvedClient, []);
179179
}
180180

181181
type MockExternalIngestClient = ReturnType<typeof createMockExternalIngestClient>;
@@ -217,7 +217,7 @@ suite('ExternalIngestIndex', () => {
217217

218218
const accessor = disposables.add(testingServiceCollection.createTestingAccessor());
219219
const instantiationService = accessor.get(IInstantiationService);
220-
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient));
220+
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient, []));
221221

222222
return { files, mockFs, mockClient, index };
223223
}
@@ -241,7 +241,7 @@ suite('ExternalIngestIndex', () => {
241241
const instantiationService = accessor.get(IInstantiationService);
242242

243243
const mockClient = createMockExternalIngestClient();
244-
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient));
244+
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient, []));
245245

246246
index.updateCodeSearchRoots([codeSearchRoot]);
247247

@@ -260,7 +260,7 @@ suite('ExternalIngestIndex', () => {
260260
const instantiationService = accessor.get(IInstantiationService);
261261

262262
const mockClient = createMockExternalIngestClient();
263-
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient));
263+
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient, []));
264264

265265
index.updateCodeSearchRoots([codeSearchRoot]);
266266

@@ -279,7 +279,7 @@ suite('ExternalIngestIndex', () => {
279279
const instantiationService = accessor.get(IInstantiationService);
280280

281281
const mockClient = createMockExternalIngestClient();
282-
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient));
282+
const index = disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient, []));
283283

284284
const file1 = URI.joinPath(root1, 'file.ts');
285285
const file2 = URI.joinPath(root2, 'file.ts');
@@ -299,7 +299,7 @@ suite('ExternalIngestIndex', () => {
299299
const instantiationService = accessor.get(IInstantiationService);
300300

301301
const mockClient = createMockExternalIngestClient();
302-
disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient));
302+
disposables.add(instantiationService.createInstance(ExternalIngestIndex, mockClient, []));
303303

304304
// The mock client is now injected - tests can verify what files would be ingested
305305
assert.strictEqual(mockClient.ingestedFiles.length, 0, 'No files ingested yet');
@@ -318,7 +318,7 @@ suite('ExternalIngestIndex', () => {
318318
testingServiceCollection.set(IWorkspaceService, new MockWorkspaceService([URI.file('/workspace')]));
319319
const customAccessor = disposables.add(testingServiceCollection.createTestingAccessor());
320320
const customInstantiationService = customAccessor.get(IInstantiationService);
321-
disposables.add(customInstantiationService.createInstance(ExternalIngestIndex, mockClient));
321+
disposables.add(customInstantiationService.createInstance(ExternalIngestIndex, mockClient, []));
322322

323323
// The mock file system and client are now injected
324324
// Tests can verify file operations and ingestion behavior

0 commit comments

Comments
 (0)