diff --git a/src/vs/workbench/services/search/node/textSearch.ts b/src/vs/workbench/services/search/node/textSearch.ts index 8043076b058..890eca5bd13 100644 --- a/src/vs/workbench/services/search/node/textSearch.ts +++ b/src/vs/workbench/services/search/node/textSearch.ts @@ -83,7 +83,7 @@ export class Engine implements ISearchEngine { const worker = this.workers[this.nextWorker]; this.nextWorker = (this.nextWorker + 1) % this.workers.length; - const maxResults = this.config.maxResults - this.numResults; + const maxResults = this.config.maxResults && (this.config.maxResults - this.numResults); worker.search({ absolutePaths: batch, maxResults }).then(result => { if (!result || this.limitReached || this.isCanceled) { return unwind(batchBytes); @@ -95,7 +95,7 @@ export class Engine implements ISearchEngine { onResult(m); }); - if (this.numResults >= this.config.maxResults) { + if (this.config.maxResults && this.numResults >= this.config.maxResults) { // It's possible to go over maxResults like this, but it's much simpler than trying to extract the exact number // of file matches, line matches, and matches within a line to == maxResults. this.limitReached = true; diff --git a/src/vs/workbench/services/search/node/worker/searchWorker.ts b/src/vs/workbench/services/search/node/worker/searchWorker.ts index 6cffa9828aa..a186d580107 100644 --- a/src/vs/workbench/services/search/node/worker/searchWorker.ts +++ b/src/vs/workbench/services/search/node/worker/searchWorker.ts @@ -48,14 +48,14 @@ export class SearchWorker implements ISearchWorker { search(args: ISearchWorkerSearchArgs): TPromise { // Queue this search to run after the current one return this.nextSearch = this.nextSearch - .then(() => searchBatch(args.absolutePaths, this.contentPattern, args.maxResults, this.fileEncoding)); + .then(() => searchBatch(args.absolutePaths, this.contentPattern, this.fileEncoding, args.maxResults)); } } /** * Searches some number of the given paths concurrently, and starts searches in other paths when those complete. */ -function searchBatch(absolutePaths: string[], contentPattern: RegExp, maxResults: number, fileEncoding: string): TPromise { +function searchBatch(absolutePaths: string[], contentPattern: RegExp, fileEncoding: string, maxResults?: number): TPromise { if (isCanceled) { return TPromise.wrap(null); } @@ -69,7 +69,7 @@ function searchBatch(absolutePaths: string[], contentPattern: RegExp, maxResults // Search in the given path, and when it's finished, search in the next path in absolutePaths const startSearchInFile = (absolutePath: string): TPromise => { - return searchInFile(absolutePath, contentPattern, maxResults - result.numMatches, fileEncoding).then(fileResult => { + return searchInFile(absolutePath, contentPattern, fileEncoding, maxResults && (maxResults - result.numMatches)).then(fileResult => { // Finish early if search is canceled if (isCanceled) { return; @@ -94,7 +94,7 @@ function searchBatch(absolutePaths: string[], contentPattern: RegExp, maxResults let batchPromises: TPromise[] = []; for (let i = 0; i < SearchWorker.CONCURRENT_SEARCH_PATHS && i < absolutePaths.length; i++) { - batchPromises.push(startSearchInFile(absolutePaths[i])); + batchPromises.push(startSearchInFile(absolutePaths.shift())); } TPromise.join(batchPromises).then(() => { @@ -109,7 +109,7 @@ interface IFileSearchResult { limitReached?: boolean; } -function searchInFile(absolutePath: string, contentPattern: RegExp, maxResults: number, fileEncoding: string): TPromise { +function searchInFile(absolutePath: string, contentPattern: RegExp, fileEncoding: string, maxResults?: number): TPromise { let fileMatch: FileMatch = null; let limitReached = false; let numMatches = 0; diff --git a/src/vs/workbench/services/search/node/worker/searchWorkerIpc.ts b/src/vs/workbench/services/search/node/worker/searchWorkerIpc.ts index 040f1a5b1d1..9b30d518437 100644 --- a/src/vs/workbench/services/search/node/worker/searchWorkerIpc.ts +++ b/src/vs/workbench/services/search/node/worker/searchWorkerIpc.ts @@ -5,10 +5,10 @@ 'use strict'; -import { PPromise, TPromise } from 'vs/base/common/winjs.base'; +import { TPromise } from 'vs/base/common/winjs.base'; import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { ISerializedFileMatch } from '../search'; -import { IProgress, ILineMatch, IPatternInfo, ISearchStats } from 'vs/platform/search/common/search'; +import { IPatternInfo } from 'vs/platform/search/common/search'; import { SearchWorker } from './searchWorker'; export interface ISearchWorkerConfig { @@ -19,7 +19,7 @@ export interface ISearchWorkerConfig { export interface ISearchWorkerSearchArgs { absolutePaths: string[]; - maxResults: number; + maxResults?: number; } export interface ISearchWorkerSearchResult { @@ -46,7 +46,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel { } call(command: string, arg?: any): TPromise { - switch(command) { + switch (command) { case 'initialize': return TPromise.wrap(this.worker.initialize(arg)); case 'search': return this.worker.search(arg); case 'cancel': return this.worker.cancel();