Cleanup GlobPattern handling in extension host (#140689)

* rewrite `NotebookExclusiveDocumentPattern` handling (#140491)

* 💄

* also fix #140707

* address feedback
This commit is contained in:
Benjamin Pasero
2022-01-17 14:21:10 +01:00
committed by GitHub
parent 9bba389a22
commit 579e0a39c2
8 changed files with 85 additions and 82 deletions

View File

@@ -24,11 +24,12 @@ import { Workspace, WorkspaceFolder } from 'vs/platform/workspace/common/workspa
import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { Range, RelativePattern } from 'vs/workbench/api/common/extHostTypes';
import { GlobPattern } from 'vs/workbench/api/common/extHostTypeConverters';
import { Range } from 'vs/workbench/api/common/extHostTypes';
import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/queryBuilder';
import { IRawFileMatch2, resultIsMatch } from 'vs/workbench/services/search/common/search';
import * as vscode from 'vscode';
import { ExtHostWorkspaceShape, IWorkspaceData, MainContext, MainThreadMessageOptions, MainThreadMessageServiceShape, MainThreadWorkspaceShape } from './extHost.protocol';
import { ExtHostWorkspaceShape, IRelativePatternDto, IWorkspaceData, MainContext, MainThreadMessageOptions, MainThreadMessageServiceShape, MainThreadWorkspaceShape } from './extHost.protocol';
export interface IExtHostWorkspaceProvider {
getWorkspaceFolder2(uri: vscode.Uri, resolveParent?: boolean): Promise<vscode.WorkspaceFolder | undefined>;
@@ -433,7 +434,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
/**
* Note, null/undefined have different and important meanings for "exclude"
*/
findFiles(include: string | RelativePattern | undefined, exclude: vscode.GlobPattern | null | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
findFiles(include: vscode.GlobPattern | undefined, exclude: vscode.GlobPattern | null | undefined, maxResults: number | undefined, extensionId: ExtensionIdentifier, token: vscode.CancellationToken = CancellationToken.None): Promise<vscode.Uri[]> {
this._logService.trace(`extHostWorkspace#findFiles: fileSearch, extension: ${extensionId.value}, entryPoint: findFiles`);
let excludePatternOrDisregardExcludes: string | false | undefined = undefined;
@@ -451,7 +452,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
return Promise.resolve([]);
}
const { includePattern, folder } = parseSearchInclude(include);
const { includePattern, folder } = parseSearchInclude(GlobPattern.from(include));
return this._proxy.$startFileSearch(
withUndefinedAsNull(includePattern),
withUndefinedAsNull(folder),
@@ -474,7 +475,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
} :
options.previewOptions;
const { includePattern, folder } = parseSearchInclude(options.include);
const { includePattern, folder } = parseSearchInclude(GlobPattern.from(options.include));
const excludePattern = (typeof options.exclude === 'string') ? options.exclude :
options.exclude ? options.exclude.pattern : undefined;
const queryOptions: ITextQueryBuilderOptions = {
@@ -579,7 +580,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
export const IExtHostWorkspace = createDecorator<IExtHostWorkspace>('IExtHostWorkspace');
export interface IExtHostWorkspace extends ExtHostWorkspace, ExtHostWorkspaceShape, IExtHostWorkspaceProvider { }
function parseSearchInclude(include: RelativePattern | vscode.GlobPattern | string | undefined): { includePattern?: string, folder?: URI; } {
function parseSearchInclude(include: string | IRelativePatternDto | undefined | null): { includePattern?: string, folder?: URI; } {
let includePattern: string | undefined;
let includeFolder: URI | undefined;
if (include) {
@@ -587,7 +588,7 @@ function parseSearchInclude(include: RelativePattern | vscode.GlobPattern | stri
includePattern = include;
} else {
includePattern = include.pattern;
includeFolder = include.baseUri;
includeFolder = URI.revive(include.baseUri);
}
}