Skip to content

Commit d88e573

Browse files
authored
1 parent 6a06fb7 commit d88e573

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ export async function createFolderQuickPick(accessor: ServicesAccessor): Promise
394394
searchFolders(
395395
workspace,
396396
value,
397+
true,
397398
undefined,
398399
undefined,
399400
configurationService,
@@ -421,6 +422,7 @@ export async function createFolderQuickPick(accessor: ServicesAccessor): Promise
421422
type: 'item',
422423
id: folder.toString(),
423424
resource: folder,
425+
alwaysShow: true,
424426
label: basename(folder),
425427
description: labelService.getUriLabel(dirname(folder), { relative: true }),
426428
iconClass: ThemeIcon.asClassName(Codicon.folder),
@@ -451,11 +453,14 @@ export async function getTopLevelFolders(workspaces: URI[], fileService: IFileSe
451453
export async function searchFolders(
452454
workspace: URI,
453455
pattern: string,
456+
fuzzyMatch: boolean,
454457
token: CancellationToken | undefined,
455458
cacheKey: string | undefined,
456459
configurationService: IConfigurationService,
457460
searchService: ISearchService
458461
): Promise<URI[]> {
462+
const segmentMatchPattern = caseInsensitiveGlobPattern(fuzzyMatch ? fuzzyMatchingGlobPattern(pattern) : continousMatchingGlobPattern(pattern));
463+
459464
const searchExcludePattern = getExcludes(configurationService.getValue<ISearchConfiguration>({ resource: workspace })) || {};
460465
const searchOptions: IFileQuery = {
461466
folderQueries: [{
@@ -470,7 +475,7 @@ export async function searchFolders(
470475

471476
let folderResults: ISearchComplete | undefined;
472477
try {
473-
folderResults = await searchService.fileSearch({ ...searchOptions, filePattern: `**/*${pattern}*/**` }, token);
478+
folderResults = await searchService.fileSearch({ ...searchOptions, filePattern: `**/${segmentMatchPattern}/**` }, token);
474479
} catch (e) {
475480
if (!isCancellationError(e)) {
476481
throw e;
@@ -481,13 +486,40 @@ export async function searchFolders(
481486
return [];
482487
}
483488

484-
const folderResources = getMatchingFoldersFromFiles(folderResults.results.map(result => result.resource), workspace, pattern);
489+
const folderResources = getMatchingFoldersFromFiles(folderResults.results.map(result => result.resource), workspace, segmentMatchPattern);
485490
return folderResources;
486491
}
487492

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-zA-Z]/.test(char)) {
512+
caseInsensitiveFilePattern += `[${char.toLowerCase()}${char.toUpperCase()}]`;
513+
} else {
514+
caseInsensitiveFilePattern += char;
515+
}
516+
}
517+
return caseInsensitiveFilePattern;
518+
}
519+
488520

489521
// 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[] {
491523
const uniqueFolders = new ResourceSet();
492524
for (const resource of resources) {
493525
const relativePathToRoot = relativePath(workspace, resource);
@@ -507,7 +539,7 @@ function getMatchingFoldersFromFiles(resources: URI[], workspace: URI, pattern:
507539
for (const folderResource of uniqueFolders) {
508540
const stats = folderResource.path.split('/');
509541
const dirStat = stats[stats.length - 1];
510-
if (!dirStat || !glob.match(`*${pattern}*`, dirStat)) {
542+
if (!dirStat || !glob.match(segmentMatchPattern, dirStat)) {
511543
continue;
512544
}
513545

src/vs/workbench/contrib/chat/browser/contrib/chatInputCompletions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ class BuiltinDynamicCompletions extends Disposable {
808808

809809
const cacheKey = this.updateCacheKey();
810810

811-
const folders = await Promise.all(workspaces.map(workspace => searchFolders(workspace, pattern, token, cacheKey.key, this.configurationService, this.searchService)));
811+
const folders = await Promise.all(workspaces.map(workspace => searchFolders(workspace, pattern, true, token, cacheKey.key, this.configurationService, this.searchService)));
812812
for (const resource of folders.flat()) {
813813
if (seen.has(resource)) {
814814
// already included via history

0 commit comments

Comments
 (0)