Skip to content

Commit 4fa86af

Browse files
author
Akos Kitta
committed
feat: use new debug -I -P CLI output
Signed-off-by: Akos Kitta <[email protected]>
1 parent 503533d commit 4fa86af

File tree

4 files changed

+95
-49
lines changed

4 files changed

+95
-49
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
'electron-app/src-gen/*',
1919
'electron-app/gen-webpack*.js',
2020
'!electron-app/webpack.config.js',
21-
'plugins/*',
21+
'electron-app/plugins/*',
2222
'arduino-ide-extension/src/node/cli-protocol',
2323
'**/lib/*',
2424
],

arduino-ide-extension/src/browser/contributions/debug.ts

Lines changed: 91 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,75 @@
1+
import { Emitter, Event } from '@theia/core/lib/common/event';
2+
import { MenuModelRegistry } from '@theia/core/lib/common/menu/menu-model-registry';
3+
import { nls } from '@theia/core/lib/common/nls';
14
import { inject, injectable } from '@theia/core/shared/inversify';
2-
import { Event, Emitter } from '@theia/core/lib/common/event';
35
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
4-
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
5-
import { NotificationCenter } from '../notification-center';
66
import {
77
Board,
88
BoardIdentifier,
99
BoardsService,
1010
ExecutableService,
11+
SketchRef,
1112
isBoardIdentifierChangeEvent,
12-
Sketch,
1313
} from '../../common/protocol';
14+
import { BoardsDataStore } from '../boards/boards-data-store';
1415
import { BoardsServiceProvider } from '../boards/boards-service-provider';
16+
import { ArduinoMenus } from '../menu/arduino-menus';
17+
import { NotificationCenter } from '../notification-center';
18+
import { CurrentSketch } from '../sketches-service-client-impl';
19+
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
1520
import {
16-
URI,
1721
Command,
1822
CommandRegistry,
1923
SketchContribution,
2024
TabBarToolbarRegistry,
25+
URI,
2126
} from './contribution';
22-
import { MenuModelRegistry, nls } from '@theia/core/lib/common';
23-
import { CurrentSketch } from '../sketches-service-client-impl';
24-
import { ArduinoMenus } from '../menu/arduino-menus';
2527

2628
const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
2729

