diff --git a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts index 7e36cdb1448..df14909d35f 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts @@ -162,6 +162,16 @@ class SearchOperation { ) { // } + + addMatch(resource: URI, match: ILineMatch): void { + if (!this.matches.has(resource.toString())) { + this.matches.set(resource.toString(), { resource, lineMatches: [] }); + } + if (match) { + this.matches.get(resource.toString()).lineMatches.push(match); + } + this.progress(this.matches.get(resource.toString())); + } } class RemoteSearchProvider implements ISearchResultProvider { @@ -199,26 +209,36 @@ class RemoteSearchProvider implements ISearchResultProvider { } } + let outer: TPromise; + 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) + outer = query.type === QueryType.File + ? this._proxy.$provideFileSearchResults(this._handle, search.id, query.filePattern) : this._proxy.$provideTextSearchResults(this._handle, search.id, query.contentPattern, { excludes: Object.keys(excludes), includes: Object.keys(includes) }); - promise.then(() => { + outer.then(() => { this._searches.delete(search.id); resolve(({ results: values(search.matches), stats: undefined })); }, err => { this._searches.delete(search.id); reject(err); }); + }, () => { + if (outer) { + outer.cancel(); + } }); } handleFindMatch(session: number, dataOrUri: UriComponents | [UriComponents, ILineMatch]): void { + if (!this._searches.has(session)) { + // ignore... + return; + } let resource: URI; let match: ILineMatch; @@ -229,12 +249,6 @@ class RemoteSearchProvider implements ISearchResultProvider { resource = URI.revive(dataOrUri); } - const { matches } = this._searches.get(session); - if (!matches.has(resource.toString())) { - matches.set(resource.toString(), { resource, lineMatches: [] }); - } - if (match) { - matches.get(resource.toString()).lineMatches.push(match); - } + this._searches.get(session).addMatch(resource, match); } } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index d864ba9693a..bc0fb0365d8 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -566,7 +566,7 @@ export interface ExtHostFileSystemShape { $mkdir(handle: number, resource: UriComponents): TPromise; $readdir(handle: number, resource: UriComponents): TPromise<[UriComponents, IStat][]>; $rmdir(handle: number, resource: UriComponents): TPromise; - $findFiles(handle: number, session: number, query: string): TPromise; + $provideFileSearchResults(handle: number, session: number, query: string): TPromise; $provideTextSearchResults(handle: number, session: number, pattern: IPatternInfo, options: { includes: string[], excludes: string[] }): TPromise; } diff --git a/src/vs/workbench/api/node/extHostFileSystem.ts b/src/vs/workbench/api/node/extHostFileSystem.ts index c137aa7b2c0..00dfa69b6df 100644 --- a/src/vs/workbench/api/node/extHostFileSystem.ts +++ b/src/vs/workbench/api/node/extHostFileSystem.ts @@ -134,7 +134,7 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { $rmdir(handle: number, resource: UriComponents): TPromise { return asWinJsPromise(token => this._fsProvider.get(handle).rmdir(URI.revive(resource))); } - $findFiles(handle: number, session: number, query: string): TPromise { + $provideFileSearchResults(handle: number, session: number, query: string): TPromise { const provider = this._searchProvider.get(handle); if (!provider.provideFileSearchResults) { return TPromise.as(undefined);