@@ -394,6 +394,7 @@ export async function createFolderQuickPick(accessor: ServicesAccessor): Promise
394
394
searchFolders (
395
395
workspace ,
396
396
value ,
397
+ true ,
397
398
undefined ,
398
399
undefined ,
399
400
configurationService ,
@@ -421,6 +422,7 @@ export async function createFolderQuickPick(accessor: ServicesAccessor): Promise
421
422
type : 'item' ,
422
423
id : folder . toString ( ) ,
423
424
resource : folder ,
425
+ alwaysShow : true ,
424
426
label : basename ( folder ) ,
425
427
description : labelService . getUriLabel ( dirname ( folder ) , { relative : true } ) ,
426
428
iconClass : ThemeIcon . asClassName ( Codicon . folder ) ,
@@ -451,11 +453,14 @@ export async function getTopLevelFolders(workspaces: URI[], fileService: IFileSe
451
453
export async function searchFolders (
452
454
workspace : URI ,
453
455
pattern : string ,
456
+ fuzzyMatch : boolean ,
454
457
token : CancellationToken | undefined ,
455
458
cacheKey : string | undefined ,
456
459
configurationService : IConfigurationService ,
457
460
searchService : ISearchService
458
461
) : Promise < URI [ ] > {
462
+ const segmentMatchPattern = caseInsensitiveGlobPattern ( fuzzyMatch ? fuzzyMatchingGlobPattern ( pattern ) : continousMatchingGlobPattern ( pattern ) ) ;
463
+
459
464
const searchExcludePattern = getExcludes ( configurationService . getValue < ISearchConfiguration > ( { resource : workspace } ) ) || { } ;
460
465
const searchOptions : IFileQuery = {
461
466
folderQueries : [ {
@@ -470,7 +475,7 @@ export async function searchFolders(
470
475
471
476
let folderResults : ISearchComplete | undefined ;
472
477
try {
473
- folderResults = await searchService . fileSearch ( { ...searchOptions , filePattern : `**/* ${ pattern } * /**` } , token ) ;
478
+ folderResults = await searchService . fileSearch ( { ...searchOptions , filePattern : `**/${ segmentMatchPattern } /**` } , token ) ;
474
479
} catch ( e ) {
475
480
if ( ! isCancellationError ( e ) ) {
476
481
throw e ;
@@ -481,13 +486,40 @@ export async function searchFolders(
481
486
return [ ] ;
482
487
}
483
488
484
- const folderResources = getMatchingFoldersFromFiles ( folderResults . results . map ( result => result . resource ) , workspace , pattern ) ;
489
+ const folderResources = getMatchingFoldersFromFiles ( folderResults . results . map ( result => result . resource ) , workspace , segmentMatchPattern ) ;
485
490
return folderResources ;
486
491
}
487
492
493
+ function fuzzyMatchingGlobPattern ( pattern : string ) : string {
494
+ if ( ! pattern ) {
495
+ return '*' ;
496
+ }
497
+ return '*' + pattern . split ( '' ) . join ( '*' ) + '*' ;
498
+ }
499
+
500
+ function continousMatchingGlobPattern ( pattern : string ) : string {
501
+ if ( ! pattern ) {
502
+ return '*' ;
503
+ }
504
+ return '*' + pattern + '*' ;
505
+ }
506
+
507
+ function caseInsensitiveGlobPattern ( pattern : string ) : string {
508
+ let caseInsensitiveFilePattern = '' ;
509
+ for ( let i = 0 ; i < pattern . length ; i ++ ) {
510
+ const char = pattern [ i ] ;
511
+ if ( / [ a - z A - Z ] / . test ( char ) ) {
512
+ caseInsensitiveFilePattern += `[${ char . toLowerCase ( ) } ${ char . toUpperCase ( ) } ]` ;
513
+ } else {
514
+ caseInsensitiveFilePattern += char ;
515
+ }
516
+ }
517
+ return caseInsensitiveFilePattern ;
518
+ }
519
+
488
520
489
521
// TODO: remove this and have support from the search service
490
- function getMatchingFoldersFromFiles ( resources : URI [ ] , workspace : URI , pattern : string ) : URI [ ] {
522
+ function getMatchingFoldersFromFiles ( resources : URI [ ] , workspace : URI , segmentMatchPattern : string ) : URI [ ] {
491
523
const uniqueFolders = new ResourceSet ( ) ;
492
524
for ( const resource of resources ) {
493
525
const relativePathToRoot = relativePath ( workspace , resource ) ;
@@ -507,7 +539,7 @@ function getMatchingFoldersFromFiles(resources: URI[], workspace: URI, pattern:
507
539
for ( const folderResource of uniqueFolders ) {
508
540
const stats = folderResource . path . split ( '/' ) ;
509
541
const dirStat = stats [ stats . length - 1 ] ;
510
- if ( ! dirStat || ! glob . match ( `* ${ pattern } *` , dirStat ) ) {
542
+ if ( ! dirStat || ! glob . match ( segmentMatchPattern , dirStat ) ) {
511
543
continue ;
512
544
}
513
545
0 commit comments