@@ -468,7 +468,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
468
468
}
469
469
470
470
// todo: consider exclude baseURI if available
471
- return this . _findFilesImpl ( include , undefined , {
471
+ return this . _findFilesImpl ( { type : ' include' , value : include } , {
472
472
exclude : [ excludeString ] ,
473
473
maxResults,
474
474
useExcludeSettings : useFileExcludes ? ExcludeSettingOptions . FilesExclude : ExcludeSettingOptions . None ,
@@ -484,23 +484,26 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
484
484
extensionId : ExtensionIdentifier ,
485
485
token : vscode . CancellationToken = CancellationToken . None ) : Promise < vscode . Uri [ ] > {
486
486
this . _logService . trace ( `extHostWorkspace#findFiles2New: fileSearch, extension: ${ extensionId . value } , entryPoint: findFiles2New` ) ;
487
- return this . _findFilesImpl ( undefined , filePatterns , options , token ) ;
487
+ return this . _findFilesImpl ( { type : 'filePatterns' , value : filePatterns } , options , token ) ;
488
488
}
489
489
490
490
private async _findFilesImpl (
491
491
// the old `findFiles` used `include` to query, but the new `findFiles2` uses `filePattern` to query.
492
492
// `filePattern` is the proper way to handle this, since it takes less precedence than the ignore files.
493
- include : vscode . GlobPattern | undefined ,
494
- filePatterns : vscode . GlobPattern [ ] | undefined ,
493
+ query : { type : 'include' ; value : vscode . GlobPattern | undefined } | { type : 'filePatterns' ; value : vscode . GlobPattern [ ] } ,
495
494
options : vscode . FindFiles2Options ,
496
- token : vscode . CancellationToken = CancellationToken . None ) : Promise < vscode . Uri [ ] > {
497
- if ( token && token . isCancellationRequested ) {
495
+ token : vscode . CancellationToken
496
+ ) : Promise < vscode . Uri [ ] > {
497
+ if ( token . isCancellationRequested ) {
498
498
return Promise . resolve ( [ ] ) ;
499
499
}
500
500
501
+ const filePatternsToUse = query . type === 'include' ? [ query . value ] : query . value ?? [ ] ;
502
+ if ( ! Array . isArray ( filePatternsToUse ) ) {
503
+ throw new Error ( `Invalid file pattern provided ${ filePatternsToUse } ` ) ;
504
+ }
501
505
502
- const filePatternsToUse = include !== undefined ? [ include ] : filePatterns ;
503
- const queryOptions : QueryOptions < IFileQueryBuilderOptions > [ ] = filePatternsToUse ?. map ( filePattern => {
506
+ const queryOptions : QueryOptions < IFileQueryBuilderOptions > [ ] = filePatternsToUse . map ( filePattern => {
504
507
505
508
const excludePatterns = globsToISearchPatternBuilder ( options . exclude ) ;
506
509
@@ -514,21 +517,22 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
514
517
maxResults : options . maxResults ,
515
518
excludePattern : excludePatterns . length > 0 ? excludePatterns : undefined ,
516
519
_reason : 'startFileSearch' ,
517
- shouldGlobSearch : include ? undefined : true ,
520
+ shouldGlobSearch : query . type === ' include' ? undefined : true ,
518
521
} ;
519
522
520
523
const parseInclude = parseSearchExcludeInclude ( GlobPattern . from ( filePattern ) ) ;
521
524
const folderToUse = parseInclude ?. folder ;
522
- if ( include ) {
525
+ if ( query . type === ' include' ) {
523
526
fileQueries . includePattern = parseInclude ?. pattern ;
524
527
} else {
525
528
fileQueries . filePattern = parseInclude ?. pattern ;
526
529
}
530
+
527
531
return {
528
532
folder : folderToUse ,
529
533
options : fileQueries
530
534
} ;
531
- } ) ?? [ ] ;
535
+ } ) ;
532
536
533
537
return this . _findFilesBase ( queryOptions , token ) ;
534
538
}
0 commit comments