From 36ac97d95d75a903038a361ba80e29e5fed76de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Sp=C3=B6nemann?= Date: Wed, 15 Jan 2020 16:43:11 +0100 Subject: [PATCH] Improved creation of default debug configurations --- .../arduino-debug-configuration-manager.ts | 39 +++++++++++++++---- ...debug-frontend-application-contribution.ts | 30 +++++++++----- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/arduino-debugger-extension/src/browser/arduino-debug-configuration-manager.ts b/arduino-debugger-extension/src/browser/arduino-debug-configuration-manager.ts index 56990444..5e15f1cd 100644 --- a/arduino-debugger-extension/src/browser/arduino-debug-configuration-manager.ts +++ b/arduino-debugger-extension/src/browser/arduino-debug-configuration-manager.ts @@ -4,13 +4,36 @@ import { injectable } from "inversify"; @injectable() export class ArduinoDebugConfigurationManager extends DebugConfigurationManager { - async addConfiguration() { - const { model } = this; - if (!model) { - return; - } - await this.doCreate(model); - await this.updateModels(); + get defaultDebugger(): Promise { + return this.debug.getDebuggersForLanguage('ino').then(debuggers => { + if (debuggers.length === 0) + return undefined; + return debuggers[0].type; + }); } -} \ No newline at end of file + protected async selectDebugType(): Promise { + const widget = this.editorManager.currentEditor; + if (!widget) { + return this.defaultDebugger; + } + const { languageId } = widget.editor.document; + const debuggers = await this.debug.getDebuggersForLanguage(languageId); + if (debuggers.length === 0) { + return this.defaultDebugger; + } + return this.quickPick.show(debuggers.map( + ({ label, type }) => ({ label, value: type }), + { placeholder: 'Select Environment' }) + ); + } + + async createDefaultConfiguration(): Promise { + const { model } = this; + if (model) { + await this.doCreate(model); + await this.updateModels(); + } + } + +} diff --git a/arduino-debugger-extension/src/browser/arduino-debug-frontend-application-contribution.ts b/arduino-debugger-extension/src/browser/arduino-debug-frontend-application-contribution.ts index 7568c72e..b4d61668 100644 --- a/arduino-debugger-extension/src/browser/arduino-debug-frontend-application-contribution.ts +++ b/arduino-debugger-extension/src/browser/arduino-debug-frontend-application-contribution.ts @@ -2,9 +2,10 @@ import { injectable, inject } from 'inversify'; import { MenuModelRegistry } from '@theia/core'; import { KeybindingRegistry } from '@theia/core/lib/browser'; import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; -import { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution'; +import { DebugFrontendApplicationContribution, DebugCommands } from '@theia/debug/lib/browser/debug-frontend-application-contribution'; import { DebugSessionOptions } from "@theia/debug/lib/browser/debug-session-options"; import { EditorMode } from "arduino-ide-extension/lib/browser/editor-mode"; +import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager'; @injectable() export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendApplicationContribution { @@ -13,12 +14,12 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp protected readonly editorMode: EditorMode; 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. + const configurations = this.configurations as ArduinoDebugConfigurationManager; + let current = debugSessionOptions ? debugSessionOptions : configurations.current; + // If no configurations are currently present, create them if (!current) { - await this.configurations.addConfiguration(); - await this.configurations.load() - current = this.configurations.current; + await configurations.createDefaultConfiguration(); + current = configurations.current; } if (current) { if (noDebug !== undefined) { @@ -35,24 +36,33 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp } initializeLayout(): Promise { - if (this.editorMode.proMode) + if (this.editorMode.proMode) { return super.initializeLayout(); + } return Promise.resolve(); } registerMenus(menus: MenuModelRegistry): void { - if (this.editorMode.proMode) + if (this.editorMode.proMode) { super.registerMenus(menus); + menus.unregisterMenuAction(DebugCommands.START_NO_DEBUG); + } } registerKeybindings(keybindings: KeybindingRegistry): void { - if (this.editorMode.proMode) + if (this.editorMode.proMode) { super.registerKeybindings(keybindings); + keybindings.unregisterKeybinding({ + command: DebugCommands.START_NO_DEBUG.id, + keybinding: 'ctrl+f5' + }); + } } registerToolbarItems(toolbar: TabBarToolbarRegistry): void { - if (this.editorMode.proMode) + if (this.editorMode.proMode) { super.registerToolbarItems(toolbar); + } } }