Skip to content

Commit 36ac97d

Browse files
committedFeb 13, 2020
Improved creation of default debug configurations
1 parent a886a10 commit 36ac97d

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed
 

‎arduino-debugger-extension/src/browser/arduino-debug-configuration-manager.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,36 @@ import { injectable } from "inversify";
44
@injectable()
55
export class ArduinoDebugConfigurationManager extends DebugConfigurationManager {
66

7-
async addConfiguration() {
7+
get defaultDebugger(): Promise<string | undefined> {
8+
return this.debug.getDebuggersForLanguage('ino').then(debuggers => {
9+
if (debuggers.length === 0)
10+
return undefined;
11+
return debuggers[0].type;
12+
});
13+
}
14+
15+
protected async selectDebugType(): Promise<string | undefined> {
16+
const widget = this.editorManager.currentEditor;
17+
if (!widget) {
18+
return this.defaultDebugger;
19+
}
20+
const { languageId } = widget.editor.document;
21+
const debuggers = await this.debug.getDebuggersForLanguage(languageId);
22+
if (debuggers.length === 0) {
23+
return this.defaultDebugger;
24+
}
25+
return this.quickPick.show(debuggers.map(
26+
({ label, type }) => ({ label, value: type }),
27+
{ placeholder: 'Select Environment' })
28+
);
29+
}
30+
31+
async createDefaultConfiguration(): Promise<void> {
832
const { model } = this;
9-
if (!model) {
10-
return;
33+
if (model) {
34+
await this.doCreate(model);
35+
await this.updateModels();
1136
}
12-
await this.doCreate(model);
13-
await this.updateModels();
1437
}
1538

16-
}
39+
}

‎arduino-debugger-extension/src/browser/arduino-debug-frontend-application-contribution.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { injectable, inject } from 'inversify';
22
import { MenuModelRegistry } from '@theia/core';
33
import { KeybindingRegistry } from '@theia/core/lib/browser';
44
import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
5-
import { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
5+
import { DebugFrontendApplicationContribution, DebugCommands } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
66
import { DebugSessionOptions } from "@theia/debug/lib/browser/debug-session-options";
77
import { EditorMode } from "arduino-ide-extension/lib/browser/editor-mode";
8+
import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager';
89

910
@injectable()
1011
export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendApplicationContribution {
@@ -13,12 +14,12 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
1314
protected readonly editorMode: EditorMode;
1415

1516
async start(noDebug?: boolean, debugSessionOptions?: DebugSessionOptions): Promise<void> {
16-
let current = debugSessionOptions ? debugSessionOptions : this.configurations.current;
17-
// If no configurations are currently present, create the `launch.json` and prompt users to select the config.
17+
const configurations = this.configurations as ArduinoDebugConfigurationManager;
18+
let current = debugSessionOptions ? debugSessionOptions : configurations.current;
19+
// If no configurations are currently present, create them
1820
if (!current) {
19-
await this.configurations.addConfiguration();
20-
await this.configurations.load()
21-
current = this.configurations.current;
21+
await configurations.createDefaultConfiguration();
22+
current = configurations.current;
2223
}
2324
if (current) {
2425
if (noDebug !== undefined) {
@@ -35,24 +36,33 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
3536
}
3637

3738
initializeLayout(): Promise<void> {
38-
if (this.editorMode.proMode)
39+
if (this.editorMode.proMode) {
3940
return super.initializeLayout();
41+
}
4042
return Promise.resolve();
4143
}
4244

4345
registerMenus(menus: MenuModelRegistry): void {
44-
if (this.editorMode.proMode)
46+
if (this.editorMode.proMode) {
4547
super.registerMenus(menus);
48+
menus.unregisterMenuAction(DebugCommands.START_NO_DEBUG);
49+
}
4650
}
4751

4852
registerKeybindings(keybindings: KeybindingRegistry): void {
49-
if (this.editorMode.proMode)
53+
if (this.editorMode.proMode) {
5054
super.registerKeybindings(keybindings);
55+
keybindings.unregisterKeybinding({
56+
command: DebugCommands.START_NO_DEBUG.id,
57+
keybinding: 'ctrl+f5'
58+
});
59+
}
5160
}
5261

5362
registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
54-
if (this.editorMode.proMode)
63+
if (this.editorMode.proMode) {
5564
super.registerToolbarItems(toolbar);
65+
}
5666
}
5767

5868
}

0 commit comments

Comments
 (0)
Please sign in to comment.