@@ -13,6 +13,8 @@ import { URI } from 'vs/base/common/uri';
13
13
import { IFileMatch , IFileSearchProviderStats , IFolderQuery , ISearchCompleteStats , IFileQuery , QueryGlobTester , resolvePatternsForProvider , hasSiblingFn , excludeToGlobPattern , DEFAULT_MAX_SEARCH_RESULTS } from 'vs/workbench/services/search/common/search' ;
14
14
import { FileSearchProviderFolderOptions , FileSearchProviderNew , FileSearchProviderOptions } from 'vs/workbench/services/search/common/searchExtTypes' ;
15
15
import { TernarySearchTree } from 'vs/base/common/ternarySearchTree' ;
16
+ import { Disposable } from 'vs/base/common/lifecycle' ;
17
+ import { OldFileSearchProviderConverter } from 'vs/workbench/services/search/common/searchExtConversionTypes' ;
16
18
17
19
interface IInternalFileMatch {
18
20
base : URI ;
@@ -53,7 +55,7 @@ class FileSearchEngine {
53
55
54
56
private globalExcludePattern ?: glob . ParsedExpression ;
55
57
56
- constructor ( private config : IFileQuery , private provider : FileSearchProviderNew , private sessionToken ?: unknown ) {
58
+ constructor ( private config : IFileQuery , private provider : FileSearchProviderNew , private sessionLifecycle ?: SessionLifecycle ) {
57
59
this . filePattern = config . filePattern ;
58
60
this . includePattern = config . includePattern && glob . parse ( config . includePattern ) ;
59
61
this . maxResults = config . maxResults || undefined ;
@@ -116,10 +118,11 @@ class FileSearchEngine {
116
118
private async doSearch ( fqs : IFolderQuery < URI > [ ] , onResult : ( match : IInternalFileMatch ) => void ) : Promise < IFileSearchProviderStats | null > {
117
119
const cancellation = new CancellationTokenSource ( ) ;
118
120
const folderOptions = fqs . map ( fq => this . getSearchOptionsForFolder ( fq ) ) ;
121
+ const session = this . provider instanceof OldFileSearchProviderConverter ? this . sessionLifecycle ?. tokenSource . token : this . sessionLifecycle ?. obj ;
119
122
const options : FileSearchProviderOptions = {
120
123
folderOptions,
121
124
maxResults : this . config . maxResults ?? DEFAULT_MAX_SEARCH_RESULTS ,
122
- session : this . sessionToken
125
+ session
123
126
} ;
124
127
125
128
@@ -301,11 +304,30 @@ interface IInternalSearchComplete {
301
304
stats ?: IFileSearchProviderStats ;
302
305
}
303
306
307
+ /**
308
+ * For backwards compatibility, store both a cancellation token and a session object. The session object is the new implementation, where
309
+ */
310
+ class SessionLifecycle extends Disposable {
311
+ public readonly obj : object ;
312
+ public readonly tokenSource : CancellationTokenSource ;
313
+
314
+ constructor ( ) {
315
+ super ( ) ;
316
+ this . obj = new Object ( ) ;
317
+ this . tokenSource = new CancellationTokenSource ( ) ;
318
+ }
319
+
320
+ public override dispose ( ) : void {
321
+ this . tokenSource . cancel ( ) ;
322
+ super . dispose ( ) ;
323
+ }
324
+ }
325
+
304
326
export class FileSearchManager {
305
327
306
328
private static readonly BATCH_SIZE = 512 ;
307
329
308
- private readonly sessions = new Map < string , unknown > ( ) ;
330
+ private readonly sessions = new Map < string , SessionLifecycle > ( ) ;
309
331
310
332
fileSearch ( config : IFileQuery , provider : FileSearchProviderNew , onBatch : ( matches : IFileMatch [ ] ) => void , token : CancellationToken ) : Promise < ISearchCompleteStats > {
311
333
const sessionTokenSource = this . getSessionTokenSource ( config . cacheKey ) ;
@@ -333,17 +355,19 @@ export class FileSearchManager {
333
355
}
334
356
335
357
clearCache ( cacheKey : string ) : void {
358
+ // cancel the token
359
+ this . sessions . get ( cacheKey ) ?. dispose ( ) ;
336
360
// with no reference to this, it will be removed from WeakMaps
337
361
this . sessions . delete ( cacheKey ) ;
338
362
}
339
363
340
- private getSessionTokenSource ( cacheKey : string | undefined ) : unknown {
364
+ private getSessionTokenSource ( cacheKey : string | undefined ) : SessionLifecycle | undefined {
341
365
if ( ! cacheKey ) {
342
366
return undefined ;
343
367
}
344
368
345
369
if ( ! this . sessions . has ( cacheKey ) ) {
346
- this . sessions . set ( cacheKey , new Object ( ) ) ;
370
+ this . sessions . set ( cacheKey , new SessionLifecycle ( ) ) ;
347
371
}
348
372
349
373
return this . sessions . get ( cacheKey ) ;
0 commit comments