From a21dbb6d81fe069c1f66e1d00b2b3ffd3821e6b3 Mon Sep 17 00:00:00 2001 From: Sana Ajani Date: Thu, 13 Sep 2018 16:27:37 -0700 Subject: [PATCH] add consistent Promise structure --- tree-view-sample/src/nodeDependencies.ts | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tree-view-sample/src/nodeDependencies.ts b/tree-view-sample/src/nodeDependencies.ts index 0a8e1078..b6f26870 100644 --- a/tree-view-sample/src/nodeDependencies.ts +++ b/tree-view-sample/src/nodeDependencies.ts @@ -23,20 +23,19 @@ export class DepNodeProvider implements vscode.TreeDataProvider { vscode.window.showInformationMessage('No dependency in empty workspace'); return Promise.resolve([]); } - - return new Promise(resolve => { - if (element) { - resolve(this.getDepsInPackageJson(path.join(this.workspaceRoot, 'node_modules', element.label, 'package.json'))); + + if (element) { + return Promise.resolve(this.getDepsInPackageJson(path.join(this.workspaceRoot, 'node_modules', element.label, 'package.json'))); + } else { + const packageJsonPath = path.join(this.workspaceRoot, 'package.json'); + if (this.pathExists(packageJsonPath)) { + return Promise.resolve(this.getDepsInPackageJson(packageJsonPath)); } else { - const packageJsonPath = path.join(this.workspaceRoot, 'package.json'); - if (this.pathExists(packageJsonPath)) { - resolve(this.getDepsInPackageJson(packageJsonPath)); - } else { - vscode.window.showInformationMessage('Workspace has no package.json'); - resolve([]); - } + vscode.window.showInformationMessage('Workspace has no package.json'); + return Promise.resolve([]); } - }); + } + } /** @@ -103,4 +102,4 @@ class Dependency extends vscode.TreeItem { contextValue = 'dependency'; -} \ No newline at end of file +}