Skip to content

Commit 239f152

Browse files
authored
Merge pull request #4873 from mjbvz/dev/mjbvz/port-293c469f26665574cb4cdffb66f12d76dd594f8a
Make sure we still enable code search when only external ingest is available
2 parents 919d993 + bee14ab commit 239f152

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ export class CodeSearchChunkSearch extends Disposable {
275275
@LogExecTime(self => self._logService, 'CodeSearchChunkSearch::isAvailable')
276276
async isAvailable(searchTelemetryInfo?: TelemetryCorrelationId, canPrompt = false, token = CancellationToken.None): Promise<boolean> {
277277
const sw = new StopWatch();
278-
const checkResult = await this.doIsAvailableCheck(canPrompt, token);
278+
const codeSearchCheckResult = await this.isCodeSearchAvailable(canPrompt, token);
279+
if (this._isDisposed) {
280+
return false;
281+
}
282+
283+
const hasExternalIngest = !!this.isExternalIngestEnabled();
279284

280285
// Track where indexed repos are located related to the workspace
281286
const indexedRepoLocation = {
@@ -285,9 +290,9 @@ export class CodeSearchChunkSearch extends Disposable {
285290
unknownFolder: 0,
286291
};
287292

288-
if (checkResult.isOk()) {
293+
if (codeSearchCheckResult.isOk()) {
289294
const workspaceFolder = this._workspaceService.getWorkspaceFolders();
290-
for (const repo of checkResult.val.indexedRepos) {
295+
for (const repo of codeSearchCheckResult.val.indexedRepos) {
291296
if (workspaceFolder.some(folder => isEqual(repo.repoInfo.rootUri, folder))) {
292297
indexedRepoLocation.workspaceFolder++;
293298
} else if (workspaceFolder.some(folder => isEqualOrParent(folder, repo.repoInfo.rootUri))) {
@@ -306,9 +311,10 @@ export class CodeSearchChunkSearch extends Disposable {
306311
"comment": "Metadata about the code search availability check",
307312
"workspaceSearchSource": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Caller of the search" },
308313
"workspaceSearchCorrelationId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Correlation id for the search" },
309-
"unavailableReason": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Correlation id for the search" },
314+
"codeSearchUnavailableReason": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Reason why code search is unavailable" },
310315
"repoStatues": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Detailed info about the statues of the repos in the workspace" },
311316
"execTime": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "How long the check too to complete" },
317+
"hasExternalIngest": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether external ingest is enabled" },
312318
"indexedRepoCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of indexed repositories" },
313319
"notYetIndexedRepoCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of repositories that have not yet been indexed" },
314320
@@ -321,28 +327,38 @@ export class CodeSearchChunkSearch extends Disposable {
321327
this._telemetryService.sendMSFTTelemetryEvent('codeSearchChunkSearch.isAvailable', {
322328
workspaceSearchSource: searchTelemetryInfo?.callTracker,
323329
workspaceSearchCorrelationId: searchTelemetryInfo?.correlationId,
324-
unavailableReason: checkResult.isError() ? checkResult.err.unavailableReason : undefined,
325-
repoStatues: JSON.stringify(checkResult.isOk() ? checkResult.val.repoStatuses : checkResult.err.repoStatuses),
330+
codeSearchUnavailableReason: codeSearchCheckResult.isError() ? codeSearchCheckResult.err.unavailableReason : undefined,
331+
repoStatues: JSON.stringify(codeSearchCheckResult.isOk() ? codeSearchCheckResult.val.repoStatuses : codeSearchCheckResult.err.repoStatuses),
326332
}, {
327333
execTime: sw.elapsed(),
328-
indexedRepoCount: checkResult.isOk() ? checkResult.val.indexedRepos.length : 0,
329-
notYetIndexedRepoCount: checkResult.isOk() ? checkResult.val.notYetIndexedRepos.length : 0,
334+
hasExternalIngest: hasExternalIngest ? 1 : 0,
335+
indexedRepoCount: codeSearchCheckResult.isOk() ? codeSearchCheckResult.val.indexedRepos.length : 0,
336+
notYetIndexedRepoCount: codeSearchCheckResult.isOk() ? codeSearchCheckResult.val.notYetIndexedRepos.length : 0,
330337
'indexedRepoLocation.workspace': indexedRepoLocation.workspaceFolder,
331338
'indexedRepoLocation.parent': indexedRepoLocation.parentFolder,
332339
'indexedRepoLocation.sub': indexedRepoLocation.subFolder,
333340
'indexedRepoLocation.unknown': indexedRepoLocation.unknownFolder,
334341
});
335342

336-
if (checkResult.isError()) {
337-
this._logService.debug(`CodeSearchChunkSearch.isAvailable: false. ${checkResult.err.unavailableReason}`);
343+
if (codeSearchCheckResult.isError()) {
344+
this._logService.debug(`CodeSearchChunkSearch.isAvailable: codeSearchCheckResult returned error: ${codeSearchCheckResult.err.unavailableReason}`);
345+
}
346+
347+
if (codeSearchCheckResult.isOk()) {
348+
this._logService.debug(`CodeSearchChunkSearch.isAvailable: true since code search is available`);
349+
return true;
350+
}
351+
352+
if (hasExternalIngest) {
353+
this._logService.debug(`CodeSearchChunkSearch.isAvailable: true since external ingest is enabled`);
338354
} else {
339-
this._logService.debug(`CodeSearchChunkSearch.isAvailable: true`);
355+
this._logService.debug(`CodeSearchChunkSearch.isAvailable: false since external ingest is not enabled and no code search repos found`);
340356
}
341357

342-
return checkResult.isOk();
358+
return hasExternalIngest;
343359
}
344360

345-
private async doIsAvailableCheck(canPrompt = false, token: CancellationToken): Promise<Result<AvailableSuccessMetadata, AvailableFailureMetadata>> {
361+
private async isCodeSearchAvailable(canPrompt = false, token: CancellationToken): Promise<Result<AvailableSuccessMetadata, AvailableFailureMetadata>> {
346362
if (!this.isCodeSearchEnabled()) {
347363
return Result.error<AvailableFailureMetadata>({ unavailableReason: 'Disabled by experiment', repoStatuses: {} });
348364
}

0 commit comments

Comments
 (0)