Skip to content

Commit

Permalink
resolve file before resolving contents fixes #53204
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jun 28, 2018
1 parent 00aeb41 commit 8115822
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/vs/workbench/parts/stats/node/workspaceStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
"workspace.reactNative" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
private async getWorkspaceTags(configuration: IWindowConfiguration): TPromise<Tags> {
private getWorkspaceTags(configuration: IWindowConfiguration): TPromise<Tags> {
const tags: Tags = Object.create(null);

const state = this.contextService.getWorkbenchState();
Expand Down Expand Up @@ -258,9 +258,11 @@ export class WorkspaceStats implements IWorkbenchContribution {
tags['workspace.empty'] = isEmpty;

const folders = !isEmpty ? workspace.folders.map(folder => folder.uri) : this.environmentService.appQuality !== 'stable' && this.findFolders(configuration);
if (folders && folders.length && this.fileService) {
//return
const files: IResolveFileResult[] = await this.fileService.resolveFiles(folders.map(resource => ({ resource })));
if (!folders || !folders.length || !this.fileService) {
return TPromise.as(tags);
}

return this.fileService.resolveFiles(folders.map(resource => ({ resource }))).then((files: IResolveFileResult[]) => {
const names = (<IFileStat[]>[]).concat(...files.map(result => result.success ? (result.stat.children || []) : [])).map(c => c.name);
const nameSet = names.reduce((s, n) => s.add(n.toLowerCase()), new Set());

Expand Down Expand Up @@ -313,12 +315,10 @@ export class WorkspaceStats implements IWorkbenchContribution {
tags['workspace.android.cpp'] = true;
}

if (nameSet.has('package.json')) {
const promises = [];
for (let i = 0; i < folders.length; i++) {
const workspaceUri = folders[i];
const uri = workspaceUri.with({ path: `${workspaceUri.path !== '/' ? workspaceUri.path : ''}/package.json` });
promises.push(this.fileService.resolveContent(uri, { acceptTextOnly: true }).then(content => {
const packageJsonPromises = !nameSet.has('package.json') ? [] : folders.map(workspaceUri => {
const uri = workspaceUri.with({ path: `${workspaceUri.path !== '/' ? workspaceUri.path : ''}/package.json` });
return this.fileService.resolveFile(uri).then(() => {
return this.fileService.resolveContent(uri, { acceptTextOnly: true }).then(content => {
try {
const packageJsonContents = JSON.parse(content.value);
if (packageJsonContents['dependencies']) {
Expand All @@ -338,12 +338,13 @@ export class WorkspaceStats implements IWorkbenchContribution {
catch (e) {
// Ignore errors when resolving file or parsing file contents
}
}));
}
await TPromise.join(promises);
}
}
return TPromise.as(tags);
});
}, err => {
// Ignore missing file
});
});
return TPromise.join(packageJsonPromises).then(() => tags);
});
}

private findFolders(configuration: IWindowConfiguration): URI[] {
Expand Down

0 comments on commit 8115822

Please sign in to comment.