From 34822887b686ead60545ea6719fe6a5672bdc7e4 Mon Sep 17 00:00:00 2001 From: Vincent Fugnitto Date: Mon, 4 Nov 2019 11:07:22 -0500 Subject: [PATCH] Automatically create 'launch.json' Automatically creates the `launch.json` file when executing the command `start debugging` whenever a `launch.json` does not exist under `.theia` or `.vscode`. Once created, users are prompted to select the type of debug configuration they desire. Signed-off-by: Vincent Fugnitto --- .../debug-frontend-application-contribution.ts | 14 ++++++++++---- .../browser/view/debug-configuration-widget.tsx | 11 ++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/debug/src/browser/debug-frontend-application-contribution.ts b/packages/debug/src/browser/debug-frontend-application-contribution.ts index b84e8f9180163..d0372118136c7 100644 --- a/packages/debug/src/browser/debug-frontend-application-contribution.ts +++ b/packages/debug/src/browser/debug-frontend-application-contribution.ts @@ -42,6 +42,7 @@ import { DebugService } from '../common/debug-service'; import { DebugSchemaUpdater } from './debug-schema-updater'; import { DebugPreferences } from './debug-preferences'; import { TabBarToolbarContribution, TabBarToolbarRegistry, TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; +import { DebugSessionOptions } from './debug-session-options'; export namespace DebugMenus { export const DEBUG = [...MAIN_MENU_BAR, '6_debug']; @@ -512,10 +513,10 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi registerCommands(registry: CommandRegistry): void { super.registerCommands(registry); registry.registerCommand(DebugCommands.START, { - execute: () => this.start() + execute: (config?: DebugSessionOptions) => this.start(false, config) }); registry.registerCommand(DebugCommands.START_NO_DEBUG, { - execute: () => this.start(true) + execute: (config?: DebugSessionOptions) => this.start(true, config) }); registry.registerCommand(DebugCommands.STOP, { execute: () => this.manager.currentSession && this.manager.currentSession.terminate(), @@ -945,8 +946,13 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi return widget; } - async start(noDebug?: boolean): Promise { - let { current } = this.configurations; + async start(noDebug?: boolean, debugSessionOptions?: DebugSessionOptions): Promise { + let current = debugSessionOptions ? debugSessionOptions : this.configurations.current; + // If no configurations are currently present, create the `launch.json` and prompt users to select the config. + if (!current) { + await this.configurations.addConfiguration(); + return; + } if (current) { if (noDebug !== undefined) { current = { diff --git a/packages/debug/src/browser/view/debug-configuration-widget.tsx b/packages/debug/src/browser/view/debug-configuration-widget.tsx index d6929324cf48e..157fe46c575c0 100644 --- a/packages/debug/src/browser/view/debug-configuration-widget.tsx +++ b/packages/debug/src/browser/view/debug-configuration-widget.tsx @@ -26,10 +26,15 @@ import { DebugSessionManager } from '../debug-session-manager'; import { DebugAction } from './debug-action'; import { DebugViewModel } from './debug-view-model'; import { DebugSessionOptions } from '../debug-session-options'; +import { DebugCommands } from '../debug-frontend-application-contribution'; +import { CommandRegistry } from '@theia/core/lib/common'; @injectable() export class DebugConfigurationWidget extends ReactWidget { + @inject(CommandRegistry) + protected readonly commandRegistry: CommandRegistry; + @inject(DebugViewModel) protected readonly viewModel: DebugViewModel; @@ -118,11 +123,7 @@ export class DebugConfigurationWidget extends ReactWidget { protected readonly start = () => { const configuration = this.manager.current; - if (configuration) { - this.sessionManager.start(configuration); - } else { - this.manager.addConfiguration(); - } + this.commandRegistry.executeCommand(DebugCommands.START.id, configuration); } protected readonly openConfiguration = () => this.manager.openConfiguration();