Skip to content

Commit e7b1a27

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
ATL-730: Refactored the debug extension.
Wired in the `cortex.debug` VSXE. Signed-off-by: Akos Kitta <[email protected]>
1 parent 4d5a046 commit e7b1a27

File tree

14 files changed

+177
-57
lines changed

14 files changed

+177
-57
lines changed

Diff for: .vscode/tasks.json

+1-14
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,7 @@
3535
"panel": "new",
3636
"clear": false
3737
}
38-
},
39-
{
40-
"label": "Arduino Pro IDE - Watch Debugger Extension",
41-
"type": "shell",
42-
"command": "yarn --cwd ./arduino-debugger-extension watch",
43-
"group": "build",
44-
"presentation": {
45-
"reveal": "always",
46-
"panel": "new",
47-
"clear": false
48-
}
49-
},
38+
}
5039
{
5140
"label": "Arduino Pro IDE - Watch Browser App",
5241
"type": "shell",
@@ -74,7 +63,6 @@
7463
"type": "shell",
7564
"dependsOn": [
7665
"Arduino Pro IDE - Watch IDE Extension",
77-
"Arduino Pro IDE - Watch Debugger Extension",
7866
"Arduino Pro IDE - Watch Browser App"
7967
]
8068
},
@@ -83,7 +71,6 @@
8371
"type": "shell",
8472
"dependsOn": [
8573
"Arduino Pro IDE - Watch IDE Extension",
86-
"Arduino Pro IDE - Watch Debugger Extension",
8774
"Arduino Pro IDE - Watch Electron App"
8875
]
8976
}

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import { TabBarRenderer } from './theia/core/tab-bars';
127127
import { EditorCommandContribution } from './theia/editor/editor-command';
128128
import { NavigatorTabBarDecorator as TheiaNavigatorTabBarDecorator } from '@theia/navigator/lib/browser/navigator-tab-bar-decorator';
129129
import { NavigatorTabBarDecorator } from './theia/navigator/navigator-tab-bar-decorator';
130+
import { Debug } from './contributions/debug';
130131

131132
const ElementQueries = require('css-element-queries/src/ElementQueries');
132133

@@ -327,6 +328,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
327328
Contribution.configure(bind, LibraryExamples);
328329
Contribution.configure(bind, IncludeLibrary);
329330
Contribution.configure(bind, About);
331+
Contribution.configure(bind, Debug);
330332

