diff --git a/src/vs/workbench/api/test/node/extHostSearch.test.ts b/src/vs/workbench/api/test/node/extHostSearch.test.ts index 9ec2c6b..2be2d08 100644 --- a/src/vs/workbench/api/test/node/extHostSearch.test.ts +++ b/src/vs/workbench/api/test/node/extHostSearch.test.ts @@ -293,6 +293,20 @@ suite('ExtHostSearch', () => { disposables.forEach(d => d?.dispose()); }); + test('session is defined when there is no cache key', async () => { + let session: object | undefined; + disposables.add(extHostSearch.registerFileSearchProvider('file', { + provideFileSearchResults(pattern: string, options: vscode.FileSearchProviderOptions, token: vscode.CancellationToken): Promise { + session = options.session; + return Promise.resolve([]); + } + })); + await rpcProtocol.sync(); + + await runFileSearch(getSimpleQuery()); + assert.strictEqual(typeof session, 'object'); + }); + test('provider returns null', async () => { await registerTestFileSearchProvider({ provideFileSearchResults(query: vscode.FileSearchQuery, options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise { diff --git a/src/vs/workbench/services/search/common/fileSearchManager.ts b/src/vs/workbench/services/search/common/fileSearchManager.ts index 1a10161..e47210e 100644 --- a/src/vs/workbench/services/search/common/fileSearchManager.ts +++ b/src/vs/workbench/services/search/common/fileSearchManager.ts @@ -347,7 +347,11 @@ export class FileSearchManager { onBatch(batch.map(m => this.rawMatchToSearchItem(m))); }; - return this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult, token).then( + return this.doSearch(engine, FileSearchManager.BATCH_SIZE, onInternalResult, token).finally(() => { + if (!config.cacheKey) { + sessionTokenSource.cancel(); + } + }).then( result => { return { limitHit: result.limitHit, @@ -369,16 +373,16 @@ export class FileSearchManager { this.sessions.delete(cacheKey); } - private getSessionTokenSource(cacheKey: string | undefined): SessionLifecycle | undefined { + private getSessionTokenSource(cacheKey: string | undefined): SessionLifecycle { if (!cacheKey) { - return undefined; + return new SessionLifecycle(); } if (!this.sessions.has(cacheKey)) { this.sessions.set(cacheKey, new SessionLifecycle()); } - return this.sessions.get(cacheKey); + return this.sessions.get(cacheKey)!; } private rawMatchToSearchItem(match: IInternalFileMatch): IFileMatch {