From 5f36b0ea9ab48abc4be5a4b51124d0fede4d1630 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 4 Sep 2019 14:32:15 -0700 Subject: [PATCH] Fix rawSearchService to handle maxResults=0 correctly Fix #79909 --- .../services/search/node/rawSearchService.ts | 2 +- .../search/test/node/rawSearchService.test.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/services/search/node/rawSearchService.ts b/src/vs/workbench/services/search/node/rawSearchService.ts index 2a27d205aac..c0d0e6d6358 100644 --- a/src/vs/workbench/services/search/node/rawSearchService.ts +++ b/src/vs/workbench/services/search/node/rawSearchService.ts @@ -254,7 +254,7 @@ export class SearchService implements IRawSearchService { const query = prepareQuery(config.filePattern || ''); const compare = (matchA: IRawFileMatch, matchB: IRawFileMatch) => compareItemsByScore(matchA, matchB, query, true, FileMatchItemAccessor, scorerCache); - const maxResults = config.maxResults || Number.MAX_VALUE; + const maxResults = typeof config.maxResults === 'number' ? config.maxResults : Number.MAX_VALUE; return arrays.topAsync(results, compare, maxResults, 10000, token); } diff --git a/src/vs/workbench/services/search/test/node/rawSearchService.test.ts b/src/vs/workbench/services/search/test/node/rawSearchService.test.ts index 4060adff5f0..c0a85168b80 100644 --- a/src/vs/workbench/services/search/test/node/rawSearchService.test.ts +++ b/src/vs/workbench/services/search/test/node/rawSearchService.test.ts @@ -185,6 +185,25 @@ suite('RawSearchService', () => { assert.strictEqual(result.results.length, 1, 'Result'); }); + test('Handles maxResults=0 correctly', async function () { + this.timeout(testTimeout); + const service = new RawSearchService(); + + const query: IFileQuery = { + type: QueryType.File, + folderQueries: MULTIROOT_QUERIES, + maxResults: 0, + sortByScore: true, + includePattern: { + '*.txt': true, + '*.js': true + }, + }; + + const result = await DiskSearch.collectResultsFromEvent(service.fileSearch(query)); + assert.strictEqual(result.results.length, 0, 'Result'); + }); + test('Multi-root with include pattern and exists', async function () { this.timeout(testTimeout); const service = new RawSearchService();