From 03cf7b9e7e9921c7d8e205fa94b6227e37280336 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 6 Nov 2018 15:52:08 -0800 Subject: [PATCH] #53526 - remove some TPromise references from search proc --- src/vs/base/common/glob.ts | 21 +++++++++---------- .../services/search/node/fileSearch.ts | 3 +-- .../services/search/node/rawSearchService.ts | 4 ++-- .../workbench/services/search/node/search.ts | 13 ++++++------ .../services/search/node/searchIpc.ts | 9 ++++---- .../services/search/node/textSearchManager.ts | 19 ++++++++--------- 6 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/vs/base/common/glob.ts b/src/vs/base/common/glob.ts index cb4771b2d3c..29828e1e7a6 100644 --- a/src/vs/base/common/glob.ts +++ b/src/vs/base/common/glob.ts @@ -8,7 +8,6 @@ import * as strings from 'vs/base/common/strings'; import * as paths from 'vs/base/common/paths'; import { LRUCache } from 'vs/base/common/map'; import { CharCode } from 'vs/base/common/charCode'; -import { TPromise } from 'vs/base/common/winjs.base'; import { isThenable } from 'vs/base/common/async'; export interface IExpression { @@ -248,7 +247,7 @@ const T5 = /^([\w\.-]+(\/[\w\.-]+)*)\/?$/; // something/else export type ParsedPattern = (path: string, basename?: string) => boolean; // The ParsedExpression returns a Promise iff hasSibling returns a Promise. -export type ParsedExpression = (path: string, basename?: string, hasSibling?: (name: string) => boolean | TPromise) => string | null | TPromise /* the matching pattern */; +export type ParsedExpression = (path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise) => string | null | Promise /* the matching pattern */; export interface IGlobOptions { /** @@ -258,14 +257,14 @@ export interface IGlobOptions { } interface ParsedStringPattern { - (path: string, basename: string): string | null | TPromise /* the matching pattern */; + (path: string, basename: string): string | null | Promise /* the matching pattern */; basenames?: string[]; patterns?: string[]; allBasenames?: string[]; allPaths?: string[]; } interface ParsedExpressionPattern { - (path: string, basename: string, name?: string, hasSibling?: (name: string) => boolean | TPromise): string | null | TPromise /* the matching pattern */; + (path: string, basename: string, name?: string, hasSibling?: (name: string) => boolean | Promise): string | null | Promise /* the matching pattern */; requiresSiblings?: boolean; allBasenames?: string[]; allPaths?: string[]; @@ -481,15 +480,15 @@ export function parse(arg1: string | IExpression | IRelativePattern, options: IG return parsedExpression(arg1, options); } -export function hasSiblingPromiseFn(siblingsFn?: () => TPromise) { +export function hasSiblingPromiseFn(siblingsFn?: () => Promise) { if (!siblingsFn) { return undefined; } - let siblings: TPromise>; + let siblings: Promise>; return (name: string) => { if (!siblings) { - siblings = (siblingsFn() || TPromise.as([])) + siblings = (siblingsFn() || Promise.resolve([])) .then(list => list ? listToMap(list) : {}); } return siblings.then(map => !!map[name]); @@ -530,9 +529,9 @@ export function isRelativePattern(obj: any): obj is IRelativePattern { */ export function parseToAsync(expression: IExpression, options?: IGlobOptions): ParsedExpression { const parsedExpression = parse(expression, options); - return (path: string, basename?: string, hasSibling?: (name: string) => boolean | TPromise): string | null | TPromise => { + return (path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise): string | null | Promise => { const result = parsedExpression(path, basename, hasSibling); - return result instanceof TPromise ? result : TPromise.as(result); + return isThenable(result) ? result : Promise.resolve(result); }; } @@ -584,7 +583,7 @@ function parsedExpression(expression: IExpression, options: IGlobOptions): Parse return resultExpression; } - const resultExpression: ParsedStringPattern = function (path: string, basename: string, hasSibling?: (name: string) => boolean | TPromise) { + const resultExpression: ParsedStringPattern = function (path: string, basename: string, hasSibling?: (name: string) => boolean | Promise) { let name: string | undefined = undefined; for (let i = 0, n = parsedPatterns.length; i < n; i++) { @@ -639,7 +638,7 @@ function parseExpressionPattern(pattern: string, value: any, options: IGlobOptio if (value) { const when = (value).when; if (typeof when === 'string') { - const result: ParsedExpressionPattern = (path: string, basename: string, name: string, hasSibling: (name: string) => boolean | TPromise) => { + const result: ParsedExpressionPattern = (path: string, basename: string, name: string, hasSibling: (name: string) => boolean | Promise) => { if (!hasSibling || !parsedPattern(path, basename)) { return null; } diff --git a/src/vs/workbench/services/search/node/fileSearch.ts b/src/vs/workbench/services/search/node/fileSearch.ts index 52deb2ff8aa..9981f33919c 100644 --- a/src/vs/workbench/services/search/node/fileSearch.ts +++ b/src/vs/workbench/services/search/node/fileSearch.ts @@ -19,7 +19,6 @@ import { StopWatch } from 'vs/base/common/stopwatch'; import * as strings from 'vs/base/common/strings'; import * as types from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import * as extfs from 'vs/base/node/extfs'; import * as flow from 'vs/base/node/flow'; import { IFileQuery, IFolderQuery, IProgress, ISearchEngineStats } from 'vs/platform/search/common/search'; @@ -697,7 +696,7 @@ class AbsoluteAndRelativeParsedExpression { this.relativeParsedExpr = relativeGlobExpr && glob.parse(relativeGlobExpr, { trimForExclusions: true }); } - public test(_path: string, basename?: string, hasSibling?: (name: string) => boolean | TPromise): string | TPromise { + public test(_path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise): string | Promise { return (this.relativeParsedExpr && this.relativeParsedExpr(_path, basename, hasSibling)) || (this.absoluteParsedExpr && this.absoluteParsedExpr(path.join(this.root, _path), basename, hasSibling)); } diff --git a/src/vs/workbench/services/search/node/rawSearchService.ts b/src/vs/workbench/services/search/node/rawSearchService.ts index 0a6f6efa94e..ee85063ce9f 100644 --- a/src/vs/workbench/services/search/node/rawSearchService.ts +++ b/src/vs/workbench/services/search/node/rawSearchService.ts @@ -377,9 +377,9 @@ export class SearchService implements IRawSearchService { }); } - public clearCache(cacheKey: string): TPromise { + public clearCache(cacheKey: string): Promise { delete this.caches[cacheKey]; - return TPromise.as(undefined); + return Promise.resolve(undefined); } /** diff --git a/src/vs/workbench/services/search/node/search.ts b/src/vs/workbench/services/search/node/search.ts index d2f0d04ab55..22cd4800928 100644 --- a/src/vs/workbench/services/search/node/search.ts +++ b/src/vs/workbench/services/search/node/search.ts @@ -5,7 +5,6 @@ import { Event } from 'vs/base/common/event'; import * as glob from 'vs/base/common/glob'; -import { TPromise } from 'vs/base/common/winjs.base'; import { IFileSearchStats, IFolderQuery, IProgress, IRawFileQuery, IRawTextQuery, ISearchEngineStats, ISearchQuery, ITextSearchMatch, ITextSearchStats, ITextSearchResult } from 'vs/platform/search/common/search'; import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; @@ -17,7 +16,7 @@ export interface ITelemetryEvent { export interface IRawSearchService { fileSearch(search: IRawFileQuery): Event; textSearch(search: IRawTextQuery): Event; - clearCache(cacheKey: string): TPromise; + clearCache(cacheKey: string): Promise; } export interface IRawFileMatch { @@ -170,10 +169,10 @@ export class QueryGlobTester { /** * Guaranteed async. */ - public includedInQuery(testPath: string, basename?: string, hasSibling?: (name: string) => boolean | TPromise): TPromise { + public includedInQuery(testPath: string, basename?: string, hasSibling?: (name: string) => boolean | Promise): Promise { const excludeP = this._parsedExcludeExpression ? - TPromise.as(this._parsedExcludeExpression(testPath, basename, hasSibling)).then(result => !!result) : - TPromise.wrap(false); + Promise.resolve(this._parsedExcludeExpression(testPath, basename, hasSibling)).then(result => !!result) : + Promise.resolve(false); return excludeP.then(excluded => { if (excluded) { @@ -181,8 +180,8 @@ export class QueryGlobTester { } return this._parsedIncludeExpression ? - TPromise.as(this._parsedIncludeExpression(testPath, basename, hasSibling)).then(result => !!result) : - TPromise.wrap(true); + Promise.resolve(this._parsedIncludeExpression(testPath, basename, hasSibling)).then(result => !!result) : + Promise.resolve(true); }).then(included => { return included; }); diff --git a/src/vs/workbench/services/search/node/searchIpc.ts b/src/vs/workbench/services/search/node/searchIpc.ts index 4703fa6648a..618f2f8c82c 100644 --- a/src/vs/workbench/services/search/node/searchIpc.ts +++ b/src/vs/workbench/services/search/node/searchIpc.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { Event } from 'vs/base/common/event'; -import { TPromise } from 'vs/base/common/winjs.base'; import { IChannel } from 'vs/base/parts/ipc/node/ipc'; import { IRawFileQuery, IRawTextQuery } from 'vs/platform/search/common/search'; import { IRawSearchService, ISerializedSearchComplete, ISerializedSearchProgressItem } from './search'; @@ -12,8 +11,8 @@ import { IRawSearchService, ISerializedSearchComplete, ISerializedSearchProgress export interface ISearchChannel extends IChannel { listen(event: 'fileSearch', search: IRawFileQuery): Event; listen(event: 'textSearch', search: IRawTextQuery): Event; - call(command: 'clearCache', cacheKey: string): TPromise; - call(command: string, arg: any): TPromise; + call(command: 'clearCache', cacheKey: string): Promise; + call(command: string, arg: any): Promise; } export class SearchChannel implements ISearchChannel { @@ -28,7 +27,7 @@ export class SearchChannel implements ISearchChannel { throw new Error('Event not found'); } - call(command: string, arg?: any): TPromise { + call(command: string, arg?: any): Promise { switch (command) { case 'clearCache': return this.service.clearCache(arg); } @@ -48,7 +47,7 @@ export class SearchChannelClient implements IRawSearchService { return this.channel.listen('textSearch', search); } - clearCache(cacheKey: string): TPromise { + clearCache(cacheKey: string): Promise { return this.channel.call('clearCache', cacheKey); } } \ No newline at end of file diff --git a/src/vs/workbench/services/search/node/textSearchManager.ts b/src/vs/workbench/services/search/node/textSearchManager.ts index 7eab65fba24..bef7553ed87 100644 --- a/src/vs/workbench/services/search/node/textSearchManager.ts +++ b/src/vs/workbench/services/search/node/textSearchManager.ts @@ -10,7 +10,6 @@ import { toErrorMessage } from 'vs/base/common/errorMessage'; import * as glob from 'vs/base/common/glob'; import * as resources from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; -import { TPromise } from 'vs/base/common/winjs.base'; import { toCanonicalName } from 'vs/base/node/encoding'; import * as extfs from 'vs/base/node/extfs'; import { IExtendedExtensionSearchOptions, IFileMatch, IFolderQuery, IPatternInfo, ISearchCompleteStats, ITextQuery, ITextSearchMatch, ITextSearchContext, ITextSearchResult } from 'vs/platform/search/common/search'; @@ -27,12 +26,12 @@ export class TextSearchManager { constructor(private query: ITextQuery, private provider: vscode.TextSearchProvider, private _extfs: typeof extfs = extfs) { } - public search(onProgress: (matches: IFileMatch[]) => void, token: CancellationToken): TPromise { + public search(onProgress: (matches: IFileMatch[]) => void, token: CancellationToken): Promise { const folderQueries = this.query.folderQueries || []; const tokenSource = new CancellationTokenSource(); token.onCancellationRequested(() => tokenSource.cancel()); - return new TPromise((resolve, reject) => { + return new Promise((resolve, reject) => { this.collector = new TextSearchResultsCollector(onProgress); let isCanceled = false; @@ -54,7 +53,7 @@ export class TextSearchManager { }; // For each root folder - TPromise.join(folderQueries.map((fq, i) => { + Promise.all(folderQueries.map((fq, i) => { return this.searchInFolder(fq, r => onResult(r, i), tokenSource.token); })).then(results => { tokenSource.dispose(); @@ -78,9 +77,9 @@ export class TextSearchManager { }); } - private searchInFolder(folderQuery: IFolderQuery, onResult: (result: vscode.TextSearchResult) => void, token: CancellationToken): TPromise { + private searchInFolder(folderQuery: IFolderQuery, onResult: (result: vscode.TextSearchResult) => void, token: CancellationToken): Promise { const queryTester = new QueryGlobTester(this.query, folderQuery); - const testingPs: TPromise[] = []; + const testingPs: Promise[] = []; const progress = { report: (result: vscode.TextSearchResult) => { // TODO: validate result.ranges vs result.preview.matches @@ -103,16 +102,16 @@ export class TextSearchManager { }; const searchOptions = this.getSearchOptionsForFolder(folderQuery); - return new TPromise(resolve => process.nextTick(resolve)) + return new Promise(resolve => process.nextTick(resolve)) .then(() => this.provider.provideTextSearchResults(patternInfoToQuery(this.query.contentPattern), searchOptions, progress, token)) .then(result => { - return TPromise.join(testingPs) + return Promise.all(testingPs) .then(() => result); }); } - private readdir(dirname: string): TPromise { - return new TPromise((resolve, reject) => { + private readdir(dirname: string): Promise { + return new Promise((resolve, reject) => { this._extfs.readdir(dirname, (err, files) => { if (err) { return reject(err); -- GitLab