331333
bind(OutputServiceImpl).toSelf().inSingletonScope().onActivation(({ container }, outputService) => {
332334
WebSocketConnectionProvider.createProxy(container, OutputServicePath, outputService);
+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { inject, injectable } from 'inversify';
2+
import { Event, Emitter } from '@theia/core/lib/common/event';
3+
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
4+
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
5+
import { NotificationCenter } from '../notification-center';
6+
import { Board, BoardsService, ExecutableService } from '../../common/protocol';
7+
import { BoardsServiceProvider } from '../boards/boards-service-provider';
8+
import { URI, Command, CommandRegistry, SketchContribution, TabBarToolbarRegistry } from './contribution';
9+
10+
@injectable()
11+
export class Debug extends SketchContribution {
12+
13+
@inject(HostedPluginSupport)
14+
protected hostedPluginSupport: HostedPluginSupport;
15+
16+
@inject(NotificationCenter)
17+
protected readonly notificationCenter: NotificationCenter;
18+
19+
@inject(ExecutableService)
20+
protected readonly executableService: ExecutableService;
21+
22+
@inject(BoardsService)
23+
protected readonly boardService: BoardsService;
24+
25+
@inject(BoardsServiceProvider)
26+
protected readonly boardsServiceProvider: BoardsServiceProvider;
27+
28+
/**
29+
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
30+
*/
31+
protected _disabledMessages?: string = 'No board selected'; // Initial pessimism.
32+
protected disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
33+
protected onDisabledMessageDidChange = this.disabledMessageDidChangeEmitter.event;
34+
35+
protected get disabledMessage(): string | undefined {
36+
return this._disabledMessages;
37+
}
38+
protected set disabledMessage(message: string | undefined) {
39+
this._disabledMessages = message;
40+
this.disabledMessageDidChangeEmitter.fire(this._disabledMessages);
41+
}
42+
43+
protected readonly debugToolbarItem = {
44+
id: Debug.Commands.START_DEBUGGING.id,
45+
command: Debug.Commands.START_DEBUGGING.id,
46+
tooltip: `${this.disabledMessage ? `Debug - ${this.disabledMessage}` : 'Start Debugging'}`,
47+
priority: 3,
48+
onDidChange: this.onDisabledMessageDidChange as Event<void>
49+
};
50+
51+
onStart(): void {
52+
this.onDisabledMessageDidChange(() => this.debugToolbarItem.tooltip = `${this.disabledMessage ? `Debug - ${this.disabledMessage}` : 'Start Debugging'}`);
53+
const refreshState = async (board: Board | undefined = this.boardsServiceProvider.boardsConfig.selectedBoard) => {
54+
if (!board) {
55+
this.disabledMessage = 'No board selected';
56+
return;
57+
}
58+
const fqbn = board.fqbn;
59+
if (!fqbn) {
60+
this.disabledMessage = `Platform is not installed for '${board.name}'`;
61+
return;
62+
}
63+
const details = await this.boardService.getBoardDetails({ fqbn });
64+
if (!details) {
65+
this.disabledMessage = `Platform is not installed for '${board.name}'`;
66+
return;
67+
}
68+
const { debuggingSupported } = details;
69+
if (!debuggingSupported) {
70+
this.disabledMessage = `Debugging is not supported by '${board.name}'`;
71+
} else {
72+
this.disabledMessage = undefined;
73+
}
74+
}
75+
this.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard }) => refreshState(selectedBoard));
76+
this.notificationCenter.onPlatformInstalled(() => refreshState());
77+
this.notificationCenter.onPlatformUninstalled(() => refreshState());
78+
refreshState();
79+
}
80+
81+
registerCommands(registry: CommandRegistry): void {
82+
registry.registerCommand(Debug.Commands.START_DEBUGGING, {
83+
execute: () => this.startDebug(),
84+
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
85+
isEnabled: () => !this.disabledMessage
86+
});
87+
}
88+
89+
registerToolbarItems(registry: TabBarToolbarRegistry): void {
90+
registry.registerItem(this.debugToolbarItem);
91+
}
92+
93+
protected async startDebug(board: Board | undefined = this.boardsServiceProvider.boardsConfig.selectedBoard): Promise<void> {
94+
if (!board) {
95+
return;
96+
}
97+
const { name, fqbn } = board;
98+
if (!fqbn) {
99+
return;
100+
}
101+
await this.hostedPluginSupport.didStart;
102+
const [sketch, executables] = await Promise.all([
103+
this.sketchServiceClient.currentSketch(),
104+
this.executableService.list()
105+
]);
106+
if (!sketch) {
107+
return;
108+
}
109+
const [cliPath, sketchPath] = await Promise.all([
110+
this.fileService.fsPath(new URI(executables.cliUri)),
111+
this.fileService.fsPath(new URI(sketch.uri))
112+
])
113+
const config = {
114+
cliPath,
115+
board: {
116+
fqbn,
117+
name
118+
},
119+
sketchPath
120+
};
121+
return this.commandService.executeCommand('arduino.debug.start', config);
122+
}
123+
124+
}
125+
126+
export namespace Debug {
127+
export namespace Commands {
128+
export const START_DEBUGGING: Command = {
129+
id: 'arduino-start-debug',
130+
label: 'Start Debugging',
131+
category: 'Arduino'
132+
}
133+
}
134+
}

Diff for: arduino-ide-extension/src/browser/style/main.css

+17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@
6464
mask-position: 28px -4px;
6565
}
6666

67+
.arduino-start-debug-icon {
68+
-webkit-mask: url('../icons/debug-dark.svg') 50%;
69+
mask: url('../icons/debug-dark.svg') 50%;
70+
-webkit-mask-size: 100%;
71+
mask-size: 100%;
72+
-webkit-mask-repeat: no-repeat;
73+
mask-repeat: no-repeat;
74+
display: flex;
75+
justify-content: center;
76+
align-items: center;
77+
color: var(--theia-ui-button-font-color);
78+
}
79+
80+
.arduino-start-debug {
81+
border-radius: 12px;
82+
}
83+
6784
#arduino-toolbar-container {
6885
display: flex;
6986
width: 100%;

Diff for: arduino-ide-extension/src/browser/theia/core/application-shell.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export class ApplicationShell extends TheiaApplicationShell {
6868
}
6969

