mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user