Skip to content

Commit

Permalink
add TextSearchOptions, only search in folder contributed by provider, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 16, 2018
1 parent 205c49a commit 42de6cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ declare module 'vscode' {
isWordMatch?: boolean;
}

export interface TextSearchOptions {
includes: GlobPattern[];
excludes: GlobPattern[];
}

export interface TextSearchResult {
uri: Uri;
range: Range;
Expand Down Expand Up @@ -147,7 +152,7 @@ declare module 'vscode' {
// find files by names
// todo@joh, move into its own provider
findFiles?(query: string, progress: Progress<Uri>, token: CancellationToken): Thenable<void>;
provideTextSearchResults?(query: TextSearchQuery, include: GlobPattern, exclude: GlobPattern, progress: Progress<TextSearchResult>, token: CancellationToken): Thenable<void>;
provideTextSearchResults?(query: TextSearchQuery, options: TextSearchOptions, progress: Progress<TextSearchResult>, token: CancellationToken): Thenable<void>;
}

export namespace workspace {
Expand Down
21 changes: 18 additions & 3 deletions src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ISearchResultProvider, ISearchQuery, ISearchComplete, ISearchProgressIt
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { onUnexpectedError } from 'vs/base/common/errors';
import { values } from 'vs/base/common/map';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';

@extHostNamedCustomer(MainContext.MainThreadFileSystem)
export class MainThreadFileSystem implements MainThreadFileSystemShape {
Expand Down Expand Up @@ -103,12 +104,12 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv
constructor(
fileService: IFileService,
searchService: ISearchService,
scheme: string,
private readonly _scheme: string,
private readonly _handle: number,
private readonly _proxy: ExtHostFileSystemShape
) {
this._registrations = [
fileService.registerProvider(scheme, this),
fileService.registerProvider(_scheme, this),
searchService.registerSearchResultProvider(this),
];
}
Expand Down Expand Up @@ -170,14 +171,28 @@ class RemoteFileSystemProvider implements IFileSystemProvider, ISearchResultProv

search(query: ISearchQuery): PPromise<ISearchComplete, ISearchProgressItem> {

if (isFalsyOrEmpty(query.folderQueries)) {
return PPromise.as(undefined);
}

let includes = { ...query.includePattern };
let excludes = { ...query.excludePattern };

for (const folderQuery of query.folderQueries) {
if (folderQuery.folder.scheme === this._scheme) {
includes = { ...includes, ...folderQuery.includePattern };
excludes = { ...excludes, ...folderQuery.excludePattern };
}
}

return new PPromise((resolve, reject, report) => {

const search = new SearchOperation(report);
this._searches.set(search.id, search);

const promise = query.type === QueryType.File
? this._proxy.$findFiles(this._handle, search.id, query.filePattern)
: this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, undefined, undefined);
: this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, { excludes: Object.keys(excludes), includes: Object.keys(includes) });

promise.then(() => {
this._searches.delete(search.id);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export interface ExtHostFileSystemShape {
$readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>;
$rmdir(handle: number, resource: UriComponents): TPromise<void>;
$findFiles(handle: number, session: number, query: string): TPromise<void>;
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, include: string, exclude: string): TPromise<void>;
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, options: { includes: string[], excludes: string[] }): TPromise<void>;
}

export interface ExtHostExtensionServiceShape {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/node/extHostFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
};
return asWinJsPromise(token => provider.findFiles(query, progress, token));
}
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, include: string, exclude: string): TPromise<void> {
$provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, options: { includes: string[], excludes: string[] }): TPromise<void> {
const provider = this._provider.get(handle);
if (!provider.provideTextSearchResults) {
return TPromise.as(undefined);
Expand All @@ -151,6 +151,6 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
}]);
}
};
return asWinJsPromise(token => provider.provideTextSearchResults(pattern, include, exclude, progress, token));
return asWinJsPromise(token => provider.provideTextSearchResults(pattern, options, progress, token));
}
}

0 comments on commit 42de6cc

Please sign in to comment.