From 85d021c8f2140f3614543729246a01bcdb6445e3 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Tue, 21 Feb 2023 15:26:42 +0800 Subject: [PATCH] Display the running launch config name in progress bar for transparency --- src/configurationProvider.ts | 6 +++--- src/debugCodeLensProvider.ts | 2 +- src/extension.ts | 4 +++- src/progressAPI.ts | 6 ++++++ src/progressImpl.ts | 4 ++++ src/utility.ts | 10 ++++++++++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index 8bfa496b..a91beba6 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -108,7 +108,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration progressReporter.observe(token); const defaultLaunchConfig = { type: "java", - name: "Launch Current File", + name: "Current File", request: "launch", // tslint:disable-next-line mainClass: "${file}", @@ -169,7 +169,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration } private constructLaunchConfigName(mainClass: string, cache: { [key: string]: any }) { - const name = `Launch ${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`; + const name = `${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`; if (cache[name] === undefined) { cache[name] = 0; return name; @@ -204,7 +204,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration if (!progressReporter && config.__progressId) { return undefined; } else if (!progressReporter) { - progressReporter = progressProvider.createProgressReporter(config.noDebug ? "Run" : "Debug"); + progressReporter = progressProvider.createProgressReporter(utility.launchJobName(config.name, config.noDebug)); } progressReporter.observe(token); diff --git a/src/debugCodeLensProvider.ts b/src/debugCodeLensProvider.ts index cdadfa74..18fa245b 100644 --- a/src/debugCodeLensProvider.ts +++ b/src/debugCodeLensProvider.ts @@ -152,7 +152,7 @@ async function constructDebugConfig(mainClass: string, projectName: string, work if (!debugConfig) { debugConfig = { type: "java", - name: `Launch ${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`, + name: `${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`, request: "launch", mainClass, projectName, diff --git a/src/extension.ts b/src/extension.ts index a4020ba7..f6d766a0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -330,6 +330,7 @@ async function launchMain(mainMethods: IMainClassOption[], uri: vscode.Uri, noDe throw new utility.OperationCancelledError(""); } + progressReporter.setJobName(utility.launchJobNameByMainClass(pick.mainClass, noDebug)); progressReporter.report("Launching main class..."); startDebugging(pick.mainClass, pick.projectName || "", uri, noDebug, progressReporter); } @@ -366,6 +367,7 @@ async function runJavaProject(node: any, noDebug: boolean) { throw new utility.OperationCancelledError(""); } + progressReporter.setJobName(utility.launchJobNameByMainClass(pick.mainClass, noDebug)); progressReporter.report("Launching main class..."); const projectName: string | undefined = pick.projectName; const mainClass: string = pick.mainClass; @@ -379,7 +381,7 @@ async function runJavaProject(node: any, noDebug: boolean) { }); const debugConfig = existConfig || { type: "java", - name: `Launch ${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`, + name: `${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`, request: "launch", mainClass, projectName, diff --git a/src/progressAPI.ts b/src/progressAPI.ts index 379069b3..d78581d8 100644 --- a/src/progressAPI.ts +++ b/src/progressAPI.ts @@ -4,6 +4,12 @@ import { CancellationToken, ProgressLocation } from "vscode"; export interface IProgressReporter { + /** + * Set the job name. + * @param jobName the job name + */ + setJobName(jobName: string): void; + /** * Returns the id of the progress reporter. */ diff --git a/src/progressImpl.ts b/src/progressImpl.ts index aefa141c..6ee2a98c 100644 --- a/src/progressImpl.ts +++ b/src/progressImpl.ts @@ -52,6 +52,10 @@ class ProgressReporter implements IProgressReporter { this._disposables.push(this._tokenSource); } + public setJobName(jobName: string): void { + this._jobName = jobName; + } + public getId(): string { return this._id; } diff --git a/src/utility.ts b/src/utility.ts index 005a1e8c..94c8e77c 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -313,3 +313,13 @@ function getJavaServerMode(): ServerMode { return vscode.workspace.getConfiguration().get("java.server.launchMode") || ServerMode.HYBRID; } + +export function launchJobName(configName: string, noDebug: boolean): string { + let jobName = noDebug ? "Run" : "Debug"; + jobName += configName ? ` '${configName} '` : ""; + return jobName; +} + +export function launchJobNameByMainClass(mainClass: string, noDebug: boolean): string { + return launchJobName(mainClass.substr(mainClass.lastIndexOf(".") + 1), noDebug); +}