Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be88074

Browse files
author
Akos Kitta
committed
feat: handle when starting debug session failed
If the sketch has not been verified, IDE2 offers user a verify action. Closes #808 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent afb02da commit be88074

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

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

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { Event, Emitter } from '@theia/core/lib/common/event';
33
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
44
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
55
import { NotificationCenter } from '../notification-center';
6-
import { Board, BoardsService, ExecutableService } from '../../common/protocol';
6+
import {
7+
Board,
8+
BoardsService,
9+
ExecutableService,
10+
Sketch,
11+
} from '../../common/protocol';
712
import { BoardsServiceProvider } from '../boards/boards-service-provider';
813
import {
914
URI,
@@ -16,9 +21,8 @@ import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common';
1621
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1722
import { ArduinoMenus } from '../menu/arduino-menus';
1823

19-
import { MainMenuManager } from '../../common/main-menu-manager';
20-
2124
const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
25+
2226
@injectable()
2327
export class Debug extends SketchContribution {
2428
@inject(HostedPluginSupport)
@@ -36,9 +40,6 @@ export class Debug extends SketchContribution {
3640
@inject(BoardsServiceProvider)
3741
private readonly boardsServiceProvider: BoardsServiceProvider;
3842

39-
@inject(MainMenuManager)
40-
private readonly mainMenuManager: MainMenuManager;
41-
4243
/**
4344
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
4445
*/
@@ -203,7 +204,28 @@ export class Debug extends SketchContribution {
203204
sketchPath,
204205
configPath,
205206
};
206-
return this.commandService.executeCommand('arduino.debug.start', config);
207+
try {
208+
await this.commandService.executeCommand('arduino.debug.start', config);
209+
} catch (err) {
210+
if (await this.isSketchNotVerifiedError(err, sketch)) {
211+
const yes = nls.localize('vscode/extensionsUtils/yes', 'Yes');
212+
const answer = await this.messageService.error(
213+
nls.localize(
214+
'arduino/debug/sketchIsNotCompiled',
215+
"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?",
216+
sketch.name
217+
),
218+
yes
219+
);
220+
if (answer === yes) {
221+
this.commandService.executeCommand('arduino-verify-sketch');
222+
}
223+
} else {
224+
this.messageService.error(
225+
err instanceof Error ? err.message : String(err)
226+
);
227+
}
228+
}
207229
}
208230

209231
get compileForDebug(): boolean {
@@ -215,7 +237,22 @@ export class Debug extends SketchContribution {
215237
const oldState = this.compileForDebug;
216238
const newState = !oldState;
217239
window.localStorage.setItem(COMPILE_FOR_DEBUG_KEY, String(newState));
218-
this.mainMenuManager.update();
240+
this.menuManager.update();
241+
}
242+
243+
private async isSketchNotVerifiedError(
244+
err: unknown,
245+
sketch: Sketch
246+
): Promise<boolean> {
247+
if (err instanceof Error) {
248+
try {
249+
const tempBuildPath = await this.sketchService.tempBuildPath(sketch);
250+
return err.message.includes(tempBuildPath);
251+
} catch {
252+
return false;
253+
}
254+
}
255+
return false;
219256
}
220257
}
221258
export namespace Debug {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ export interface SketchesService {
105105
* Recursively deletes the sketch folder with all its content.
106106
*/
107107
deleteSketch(sketch: Sketch): Promise<void>;
108+
109+
/**
110+
* This is the JS/TS re-implementation of [`GenBuildPath`](https://github.com/arduino/arduino-cli/blob/c0d4e4407d80aabad81142693513b3306759cfa6/arduino/sketch/sketch.go#L296-L306) of the CLI.
111+
* Pass in a sketch and get the build temporary folder filesystem path calculated from the main sketch file location. This method does not check the existence of the sketch.
112+
*/
113+
tempBuildPath(sketch: Sketch): Promise<string>;
108114
}
109115

110116
export interface SketchRef {

‎arduino-ide-extension/src/node/is-temp-sketch.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export const TempSketchPrefix = '.arduinoIDE-unsaved';
1010
@injectable()
1111
export class IsTempSketch {
1212
// If on macOS, the `temp-dir` lib will make sure there is resolved realpath.
13-
// If on Windows, the `C:\Users\KITTAA~1\AppData\Local\Temp` path will be resolved and normalized to `C:\Users\kittaakos\AppData\Local\Temp`.
13+
// If on Windows, the `C:\Users\KITTAA~1\AppData\Local\Temp` path will be resolved and normalized to `c:\Users\kittaakos\AppData\Local\Temp`.
1414
// Note: VS Code URI normalizes the drive letter. `C:` will be converted into `c:`.
1515
// https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992
16-
privatereadonly tempDirRealpath = isOSX
16+
readonly tempDirRealpath = isOSX
1717
? tempDir
1818
: maybeNormalizeDrive(fs.realpathSync.native(tempDir));
1919

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,24 @@ export class SketchesServiceImpl
566566
return FileUri.create(genBuildPath).toString();
567567
}
568568

569-
async getIdeTempFolderPath(sketch: Sketch): Promise<string> {
569+
privateasync getIdeTempFolderPath(sketch: Sketch): Promise<string> {
570570
const sketchPath = FileUri.fsPath(sketch.uri);
571571
await fs.readdir(sketchPath); // Validates the sketch folder and rejects if not accessible.
572572
const suffix = crypto.createHash('md5').update(sketchPath).digest('hex');
573-
return path.join(os.tmpdir(), `arduino-ide2-${suffix}`);
573+
return path.join(
574+
this.isTempSketch.tempDirRealpath,
575+
`arduino-ide2-${suffix}`
576+
);
577+
}
578+
579+
async tempBuildPath(sketch: Sketch): Promise<string> {
580+
const sketchPath = FileUri.fsPath(sketch.uri);
581+
const hash = crypto
582+
.createHash('md5')
583+
.update(sketchPath)
584+
.digest('hex')
585+
.toUpperCase();
586+
return join(this.isTempSketch.tempDirRealpath, `arduino-sketch-${hash}`);
574587
}
575588

576589
async deleteSketch(sketch: Sketch): Promise<void> {

‎i18n/en.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191
"debugWithMessage": "Debug - {0}",
192192
"debuggingNotSupported": "Debugging is not supported by '{0}'",
193193
"noPlatformInstalledFor": "Platform is not installed for '{0}'",
194-
"optimizeForDebugging": "Optimize for Debugging"
194+
"optimizeForDebugging": "Optimize for Debugging",
195+
"sketchIsNotCompiled": "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?"
195196
},
196197
"dialog": {
197198
"dontAskAgain": "Don't ask again"

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"theiaPluginsDir": "plugins",
7676
"theiaPlugins": {
7777
"vscode-builtin-cpp": "https://open-vsx.org/api/vscode/cpp/1.52.1/file/vscode.cpp-1.52.1.vsix",
78-
"vscode-arduino-tools": "https://downloads.arduino.cc/vscode-arduino-tools/vscode-arduino-tools-0.0.2-beta.5.vsix",
78+
"vscode-arduino-tools": "https://downloads.arduino.cc/vscode-arduino-tools/vscode-arduino-tools-0.0.2-beta.7.vsix",
7979
"vscode-builtin-json": "https://open-vsx.org/api/vscode/json/1.46.1/file/vscode.json-1.46.1.vsix",
8080
"vscode-builtin-json-language-features": "https://open-vsx.org/api/vscode/json-language-features/1.46.1/file/vscode.json-language-features-1.46.1.vsix",
8181
"cortex-debug": "https://downloads.arduino.cc/marus25.cortex-debug/marus25.cortex-debug-1.5.1.vsix",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /