From 2ca312b08bbe19ca2e0cbca98cfbf22e4622f37d Mon Sep 17 00:00:00 2001 From: xuzho Date: Thu, 19 Oct 2017 13:11:31 +0800 Subject: [PATCH] add progress when initializing debug config Signed-off-by: xuzho --- src/configurationProvider.ts | 51 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index 8e062722..bde8774c 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -12,7 +12,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration // Returns an initial debug configurations based on contextual information. public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): vscode.ProviderResult { - return this.provideDebugConfigurationsAsync(folder); + return >this.provideDebugConfigurationsAsync(folder); } // Try to add all missing attributes to the debug configuration being launched. @@ -21,27 +21,36 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration return this.heuristicallyResolveDebugConfiguration(folder, config); } - private async provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) { - const res = (await resolveMainClass()); - let cache; - cache = {}; - const launchConfigs = res.map((item) => { - return { - type: "java", - name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache), - request: "launch", - mainClass: item.mainClass, - projectName: item.projectName, - args: "", - }; + private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) { + return vscode.window.withProgress({location: vscode.ProgressLocation.Window}, (p) => { + return new Promise((resolve, reject) => { + p.report({message: "Auto generating configuration..."}); + resolveMainClass().then((res: any[]) => { + let cache; + cache = {}; + const launchConfigs = res.map((item) => { + return { + type: "java", + name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache), + request: "launch", + mainClass: item.mainClass, + projectName: item.projectName, + args: "", + }; + }); + resolve([...launchConfigs, { + type: "java", + name: "Debug (Attach)", + request: "attach", + hostName: "localhost", + port: 0, + }]); + }, (ex) => { + p.report({message: `failed to generate configuration. ${ex}`}); + reject(ex); + }); + }); }); - return [...launchConfigs, { - type: "java", - name: "Debug (Attach)", - request: "attach", - hostName: "localhost", - port: 0, - }]; } private constructLaunchConfigName(mainClass: string, projectName: string, cache: {}) {