30+
interface StartDebugParams {
31+
/**
32+
* Absolute filesystem path to the Arduino CLI executable.
33+
*/
34+
readonly cliPath: string;
35+
/**
36+
* The the board to debug.
37+
*/
38+
readonly board: Readonly<{ fqbn: string; name?: string }>;
39+
/**
40+
* Absolute filesystem path of the sketch to debug.
41+
*/
42+
readonly sketchPath: string;
43+
/**
44+
* Location where the `launch.json` will be created on the fly before starting every debug session.
45+
* If not defined, it falls back to `sketchPath/.vscode/launch.json`.
46+
*/
47+
readonly launchConfigPath?: string;
48+
/**
49+
* Absolute path to the `arduino-cli.yaml` file. If not specified, it falls back to `~/.arduinoIDE/arduino-cli.yaml`.
50+
*/
51+
readonly cliConfigPath?: string;
52+
/**
53+
* Programmer for the debugging.
54+
*/
55+
readonly programmer?: string;
56+
}
57+
type StartDebugResult = boolean;
58+
2859
@injectable()
2960
export class Debug extends SketchContribution {
3061
@inject(HostedPluginSupport)
3162
private readonly hostedPluginSupport: HostedPluginSupport;
32-
3363
@inject(NotificationCenter)
3464
private readonly notificationCenter: NotificationCenter;
35-
3665
@inject(ExecutableService)
3766
private readonly executableService: ExecutableService;
38-
3967
@inject(BoardsService)
4068
private readonly boardService: BoardsService;
41-
4269
@inject(BoardsServiceProvider)
4370
private readonly boardsServiceProvider: BoardsServiceProvider;
71+
@inject(BoardsDataStore)
72+
private readonly boardsDataStore: BoardsDataStore;
4473

4574
/**
4675
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
@@ -175,42 +204,18 @@ export class Debug extends SketchContribution {
175204
private async startDebug(
176205
board: BoardIdentifier | undefined = this.boardsServiceProvider.boardsConfig
177206
.selectedBoard
178-
): Promise<void> {
179-
if (!board) {
180-
return;
181-
}
182-
const { name, fqbn } = board;
183-
if (!fqbn) {
184-
return;
207+
): Promise<StartDebugResult> {
208+
const params = await this.createStartDebugParams(board);
209+
if (!params) {
210+
return false;
185211
}
186212
await this.hostedPluginSupport.didStart;
187-
const [sketch, executables] = await Promise.all([
188-
this.sketchServiceClient.currentSketch(),
189-
this.executableService.list(),
190-
]);
191-
if (!CurrentSketch.isValid(sketch)) {
192-
return;
193-
}
194-
const ideTempFolderUri = await this.sketchesService.getIdeTempFolderUri(
195-
sketch
196-
);
197-
const [cliPath, sketchPath, configPath] = await Promise.all([
198-
this.fileService.fsPath(new URI(executables.cliUri)),
199-
this.fileService.fsPath(new URI(sketch.uri)),
200-
this.fileService.fsPath(new URI(ideTempFolderUri)),
201-
]);
202-
const config = {
203-
cliPath,
204-
board: {
205-
fqbn,
206-
name,
207-
},
208-
sketchPath,
209-
configPath,
210-
};
211213
try {
212-
await this.commandService.executeCommand('arduino.debug.start', config);
214+
const result = await this.debug(params);
215+
return Boolean(result);
213216
} catch (err) {
217+
const sketchUri = await this.fileSystemExt.getUri(params.sketchPath);
218+
const sketch = SketchRef.fromUri(sketchUri);
214219
if (await this.isSketchNotVerifiedError(err, sketch)) {
215220
const yes = nls.localize('vscode/extensionsUtils/yes', 'Yes');
216221
const answer = await this.messageService.error(
@@ -230,6 +235,16 @@ export class Debug extends SketchContribution {
230235
);
231236
}
232237
}
238+
return false;
239+
}
240+
241+
private async debug(
242+
params: StartDebugParams
243+
): Promise<StartDebugResult | undefined> {
244+
return this.commandService.executeCommand<StartDebugResult>(
245+
'arduino.debug.start',
246+
params
247+
);
233248
}
234249

235250
get compileForDebug(): boolean {
@@ -246,7 +261,7 @@ export class Debug extends SketchContribution {
246261

247262
private async isSketchNotVerifiedError(
248263
err: unknown,
249-
sketch: Sketch
264+
sketch: SketchRef
250265
): Promise<boolean> {
251266
if (err instanceof Error) {
252267
try {
@@ -260,6 +275,37 @@ export class Debug extends SketchContribution {
260275
}
261276
return false;
262277
}
278+
279+
private async createStartDebugParams(
280+
board: BoardIdentifier | undefined
281+
): Promise<StartDebugParams | undefined> {
282+
if (!board || !board.fqbn) {
283+
return undefined;
284+
}
285+
const [sketch, executables, boardsData] = await Promise.all([
286+
this.sketchServiceClient.currentSketch(),
287+
this.executableService.list(),
288+
this.boardsDataStore.getData(board.fqbn),
289+
]);
290+
if (!CurrentSketch.isValid(sketch)) {
291+
return;
292+
}
293+
const ideTempFolderUri = await this.sketchesService.getIdeTempFolderUri(
294+
sketch
295+
);
296+
const [cliPath, sketchPath, launchConfigPath] = await Promise.all([
297+
this.fileService.fsPath(new URI(executables.cliUri)),
298+
this.fileService.fsPath(new URI(sketch.uri)),
299+
this.fileService.fsPath(new URI(ideTempFolderUri)),
300+
]);
301+
return {
302+
board: { fqbn: board.fqbn, name: board.name },
303+
cliPath,
304+
sketchPath,
305+
launchConfigPath,
306+
programmer: boardsData.selectedProgrammer?.id,
307+
};
308+
}
263309
}
264310
export namespace Debug {
265311
export namespace Commands {

arduino-ide-extension/src/common/protocol/sketches-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export interface SketchesService {
121121
* Hence, IDE2 has to provide multiple build paths on Windows. This hack will be obsolete when the CLI can provide error codes:
122122
* https://github.com/arduino/arduino-cli/issues/1762.
123123
*/
124-
tempBuildPath(sketch: Sketch): Promise<string[]>;
124+
tempBuildPath(sketch: SketchRef): Promise<string[]>;
125125
}
126126

127127
export interface SketchRef {

arduino-ide-extension/src/node/sketches-service-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,12 @@ export class SketchesServiceImpl
555555
return destinationUri;
556556
}
557557

558-
async getIdeTempFolderUri(sketch: Sketch): Promise<string> {
558+
async getIdeTempFolderUri(sketch: SketchRef): Promise<string> {
559559
const genBuildPath = await this.getIdeTempFolderPath(sketch);
560560
return FileUri.create(genBuildPath).toString();
561561
}
562562

563-
private async getIdeTempFolderPath(sketch: Sketch): Promise<string> {
563+
private async getIdeTempFolderPath(sketch: SketchRef): Promise<string> {
564564
const sketchPath = FileUri.fsPath(sketch.uri);
565565
await fs.readdir(sketchPath); // Validates the sketch folder and rejects if not accessible.
566566
const suffix = crypto.createHash('md5').update(sketchPath).digest('hex');

0 commit comments

Comments
 (0)