Skip to content

Commit d57a038

Browse files
stoyannkalexr00
andauthored
Removed a redundand 'resolve' in SimpleFileDialog by reusing the alre… (microsoft#99432)
* Removed a redundand 'resolve' in SimpleFileDialog by reusing the already queried stat data. * get filename before adding path separator Co-authored-by: Alex Ross <alros@microsoft.com>
1 parent 1428d44 commit d57a038

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,7 @@ export class SimpleFileDialog {
878878
const backDir = this.createBackItem(currentFolder);
879879
try {
880880
const folder = await this.fileService.resolve(currentFolder);
881-
const fileNames = folder.children ? folder.children.map(child => child.name) : [];
882-
const items = await Promise.all(fileNames.map(fileName => this.createItem(fileName, currentFolder, token)));
881+
const items = folder.children ? await Promise.all(folder.children.map(child => this.createItem(child, currentFolder, token))) : [];
883882
for (let item of items) {
884883
if (item) {
885884
result.push(item);
@@ -922,23 +921,18 @@ export class SimpleFileDialog {
922921
return true;
923922
}
924923

925-
private async createItem(filename: string, parent: URI, token: CancellationToken): Promise<FileQuickPickItem | undefined> {
924+
private async createItem(stat: IFileStat, parent: URI, token: CancellationToken): Promise<FileQuickPickItem | undefined> {
926925
if (token.isCancellationRequested) {
927926
return undefined;
928927
}
929-
let fullPath = resources.joinPath(parent, filename);
930-
try {
931-
const stat = await this.fileService.resolve(fullPath);
932-
if (stat.isDirectory) {
933-
filename = resources.basename(fullPath);
934-
fullPath = resources.addTrailingPathSeparator(fullPath, this.separator);
935-
return { label: filename, uri: fullPath, isFolder: true, iconClasses: getIconClasses(this.modelService, this.modeService, fullPath || undefined, FileKind.FOLDER) };
936-
} else if (!stat.isDirectory && this.allowFileSelection && this.filterFile(fullPath)) {
937-
return { label: filename, uri: fullPath, isFolder: false, iconClasses: getIconClasses(this.modelService, this.modeService, fullPath || undefined) };
938-
}
939-
return undefined;
940-
} catch (e) {
941-
return undefined;
928+
let fullPath = resources.joinPath(parent, stat.name);
929+
if (stat.isDirectory) {
930+
const filename = resources.basename(fullPath);
931+
fullPath = resources.addTrailingPathSeparator(fullPath, this.separator);
932+
return { label: filename, uri: fullPath, isFolder: true, iconClasses: getIconClasses(this.modelService, this.modeService, fullPath || undefined, FileKind.FOLDER) };
933+
} else if (!stat.isDirectory && this.allowFileSelection && this.filterFile(fullPath)) {
934+
return { label: stat.name, uri: fullPath, isFolder: false, iconClasses: getIconClasses(this.modelService, this.modeService, fullPath || undefined) };
942935
}
936+
return undefined;
943937
}
944938
}

0 commit comments

Comments
 (0)