7070
async saveAll(): Promise<void> {
71+
if (!this.canSaveAll()) { // This is a quick fix for not saving the editor when there are no dirty editors.
72+
return; // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
73+
}
7174
if (this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE) {
7275
this.messageService.error('Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.');
7376
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803

Diff for: arduino-ide-extension/src/common/protocol/boards-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface BoardsService extends Installable<BoardsPackage>, Searchable<Bo
9999
*/
100100
getAvailablePorts(): Promise<Port[]>;
101101
getState(): Promise<AvailablePorts>;
102-
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails>;
102+
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined>;
103103
getBoardPackage(options: { id: string }): Promise<BoardsPackage | undefined>;
104104
getContainerBoardPackage(options: { fqbn: string }): Promise<BoardsPackage | undefined>;
105105
// The CLI cannot do fuzzy search. This method provides all boards and we do the fuzzy search (with monaco) on the frontend.
@@ -272,6 +272,7 @@ export interface BoardDetails {
272272
readonly requiredTools: Tool[];
273273
readonly configOptions: ConfigOption[];
274274
readonly programmers: Programmer[];
275+
readonly debuggingSupported: boolean;
275276
}
276277

277278
export interface Tool {

Diff for: arduino-ide-extension/src/node/boards-service-impl.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class BoardsServiceImpl implements BoardsService {
6767
return coreClient;
6868
}
6969

70-
async getBoardDetails(options: { fqbn: string }): Promise<BoardDetails> {
70+
async getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined> {
7171
const coreClient = await this.coreClient();
7272
const { client, instance } = coreClient;
7373
const { fqbn } = options;
@@ -77,7 +77,9 @@ export class BoardsServiceImpl implements BoardsService {
7777
const detailsResp = await new Promise<BoardDetailsResp | undefined>((resolve, reject) => client.boardDetails(detailsReq, (err, resp) => {
7878
if (err) {
7979
// Required cores are not installed manually: https://github.com/arduino/arduino-cli/issues/954
80-
if (err.message.indexOf('missing platform release') !== -1 && err.message.indexOf('referenced by board') !== -1) {
80+
if ((err.message.indexOf('missing platform release') !== -1 && err.message.indexOf('referenced by board') !== -1)
81+
// Platform is not installed.
82+
|| err.message.indexOf('platform') !== -1 && err.message.indexOf('not installed') !== -1) {
8183
resolve(undefined);
8284
return;
8385
}
@@ -88,14 +90,11 @@ export class BoardsServiceImpl implements BoardsService {
8890
}));
8991

9092
if (!detailsResp) {
91-
return {
92-
fqbn,
93-
configOptions: [],
94-
programmers: [],
95-
requiredTools: []
96-
};
93+
return undefined;
9794
}
9895

96+
const debuggingSupported = detailsResp.getDebuggingSupported();
97+
9998
const requiredTools = detailsResp.getToolsdependenciesList().map(t => <Tool>{
10099
name: t.getName(),
101100
packager: t.getPackager(),
@@ -133,7 +132,8 @@ export class BoardsServiceImpl implements BoardsService {
133132
fqbn,
134133
requiredTools,
135134
configOptions,
136-
programmers
135+
programmers,
136+
debuggingSupported
137137
};
138138
}
139139

Diff for: browser-app/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"@theia/process": "next",
1919
"@theia/terminal": "next",
2020
"@theia/workspace": "next",
21-
"arduino-ide-extension": "0.1.2",
22-
"arduino-debugger-extension": "0.1.2"
21+
"arduino-ide-extension": "0.1.2"
2322
},
2423
"devDependencies": {
2524
"@theia/cli": "next"

Diff for: electron-app/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"@theia/process": "next",
2121
"@theia/terminal": "next",
2222
"@theia/workspace": "next",
23-
"arduino-ide-extension": "0.1.2",
24-
"arduino-debugger-extension": "0.1.2"
23+
"arduino-ide-extension": "0.1.2"
2524
},
2625
"devDependencies": {
2726
"@theia/cli": "next"

Diff for: electron/build/template-package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"theiaPluginsDir": "plugins",
138138
"theiaPlugins": {
139139
"vscode-builtin-cpp": "http://open-vsx.org/api/vscode/cpp/1.44.2/file/vscode.cpp-1.44.2.vsix",
140-
"vscode-arduino-language-server": "https://downloads.arduino.cc/vscode-arduino-language-server/nightly/vscode-arduino-language-server-0.0.1.vsix"
140+
"vscode-arduino-language-server": "https://downloads.arduino.cc/vscode-arduino-language-server/nightly/vscode-arduino-language-server-0.0.1.vsix",
141+
"cortex-debug": "https://open-vsx.org/api/marus25/cortex-debug/0.3.7/file/marus25.cortex-debug-0.3.7.vsix"
141142
}
142143
}

Diff for: electron/packager/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
shell.exec(`git -C ${path('..', 'build')} clean -ffxdq`, { async: false });
4545

4646
const extensions = [
47-
'arduino-ide-extension',
48-
'arduino-debugger-extension',
47+
'arduino-ide-extension'
4948
];
5049
const allDependencies = [
5150
...extensions,

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
},
2929
"workspaces": [
3030
"arduino-ide-extension",
31-
"arduino-debugger-extension",
3231
"electron-app",
3332
"browser-app"
3433
],
3534
"theiaPluginsDir": "plugins",
3635
"theiaPlugins": {
3736
"vscode-builtin-cpp": "http://open-vsx.org/api/vscode/cpp/1.44.2/file/vscode.cpp-1.44.2.vsix",
38-
"vscode-arduino-language-server": "https://downloads.arduino.cc/vscode-arduino-language-server/nightly/vscode-arduino-language-server-0.0.1.vsix"
37+
"vscode-arduino-language-server": "https://downloads.arduino.cc/vscode-arduino-language-server/nightly/vscode-arduino-language-server-0.0.1.vsix",
38+
"cortex-debug": "https://open-vsx.org/api/marus25/cortex-debug/0.3.7/file/marus25.cortex-debug-0.3.7.vsix"
3939
}
4040
}

Diff for: yarn.lock

+2-24
Original file line numberDiff line numberDiff line change
@@ -5200,15 +5200,6 @@ caw@^2.0.1:
52005200
tunnel-agent "^0.6.0"
52015201
url-to-options "^1.0.1"
52025202

5203-
cdt-gdb-adapter@^0.0.14:
5204-
version "0.0.14"
5205-
resolved "https://registry.yarnpkg.com/cdt-gdb-adapter/-/cdt-gdb-adapter-0.0.14.tgz#0b4cc8650699572003e52a9f8265e9c65055339c"
5206-
integrity sha512-SDRVECyEkgePj0AJNVp8HUOw/ObXSlakQNxMasC1wlCn6eE8HcLAdYqdIgwRtnkp2Ct96/U5mXHFHWQDan6ckw==
5207-
dependencies:
5208-
node-addon-api "^1.6.2"
5209-
vscode-debugadapter "^1.37.1"
5210-
vscode-debugprotocol "^1.37.0"
5211-
52125203
chai-string@^1.5.0:
52135204
version "1.5.0"
52145205
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.5.0.tgz#0bdb2d8a5f1dbe90bc78ec493c1c1c180dd4d3d2"
@@ -10620,7 +10611,7 @@ mkdirp@*, mkdirp@^1.0.0, mkdirp@^1.0.3, mkdirp@^1.0.4:
1062010611
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
1062110612
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
1062210613

10623-
[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.4, mkdirp@^0.5.5, mkdirp@~0.5.1:
10614+
[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.4, mkdirp@~0.5.1:
1062410615
version "0.5.5"
1062510616
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
1062610617
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
@@ -10856,11 +10847,6 @@ node-abi@^2.11.0, node-abi@^2.7.0:
1085610847
dependencies:
1085710848
semver "^5.4.1"
1085810849

10859-
node-addon-api@^1.6.2:
10860-
version "1.7.2"
10861-
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d"
10862-
integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==
10863-
1086410850
1086510851
version "0.1.8"
1086610852
resolved "https://registry.yarnpkg.com/node-dir/-/node-dir-0.1.8.tgz#55fb8deb699070707fb67f91a460f0448294c77d"
@@ -15058,15 +15044,7 @@ vm-browserify@^1.0.1:
1505815044
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
1505915045
integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==
1506015046

15061-
vscode-debugadapter@^1.26.0, vscode-debugadapter@^1.37.1:
15062-
version "1.42.1"
15063-
resolved "https://registry.yarnpkg.com/vscode-debugadapter/-/vscode-debugadapter-1.42.1.tgz#8fe1daa23548dbe4034a065c362d16a4bab18dc2"
15064-
integrity sha512-bICDB8mxReU2kGL13ftjNqeInYtVN3zpRdZKjRZHCpXC/mofrdaj9KRlJsALwcUNivMA9S/LwTZ2n+ros3X0jg==
15065-
dependencies:
15066-
mkdirp "^0.5.5"
15067-
vscode-debugprotocol "1.42.0"
15068-
15069-
[email protected], vscode-debugprotocol@^1.26.0, vscode-debugprotocol@^1.32.0, vscode-debugprotocol@^1.37.0:
15047+
vscode-debugprotocol@^1.32.0:
1507015048
version "1.42.0"
1507115049
resolved "https://registry.yarnpkg.com/vscode-debugprotocol/-/vscode-debugprotocol-1.42.0.tgz#86ad5d95c52a8fd255bc40476414b3a417160f84"
1507215050
integrity sha512-nVsfVCat9FZlOso5SYB1LQQiFGifTyOALpkpJdudDlRXGTpI3mSFiDYXWaoFm7UcfqTOzn1SC7Hqw4d89btT0w==

0 commit comments

Comments
 (0)