Skip to content

Commit

Permalink
Merge pull request #236267 from mjbvz/port-find-fix
Browse files Browse the repository at this point in the history
Add extra type check in `findFiles2` (#235692)
  • Loading branch information
mjbvz authored Dec 17, 2024
2 parents f216365 + 9083f01 commit 42b2661
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/vs/workbench/api/common/extHostWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
}

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

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

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

const filePatternsToUse = include !== undefined ? [include] : filePatterns;
const queryOptions: QueryOptions<IFileQueryBuilderOptions>[] = filePatternsToUse?.map(filePattern => {
const queryOptions: QueryOptions<IFileQueryBuilderOptions>[] = filePatternsToUse.map(filePattern => {

const excludePatterns = globsToISearchPatternBuilder(options.exclude);

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

const parseInclude = parseSearchExcludeInclude(GlobPattern.from(filePattern));
const folderToUse = parseInclude?.folder;
if (include) {
if (query.type === 'include') {
fileQueries.includePattern = parseInclude?.pattern;
} else {
fileQueries.filePattern = parseInclude?.pattern;
}

return {
folder: folderToUse,
options: fileQueries
};
}) ?? [];
});

return this._findFilesBase(queryOptions, token);
}
Expand Down

0 comments on commit 42b2661

Please sign in to comment.