Skip to content

Commit 81f48ca

Browse files
author
Akos Kitta
committed
chore: use 0.35.0-rc.6 CLI + new check debug API
Signed-off-by: Akos Kitta <[email protected]>
1 parent a6e0eee commit 81f48ca

File tree

10 files changed

+922
-369
lines changed

10 files changed

+922
-369
lines changed

arduino-ide-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
],
170170
"arduino": {
171171
"arduino-cli": {
172-
"version": "0.35.0-rc.5"
172+
"version": "0.35.0-rc.6"
173173
},
174174
"arduino-fwuploader": {
175175
"version": "2.4.1"

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

+43-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MenuModelRegistry } from '@theia/core/lib/common/menu/menu-model-regist
33
import { nls } from '@theia/core/lib/common/nls';
44
import { MaybePromise } from '@theia/core/lib/common/types';
55
import { inject, injectable } from '@theia/core/shared/inversify';
6-
import { noBoardSelected, noSketchOpened } from '../../common/nls';
6+
import { noBoardSelected } from '../../common/nls';
77
import {
88
BoardDetails,
99
BoardIdentifier,
@@ -193,24 +193,30 @@ export class Debug extends SketchContribution {
193193
}
194194
}
195195

196-
private async isDebugEnabled(): Promise<void> {
197-
const sketch = this.sketchServiceClient.tryGetCurrentSketch();
198-
const board = this.boardsServiceProvider.boardsConfig.selectedBoard;
199-
await isDebugEnabled(
200-
sketch,
196+
private async isDebugEnabled(
197+
board: BoardIdentifier | undefined = this.boardsServiceProvider.boardsConfig
198+
.selectedBoard
199+
): Promise<string> {
200+
const debugFqbn = await isDebugEnabled(
201201
board,
202202
(fqbn) => this.boardService.getBoardDetails({ fqbn }),
203203
(fqbn) => this.boardsDataStore.getData(fqbn),
204204
(fqbn) => this.boardsDataStore.appendConfigToFqbn(fqbn),
205-
(params) => this.boardService.checkDebugEnabled(params),
206-
(reason, sketch) => this.isSketchNotVerifiedError(reason, sketch)
205+
(params) => this.boardService.checkDebugEnabled(params)
207206
);
207+
return debugFqbn;
208208
}
209209

210210
private async startDebug(
211211
board: BoardIdentifier | undefined = this.boardsServiceProvider.boardsConfig
212-
.selectedBoard
212+
.selectedBoard,
213+
sketch:
214+
| CurrentSketch
215+
| undefined = this.sketchServiceClient.tryGetCurrentSketch()
213216
): Promise<StartDebugResult> {
217+
if (!CurrentSketch.isValid(sketch)) {
218+
return false;
219+
}
214220
const params = await this.createStartDebugParams(board);
215221
if (!params) {
216222
return false;
@@ -220,6 +226,20 @@ export class Debug extends SketchContribution {
220226
const result = await this.debug(params);
221227
return Boolean(result);
222228
} catch (err) {
229+
if (await this.isSketchNotVerifiedError(err, sketch)) {
230+
const yes = nls.localize('vscode/extensionsUtils/yes', 'Yes');
231+
const answer = await this.messageService.error(
232+
sketchIsNotCompiled(sketch.name),
233+
yes
234+
);
235+
if (answer === yes) {
236+
this.commandService.executeCommand('arduino-verify-sketch');
237+
}
238+
} else {
239+
this.messageService.error(
240+
err instanceof Error ? err.message : String(err)
241+
);
242+
}
223243
console.error(err);
224244
this.messageService.error(
225245
err instanceof Error ? err.message : String(err)
@@ -272,13 +292,20 @@ export class Debug extends SketchContribution {
272292
if (!board || !board.fqbn) {
273293
return undefined;
274294
}
295+
let debugFqbn: string | undefined = undefined;
296+
try {
297+
debugFqbn = await this.isDebugEnabled(board);
298+
} catch {}
299+
if (!debugFqbn) {
300+
return undefined;
301+
}
275302
const [sketch, executables, boardsData] = await Promise.all([
276303
this.sketchServiceClient.currentSketch(),
277304
this.executableService.list(),
278305
this.boardsDataStore.getData(board.fqbn),
279306
]);
280307
if (!CurrentSketch.isValid(sketch)) {
281-
return;
308+
return undefined;
282309
}
283310
const ideTempFolderUri = await this.sketchesService.getIdeTempFolderUri(
284311
sketch
@@ -289,7 +316,7 @@ export class Debug extends SketchContribution {
289316
this.fileService.fsPath(new URI(ideTempFolderUri)),
290317
]);
291318
return {
292-
board: { fqbn: board.fqbn, name: board.name },
319+
board: { fqbn: debugFqbn, name: board.name },
293320
cliPath,
294321
sketchPath,
295322
launchConfigsDirPath,
@@ -329,20 +356,12 @@ export namespace Debug {
329356
* (non-API)
330357
*/
331358
export async function isDebugEnabled(
332-
sketch: CurrentSketch | undefined,
333359
board: BoardIdentifier | undefined,
334360
getDetails: (fqbn: string) => MaybePromise<BoardDetails | undefined>,
335361
getData: (fqbn: string) => MaybePromise<BoardsDataStore.Data>,
336362
appendConfigToFqbn: (fqbn: string) => MaybePromise<string | undefined>,
337-
checkDebugEnabled: (params: CheckDebugEnabledParams) => MaybePromise<void>,
338-
isSketchNotVerifiedError: (
339-
err: unknown,
340-
sketchRef: SketchRef
341-
) => MaybePromise<boolean>
342-
): Promise<void> {
343-
if (!CurrentSketch.isValid(sketch)) {
344-
throw new Error(noSketchOpened);
345-
}
363+
checkDebugEnabled: (params: CheckDebugEnabledParams) => MaybePromise<string>
364+
): Promise<string> {
346365
if (!board) {
347366
throw new Error(noBoardSelected);
348367
}
@@ -369,15 +388,11 @@ export async function isDebugEnabled(
369388
const params = {
370389
fqbn: fqbnWithConfig,
371390
programmer: data.selectedProgrammer.id,
372-
sketchUri: sketch.uri,
373391
};
374392
try {
375-
await checkDebugEnabled(params);
393+
const debugFqbn = await checkDebugEnabled(params);
394+
return debugFqbn;
376395
} catch (err) {
377-
const sketchNotVerified = await isSketchNotVerifiedError(err, sketch);
378-
if (sketchNotVerified) {
379-
throw new Error(sketchIsNotCompiled(sketch.name));
380-
}
381396
throw new Error(debuggingNotSupported(board.name));
382397
}
383398
}
@@ -388,7 +403,7 @@ export async function isDebugEnabled(
388403
export function sketchIsNotCompiled(sketchName: string): string {
389404
return nls.localize(
390405
'arduino/debug/sketchIsNotCompiled',
391-
"Sketch '{0}' must be verified before starting a debug session",
406+
"Sketch '{0}' must be verified before starting a debug session. Please verify the sketch and start debugging again. Do you want to verify the sketch now?",
392407
sketchName
393408
);
394409
}

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ export interface BoardsService
8282
}): Promise<BoardUserField[]>;
8383
/**
8484
* Checks whether the debugging is enabled with the FQBN, programmer, current sketch, and custom board options.
85-
* Rejects when the debugging is unsupported.
85+
*
86+
* When the debugging is enabled, the promise resolves with the FQBN to use with the debugger. This is the same
87+
* FQBN given in the `CheckDebugEnabledParams#fqbn` but cleaned up of the board options that do not affect the debugger configuration.
88+
* It may be used by clients/IDE to group slightly different boards option selections under the same debug configuration.
8689
*/
87-
checkDebugEnabled(params: CheckDebugEnabledParams): Promise<void>;
90+
checkDebugEnabled(params: CheckDebugEnabledParams): Promise<string>;
8891
}
8992

9093
export interface CheckDebugEnabledParams {
94+
/**
95+
* The FQBN might contain custom board config options. For example, `arduino:esp32:nano_nora:USBMode=hwcdc,option2=value2`.
96+
*/
9197
readonly fqbn: string;
9298
readonly programmer: string;
93-
readonly sketchUri: string;
9499
}
95100

96101
export interface BoardSearch extends Searchable.Options {

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

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ILogger } from '@theia/core/lib/common/logger';
22
import { nls } from '@theia/core/lib/common/nls';
33
import { notEmpty } from '@theia/core/lib/common/objects';
4-
import { FileUri } from '@theia/core/lib/node/file-uri';
54
import { inject, injectable } from '@theia/core/shared/inversify';
65
import {
76
Board,
@@ -42,7 +41,7 @@ import {
4241
PlatformSearchResponse,
4342
PlatformUninstallRequest,
4443
} from './cli-protocol/cc/arduino/cli/commands/v1/core_pb';
45-
import { GetDebugConfigRequest } from './cli-protocol/cc/arduino/cli/commands/v1/debug_pb';
44+
import { IsDebugSupportedRequest } from './cli-protocol/cc/arduino/cli/commands/v1/debug_pb';
4645
import {
4746
ListProgrammersAvailableForUploadRequest,
4847
ListProgrammersAvailableForUploadResponse,
@@ -173,30 +172,32 @@ export class BoardsServiceImpl
173172
};
174173
}
175174

176-
async checkDebugEnabled(params: CheckDebugEnabledParams): Promise<void> {
177-
const { fqbn, programmer, sketchUri } = params;
178-
const sketchPath = FileUri.fsPath(sketchUri);
175+
async checkDebugEnabled(params: CheckDebugEnabledParams): Promise<string> {
176+
const { fqbn, programmer } = params;
179177
const { client, instance } = await this.coreClient;
180-
const req = new GetDebugConfigRequest()
178+
const req = new IsDebugSupportedRequest()
181179
.setInstance(instance)
182180
.setFqbn(fqbn)
183-
.setProgrammer(programmer)
184-
.setSketchPath(sketchPath);
181+
.setProgrammer(programmer);
185182
try {
186-
await new Promise<void>((resolve, reject) =>
187-
client.getDebugConfig(req, (err) => {
183+
const debugFqbn = await new Promise<string>((resolve, reject) =>
184+
client.isDebugSupported(req, (err, resp) => {
188185
if (err) {
189186
reject(err);
190-
} else {
191-
resolve();
187+
return;
188+
}
189+
if (resp.getDebuggingSupported()) {
190+
const debugFqbn = resp.getDebugFqbn();
191+
if (debugFqbn) {
192+
resolve(debugFqbn);
193+
}
192194
}
195+
reject(new Error(`Debugging is not supported.`));
193196
})
194197
);
198+
return debugFqbn;
195199
} catch (err) {
196-
console.error(
197-
`Failed to get debug config: ${fqbn}, ${programmer}, ${sketchPath}`,
198-
err
199-
);
200+
console.error(`Failed to get debug config: ${fqbn}, ${programmer}`, err);
200201
throw err;
201202
}
202203
}

arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ interface IArduinoCoreServiceService extends grpc.ServiceDefinition<grpc.Untyped
5757
monitor: IArduinoCoreServiceService_IMonitor;
5858
enumerateMonitorPortSettings: IArduinoCoreServiceService_IEnumerateMonitorPortSettings;
5959
debug: IArduinoCoreServiceService_IDebug;
60+
isDebugSupported: IArduinoCoreServiceService_IIsDebugSupported;
6061
getDebugConfig: IArduinoCoreServiceService_IGetDebugConfig;
6162
}
6263

@@ -420,6 +421,15 @@ interface IArduinoCoreServiceService_IDebug extends grpc.MethodDefinition<cc_ard
420421
responseSerialize: grpc.serialize<cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
421422
responseDeserialize: grpc.deserialize<cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
422423
}
424+
interface IArduinoCoreServiceService_IIsDebugSupported extends grpc.MethodDefinition<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse> {
425+
path: "/cc.arduino.cli.commands.v1.ArduinoCoreService/IsDebugSupported";
426+
requestStream: false;
427+
responseStream: false;
428+
requestSerialize: grpc.serialize<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest>;
429+
requestDeserialize: grpc.deserialize<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest>;
430+
responseSerialize: grpc.serialize<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse>;
431+
responseDeserialize: grpc.deserialize<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse>;
432+
}
423433
interface IArduinoCoreServiceService_IGetDebugConfig extends grpc.MethodDefinition<cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse> {
424434
path: "/cc.arduino.cli.commands.v1.ArduinoCoreService/GetDebugConfig";
425435
requestStream: false;
@@ -473,6 +483,7 @@ export interface IArduinoCoreServiceServer extends grpc.UntypedServiceImplementa
473483
monitor: grpc.handleBidiStreamingCall<cc_arduino_cli_commands_v1_monitor_pb.MonitorRequest, cc_arduino_cli_commands_v1_monitor_pb.MonitorResponse>;
474484
enumerateMonitorPortSettings: grpc.handleUnaryCall<cc_arduino_cli_commands_v1_monitor_pb.EnumerateMonitorPortSettingsRequest, cc_arduino_cli_commands_v1_monitor_pb.EnumerateMonitorPortSettingsResponse>;
475485
debug: grpc.handleBidiStreamingCall<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
486+
isDebugSupported: grpc.handleUnaryCall<cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse>;
476487
getDebugConfig: grpc.handleUnaryCall<cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse>;
477488
}
478489

@@ -578,6 +589,9 @@ export interface IArduinoCoreServiceClient {
578589
debug(): grpc.ClientDuplexStream<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
579590
debug(options: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
580591
debug(metadata: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
592+
isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
593+
isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
594+
isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
581595
getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;
582596
getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;
583597
getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;
@@ -684,6 +698,9 @@ export class ArduinoCoreServiceClient extends grpc.Client implements IArduinoCor
684698
public enumerateMonitorPortSettings(request: cc_arduino_cli_commands_v1_monitor_pb.EnumerateMonitorPortSettingsRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_monitor_pb.EnumerateMonitorPortSettingsResponse) => void): grpc.ClientUnaryCall;
685699
public debug(options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
686700
public debug(metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<cc_arduino_cli_commands_v1_debug_pb.DebugRequest, cc_arduino_cli_commands_v1_debug_pb.DebugResponse>;
701+
public isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
702+
public isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
703+
public isDebugSupported(request: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse) => void): grpc.ClientUnaryCall;
687704
public getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;
688705
public getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;
689706
public getDebugConfig(request: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: cc_arduino_cli_commands_v1_debug_pb.GetDebugConfigResponse) => void): grpc.ClientUnaryCall;

arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ function deserialize_cc_arduino_cli_commands_v1_InitResponse(buffer_arg) {
358358
return cc_arduino_cli_commands_v1_commands_pb.InitResponse.deserializeBinary(new Uint8Array(buffer_arg));
359359
}
360360

361+
function serialize_cc_arduino_cli_commands_v1_IsDebugSupportedRequest(arg) {
362+
if (!(arg instanceof cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest)) {
363+
throw new Error('Expected argument of type cc.arduino.cli.commands.v1.IsDebugSupportedRequest');
364+
}
365+
return Buffer.from(arg.serializeBinary());
366+
}
367+
368+
function deserialize_cc_arduino_cli_commands_v1_IsDebugSupportedRequest(buffer_arg) {
369+
return cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest.deserializeBinary(new Uint8Array(buffer_arg));
370+
}
371+
372+
function serialize_cc_arduino_cli_commands_v1_IsDebugSupportedResponse(arg) {
373+
if (!(arg instanceof cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse)) {
374+
throw new Error('Expected argument of type cc.arduino.cli.commands.v1.IsDebugSupportedResponse');
375+
}
376+
return Buffer.from(arg.serializeBinary());
377+
}
378+
379+
function deserialize_cc_arduino_cli_commands_v1_IsDebugSupportedResponse(buffer_arg) {
380+
return cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse.deserializeBinary(new Uint8Array(buffer_arg));
381+
}
382+
361383
function serialize_cc_arduino_cli_commands_v1_LibraryDownloadRequest(arg) {
362384
if (!(arg instanceof cc_arduino_cli_commands_v1_lib_pb.LibraryDownloadRequest)) {
363385
throw new Error('Expected argument of type cc.arduino.cli.commands.v1.LibraryDownloadRequest');
@@ -1424,7 +1446,20 @@ debug: {
14241446
responseSerialize: serialize_cc_arduino_cli_commands_v1_DebugResponse,
14251447
responseDeserialize: deserialize_cc_arduino_cli_commands_v1_DebugResponse,
14261448
},
1427-
getDebugConfig: {
1449+
// Determine if debugging is suported given a specific configuration.
1450+
isDebugSupported: {
1451+
path: '/cc.arduino.cli.commands.v1.ArduinoCoreService/IsDebugSupported',
1452+
requestStream: false,
1453+
responseStream: false,
1454+
requestType: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedRequest,
1455+
responseType: cc_arduino_cli_commands_v1_debug_pb.IsDebugSupportedResponse,
1456+
requestSerialize: serialize_cc_arduino_cli_commands_v1_IsDebugSupportedRequest,
1457+
requestDeserialize: deserialize_cc_arduino_cli_commands_v1_IsDebugSupportedRequest,
1458+
responseSerialize: serialize_cc_arduino_cli_commands_v1_IsDebugSupportedResponse,
1459+
responseDeserialize: deserialize_cc_arduino_cli_commands_v1_IsDebugSupportedResponse,
1460+
},
1461+
// Query the debugger information given a specific configuration.
1462+
getDebugConfig: {
14281463
path: '/cc.arduino.cli.commands.v1.ArduinoCoreService/GetDebugConfig',
14291464
requestStream: false,
14301465
responseStream: false,

0 commit comments

Comments
 (0)