提交 c4f336d1 编写于 作者: R Rob Lourens

Fix #53887 - remove remaining PPromise usage in search

上级 74c270e8
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
'use strict'; 'use strict';
import { isFalsyOrEmpty } from 'vs/base/common/arrays'; import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { values } from 'vs/base/common/map'; import { values } from 'vs/base/common/map';
import URI, { UriComponents } from 'vs/base/common/uri'; import URI, { UriComponents } from 'vs/base/common/uri';
import { PPromise, TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { IFileMatch, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType, IRawFileMatch2, ISearchCompleteStats } from 'vs/platform/search/common/search'; import { IFileMatch, IRawFileMatch2, ISearchComplete, ISearchCompleteStats, ISearchProgressItem, ISearchQuery, ISearchResultProvider, ISearchService, QueryType } from 'vs/platform/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { ExtHostContext, ExtHostSearchShape, IExtHostContext, MainContext, MainThreadSearchShape } from '../node/extHost.protocol'; import { ExtHostContext, ExtHostSearchShape, IExtHostContext, MainContext, MainThreadSearchShape } from '../node/extHost.protocol';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@extHostNamedCustomer(MainContext.MainThreadSearch) @extHostNamedCustomer(MainContext.MainThreadSearch)
export class MainThreadSearch implements MainThreadSearchShape { export class MainThreadSearch implements MainThreadSearchShape {
...@@ -100,7 +100,7 @@ class RemoteSearchProvider implements ISearchResultProvider, IDisposable { ...@@ -100,7 +100,7 @@ class RemoteSearchProvider implements ISearchResultProvider, IDisposable {
search(query: ISearchQuery, onProgress?: (p: ISearchProgressItem) => void): TPromise<ISearchComplete> { search(query: ISearchQuery, onProgress?: (p: ISearchProgressItem) => void): TPromise<ISearchComplete> {
if (isFalsyOrEmpty(query.folderQueries)) { if (isFalsyOrEmpty(query.folderQueries)) {
return PPromise.as(undefined); return TPromise.as(undefined);
} }
const folderQueriesForScheme = query.folderQueries.filter(fq => fq.folder.scheme === this._scheme); const folderQueriesForScheme = query.folderQueries.filter(fq => fq.folder.scheme === this._scheme);
......
...@@ -10,7 +10,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage'; ...@@ -10,7 +10,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
import * as glob from 'vs/base/common/glob'; import * as glob from 'vs/base/common/glob';
import * as resources from 'vs/base/common/resources'; import * as resources from 'vs/base/common/resources';
import URI, { UriComponents } from 'vs/base/common/uri'; import URI, { UriComponents } from 'vs/base/common/uri';
import { PPromise, TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import * as extfs from 'vs/base/node/extfs'; import * as extfs from 'vs/base/node/extfs';
import { IFileMatch, IFolderQuery, IPatternInfo, IRawSearchQuery, ISearchCompleteStats, ISearchQuery } from 'vs/platform/search/common/search'; import { IFileMatch, IFolderQuery, IPatternInfo, IRawSearchQuery, ISearchCompleteStats, ISearchQuery } from 'vs/platform/search/common/search';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
...@@ -58,12 +58,9 @@ export class ExtHostSearch implements ExtHostSearchShape { ...@@ -58,12 +58,9 @@ export class ExtHostSearch implements ExtHostSearchShape {
} }
const query = reviveQuery(rawQuery); const query = reviveQuery(rawQuery);
return this._fileSearchManager.fileSearch(query, provider).then( return this._fileSearchManager.fileSearch(query, provider, progress => {
null, this._proxy.$handleFileMatch(handle, session, progress.map(p => p.resource));
null, });
progress => {
this._proxy.$handleFileMatch(handle, session, progress.map(p => p.resource));
});
} }
$clearCache(handle: number, cacheKey: string): TPromise<void> { $clearCache(handle: number, cacheKey: string): TPromise<void> {
...@@ -84,12 +81,7 @@ export class ExtHostSearch implements ExtHostSearchShape { ...@@ -84,12 +81,7 @@ export class ExtHostSearch implements ExtHostSearchShape {
const query = reviveQuery(rawQuery); const query = reviveQuery(rawQuery);
const engine = new TextSearchEngine(pattern, query, provider, this._extfs); const engine = new TextSearchEngine(pattern, query, provider, this._extfs);
return engine.search().then( return engine.search(progress => this._proxy.$handleTextMatch(handle, session, progress));
null,
null,
progress => {
this._proxy.$handleTextMatch(handle, session, progress);
});
} }
} }
...@@ -380,11 +372,11 @@ class TextSearchEngine { ...@@ -380,11 +372,11 @@ class TextSearchEngine {
this.activeCancellationTokens = new Set(); this.activeCancellationTokens = new Set();
} }
public search(): PPromise<{ limitHit: boolean }, IFileMatch[]> { public search(onProgress: (matches: IFileMatch[]) => void): TPromise<{ limitHit: boolean }> {
const folderQueries = this.config.folderQueries; const folderQueries = this.config.folderQueries;
return new PPromise<{ limitHit: boolean }, IFileMatch[]>((resolve, reject, _onResult) => { return new TPromise<{ limitHit: boolean }>((resolve, reject) => {
this.collector = new TextSearchResultsCollector(_onResult); this.collector = new TextSearchResultsCollector(onProgress);
const onResult = (match: vscode.TextSearchResult, folderIdx: number) => { const onResult = (match: vscode.TextSearchResult, folderIdx: number) => {
if (this.isCanceled) { if (this.isCanceled) {
...@@ -403,8 +395,8 @@ class TextSearchEngine { ...@@ -403,8 +395,8 @@ class TextSearchEngine {
}; };
// For each root folder // For each root folder
PPromise.join(folderQueries.map((fq, i) => { TPromise.join(folderQueries.map((fq, i) => {
return this.searchInFolder(fq).then(null, null, r => onResult(r, i)); return this.searchInFolder(fq, r => onResult(r, i));
})).then(() => { })).then(() => {
this.collector.flush(); this.collector.flush();
resolve({ limitHit: this.isLimitHit }); resolve({ limitHit: this.isLimitHit });
...@@ -418,9 +410,9 @@ class TextSearchEngine { ...@@ -418,9 +410,9 @@ class TextSearchEngine {
}); });
} }
private searchInFolder(folderQuery: IFolderQuery<URI>): PPromise<void, vscode.TextSearchResult> { private searchInFolder(folderQuery: IFolderQuery<URI>, onResult: (result: vscode.TextSearchResult) => void): TPromise<void> {
let cancellation = new CancellationTokenSource(); let cancellation = new CancellationTokenSource();
return new PPromise((resolve, reject, onResult) => { return new TPromise((resolve, reject) => {
const queryTester = new QueryGlobTester(this.config, folderQuery); const queryTester = new QueryGlobTester(this.config, folderQuery);
const testingPs = []; const testingPs = [];
...@@ -532,10 +524,10 @@ class FileSearchEngine { ...@@ -532,10 +524,10 @@ class FileSearchEngine {
this.activeCancellationTokens = new Set(); this.activeCancellationTokens = new Set();
} }
public search(): PPromise<IInternalSearchComplete, IInternalFileMatch> { public search(_onResult: (match: IInternalFileMatch) => void): TPromise<IInternalSearchComplete> {
const folderQueries = this.config.folderQueries; const folderQueries = this.config.folderQueries;
return new PPromise((resolve, reject, _onResult) => { return new TPromise((resolve, reject) => {
const onResult = (match: IInternalFileMatch) => { const onResult = (match: IInternalFileMatch) => {
this.resultCount++; this.resultCount++;
_onResult(match); _onResult(match);
...@@ -562,8 +554,8 @@ class FileSearchEngine { ...@@ -562,8 +554,8 @@ class FileSearchEngine {
} }
// For each root folder // For each root folder
PPromise.join(folderQueries.map(fq => { TPromise.join(folderQueries.map(fq => {
return this.searchInFolder(fq).then(null, null, onResult); return this.searchInFolder(fq, onResult);
})).then(cacheKeys => { })).then(cacheKeys => {
resolve({ limitHit: this.isLimitHit, cacheKeys }); resolve({ limitHit: this.isLimitHit, cacheKeys });
}, (errs: Error[]) => { }, (errs: Error[]) => {
...@@ -576,9 +568,9 @@ class FileSearchEngine { ...@@ -576,9 +568,9 @@ class FileSearchEngine {
}); });
} }
private searchInFolder(fq: IFolderQuery<URI>): PPromise<string, IInternalFileMatch> { private searchInFolder(fq: IFolderQuery<URI>, onResult: (match: IInternalFileMatch) => void): TPromise<string> {
let cancellation = new CancellationTokenSource(); let cancellation = new CancellationTokenSource();
return new PPromise((resolve, reject, onResult) => { return new TPromise((resolve, reject) => {
const options = this.getSearchOptionsForFolder(fq); const options = this.getSearchOptionsForFolder(fq);
const tree = this.initDirectoryTree(); const tree = this.initDirectoryTree();
...@@ -748,12 +740,16 @@ class FileSearchManager { ...@@ -748,12 +740,16 @@ class FileSearchManager {
private readonly expandedCacheKeys = new Map<string, string[]>(); private readonly expandedCacheKeys = new Map<string, string[]>();
fileSearch(config: ISearchQuery, provider: vscode.SearchProvider): PPromise<ISearchCompleteStats, IFileMatch[]> { fileSearch(config: ISearchQuery, provider: vscode.SearchProvider, onResult: (matches: IFileMatch[]) => void): TPromise<ISearchCompleteStats> {
let searchP: PPromise; let searchP: TPromise;
return new PPromise<ISearchCompleteStats, IFileMatch[]>((c, e, p) => { return new TPromise<ISearchCompleteStats>((c, e) => {
const engine = new FileSearchEngine(config, provider); const engine = new FileSearchEngine(config, provider);
searchP = this.doSearch(engine, FileSearchManager.BATCH_SIZE).then( const onInternalResult = (progress: IInternalFileMatch[]) => {
onResult(progress.map(m => this.rawMatchToSearchItem(m)));
};
searchP = this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult).then(
result => { result => {
if (config.cacheKey) { if (config.cacheKey) {
this.expandedCacheKeys.set(config.cacheKey, result.cacheKeys); this.expandedCacheKeys.set(config.cacheKey, result.cacheKeys);
...@@ -763,10 +759,7 @@ class FileSearchManager { ...@@ -763,10 +759,7 @@ class FileSearchManager {
limitHit: result.limitHit limitHit: result.limitHit
}); });
}, },
e, e);
progress => {
p(progress.map(m => this.rawMatchToSearchItem(m)));
});
}, () => { }, () => {
if (searchP) { if (searchP) {
searchP.cancel(); searchP.cancel();
...@@ -789,29 +782,31 @@ class FileSearchManager { ...@@ -789,29 +782,31 @@ class FileSearchManager {
}; };
} }
private doSearch(engine: FileSearchEngine, batchSize: number): PPromise<IInternalSearchComplete, IInternalFileMatch[]> { private doSearch(engine: FileSearchEngine, batchSize: number, onResultBatch: (matches: IInternalFileMatch[]) => void): TPromise<IInternalSearchComplete> {
return new PPromise((c, e, p) => { return new TPromise((c, e) => {
const _onResult = match => {
if (match) {
batch.push(match);
if (batchSize > 0 && batch.length >= batchSize) {
onResultBatch(batch);
batch = [];
}
}
};
let batch: IInternalFileMatch[] = []; let batch: IInternalFileMatch[] = [];
engine.search().then(result => { engine.search(_onResult).then(result => {
if (batch.length) { if (batch.length) {
p(batch); onResultBatch(batch);
} }
c(result); c(result);
}, error => { }, error => {
if (batch.length) { if (batch.length) {
p(batch); onResultBatch(batch);
} }
e(error); e(error);
}, match => {
if (match) {
batch.push(match);
if (batchSize > 0 && batch.length >= batchSize) {
p(batch);
batch = [];
}
}
}); });
}, () => { }, () => {
engine.cancel(); engine.cancel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册