From 21082bf9ef3aedbdbf8ecfd6c30d7b4c5a6eed28 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 3 Jul 2018 14:46:41 -0700 Subject: [PATCH] Search provider - give different cacheKeys for different folders --- src/vs/workbench/api/node/extHostSearch.ts | 5 ++- .../api/extHostSearch.test.ts | 44 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/api/node/extHostSearch.ts b/src/vs/workbench/api/node/extHostSearch.ts index aeba2749c5f..4f9c48ed0eb 100644 --- a/src/vs/workbench/api/node/extHostSearch.ts +++ b/src/vs/workbench/api/node/extHostSearch.ts @@ -621,7 +621,10 @@ class FileSearchEngine { .then(() => { this.activeCancellationTokens.add(cancellation); return this.provider.provideFileSearchResults( - { cacheKey: this.config.cacheKey, pattern: this.config.filePattern || '' }, + { + pattern: this.config.filePattern || '', + cacheKey: this.config.cacheKey + '_' + fq.folder.fsPath + }, options, { report: onProviderResult }, cancellation.token); diff --git a/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts b/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts index 3c5cceb4ce7..49d33da63b2 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts @@ -666,27 +666,33 @@ suite('ExtHostSearch', () => { compareURIs(results, reportedResults); }); - // Mock fs? - // test('Returns result for absolute path', async () => { - // const queriedFile = makeFileResult(rootFolderA, 'file2.ts'); - // const reportedResults = [ - // makeFileResult(rootFolderA, 'file1.ts'), - // queriedFile, - // makeFileResult(rootFolderA, 'file3.ts'), - // ]; + test('uses different cache keys for different folders', async () => { + const cacheKeys: string[] = []; + await registerTestSearchProvider({ + provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, progress: vscode.Progress, token: vscode.CancellationToken): Thenable { + cacheKeys.push(query.cacheKey); + return TPromise.wrap(null); + } + }); - // await registerTestSearchProvider({ - // provideFileSearchResults(options: vscode.FileSearchOptions, progress: vscode.Progress, token: vscode.CancellationToken): Thenable { - // reportedResults.forEach(r => progress.report(r)); - // return TPromise.wrap(null); - // } - // }); + const query: ISearchQuery = { + type: QueryType.File, + filePattern: '', + cacheKey: 'cacheKey', + folderQueries: [ + { + folder: rootFolderA + }, + { + folder: rootFolderB + } + ] + }; - // const queriedFilePath = queriedFile.fsPath; - // const { results } = await runFileSearch(getSimpleQuery(queriedFilePath)); - // assert.equal(results.length, 1); - // compareURIs(results, [queriedFile]); - // }); + await runFileSearch(query); + assert.equal(cacheKeys.length, 2); + assert.notEqual(cacheKeys[0], cacheKeys[1]); + }); }); suite('Text:', () => {