Introduce GlobPattern and adopt in DocumentFilter/FileWatcher/FileSearch (#34695)

* introduce IRelativePattern and use in extension API

* 💄

* docs

* introduce RelativePattern

* support RelativePattern also for file watcher

* also make findFiles support RelativePattern

* less type conversion

* add GlobPattern type and remove readonly

* make base a string

* fix setter access to RelativePattern

* fix npe when exclude is undefined

* fix findFiles: pattern seems to be matched against workspace always

* 💄

* clarify glob pattern matching
This commit is contained in:
Benjamin Pasero
2017-09-22 13:52:23 +02:00
committed by GitHub
parent 9e05d4b635
commit 3e9fa59616
11 changed files with 169 additions and 38 deletions

View File

@@ -6,7 +6,7 @@
import { isPromiseCanceledError } from 'vs/base/common/errors';
import URI from 'vs/base/common/uri';
import { ISearchService, QueryType, ISearchQuery } from 'vs/platform/search/common/search';
import { ISearchService, QueryType, ISearchQuery, IFolderQuery } from 'vs/platform/search/common/search';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { TPromise } from 'vs/base/common/winjs.base';
@@ -15,6 +15,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IExperimentService } from 'vs/platform/telemetry/common/experiments';
import { IRelativePattern } from 'vs/base/common/glob';
@extHostNamedCustomer(MainContext.MainThreadWorkspace)
export class MainThreadWorkspace implements MainThreadWorkspaceShape {
@@ -53,17 +54,25 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
// --- search ---
$startSearch(include: string, exclude: string, maxResults: number, requestId: number): Thenable<URI[]> {
$startSearch(include: string | IRelativePattern, exclude: string | IRelativePattern, maxResults: number, requestId: number): Thenable<URI[]> {
const workspace = this._contextService.getWorkspace();
if (!workspace.folders.length) {
return undefined;
}
let folderQueries: IFolderQuery[];
if (typeof include === 'string' || !include) {
folderQueries = workspace.folders.map(folder => ({ folder: folder.uri })); // absolute pattern: search across all folders
} else {
folderQueries = [{ folder: URI.file(include.base) }]; // relative pattern: search only in base folder
}
const query: ISearchQuery = {
folderQueries: workspace.folders.map(folder => ({ folder: folder.uri })),
folderQueries,
type: QueryType.File,
maxResults,
includePattern: { [include]: true },
excludePattern: { [exclude]: true },
includePattern: { [typeof include === 'string' ? include : !!include ? include.pattern : undefined]: true },
excludePattern: { [typeof exclude === 'string' ? exclude : !!exclude ? exclude.pattern : undefined]: true },
useRipgrep: this._experimentService.getExperiments().ripgrepQuickSearch
};
this._searchService.extendQuery(query);