Skip to content

Commit 75e8699

Browse files
authored
Add extra type check in findFiles2 (microsoft#235692)
For microsoft/vscode-copilot-release#2493 Looking at the code I'm still not sure how this can happen but it seems like we end up trying to call `.map` on a value that is not an array. Adding a more explicit exception here to hopefully track this down
1 parent 2531455 commit 75e8699

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/vs/workbench/api/common/extHostWorkspace.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
468468
}
469469

470470
// todo: consider exclude baseURI if available
471-
return this._findFilesImpl(include, undefined, {
471+
return this._findFilesImpl({ type: 'include', value: include }, {
472472
exclude: [excludeString],
473473
maxResults,
474474
useExcludeSettings: useFileExcludes ? ExcludeSettingOptions.FilesExclude : ExcludeSettingOptions.None,
@@ -484,23 +484,26 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
484484
extensionId: ExtensionIdentifier,
485485
token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
486486
this._logService.trace(`extHostWorkspace#findFiles2New: fileSearch, extension: ${extensionId.value}, entryPoint: findFiles2New`);
487-
return this._findFilesImpl(undefined, filePatterns, options, token);
487+
return this._findFilesImpl({ type: 'filePatterns', value: filePatterns }, options, token);
488488
}
489489

490490
private async _findFilesImpl(
491491
// the old `findFiles` used `include` to query, but the new `findFiles2` uses `filePattern` to query.
492492
// `filePattern` is the proper way to handle this, since it takes less precedence than the ignore files.
493-
include: vscode.GlobPattern | undefined,
494-
filePatterns: vscode.GlobPattern[] | undefined,
493+
query: { type: 'include'; value: vscode.GlobPattern | undefined } | { type: 'filePatterns'; value: vscode.GlobPattern[] },
495494
options: vscode.FindFiles2Options,
496-
token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
497-
if (token && token.isCancellationRequested) {
495+
token: vscode.CancellationToken
496+
): Promise<vscode.Uri[]> {
497+
if (token.isCancellationRequested) {
498498
return Promise.resolve([]);
499499
}
500500

501+
const filePatternsToUse = query.type === 'include' ? [query.value] : query.value ?? [];
502+
if (!Array.isArray(filePatternsToUse)) {
503+
throw new Error(`Invalid file pattern provided ${filePatternsToUse}`);
504+
}
501505

502-
const filePatternsToUse = include !== undefined ? [include] : filePatterns;
503-
const queryOptions: QueryOptions<IFileQueryBuilderOptions>[] = filePatternsToUse?.map(filePattern => {
506+
const queryOptions: QueryOptions<IFileQueryBuilderOptions>[] = filePatternsToUse.map(filePattern => {
504507

505508
const excludePatterns = globsToISearchPatternBuilder(options.exclude);
506509

@@ -514,21 +517,22 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
514517
maxResults: options.maxResults,
515518
excludePattern: excludePatterns.length > 0 ? excludePatterns : undefined,
516519
_reason: 'startFileSearch',
517-
shouldGlobSearch: include ? undefined : true,
520+
shouldGlobSearch: query.type === 'include' ? undefined : true,
518521
};
519522

520523
const parseInclude = parseSearchExcludeInclude(GlobPattern.from(filePattern));
521524
const folderToUse = parseInclude?.folder;
522-
if (include) {
525+
if (query.type === 'include') {
523526
fileQueries.includePattern = parseInclude?.pattern;
524527
} else {
525528
fileQueries.filePattern = parseInclude?.pattern;
526529
}
530+
527531
return {
528532
folder: folderToUse,
529533
options: fileQueries
530534
};
531-
}) ?? [];
535+
});
532536

533537
return this._findFilesBase(queryOptions, token);
534538
}

0 commit comments

Comments
 (0)