diff --git a/arduino-ide-extension/src/browser/arduino-preferences.ts b/arduino-ide-extension/src/browser/arduino-preferences.ts index bc9cdb099..e0bef3e58 100644 --- a/arduino-ide-extension/src/browser/arduino-preferences.ts +++ b/arduino-ide-extension/src/browser/arduino-preferences.ts @@ -137,6 +137,18 @@ const properties: ArduinoPreferenceSchemaProperties = { 'arduino.upload.verify': { type: 'boolean', default: false, + description: nls.localize( + 'arduino/preferences/upload.verify', + 'After upload, verify that the contents of the memory on the board match the uploaded binary.' + ), + }, + 'arduino.upload.autoVerify': { + type: 'boolean', + default: true, + description: nls.localize( + 'arduino/preferences/upload.autoVerify', + "True if the IDE should automatically verify the code before the upload. True by default. When this value is false, IDE does not recompile the code before uploading the binary to the board. It's highly advised to only set this value to false if you know what you are doing." + ), }, 'arduino.window.autoScale': { type: 'boolean', @@ -319,6 +331,7 @@ export interface ArduinoConfiguration { 'arduino.compile.warnings': CompilerWarnings; 'arduino.upload.verbose': boolean; 'arduino.upload.verify': boolean; + 'arduino.upload.autoVerify': boolean; 'arduino.window.autoScale': boolean; 'arduino.ide.updateChannel': UpdateChannel; 'arduino.ide.updateBaseUrl': string; diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 9cee46abb..b38ab17bc 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -104,6 +104,7 @@ export class UploadSketch extends CoreServiceContribution { } try { + const autoVerify = this.preferences['arduino.upload.autoVerify']; // toggle the toolbar button and menu item state. // uploadInProgress will be set to false whether the upload fails or not this.uploadInProgress = true; @@ -116,7 +117,7 @@ export class UploadSketch extends CoreServiceContribution { 'arduino-verify-sketch', { exportBinaries: false, - silent: true, + mode: autoVerify ? 'auto' : 'dry-run', } ); if (!verifyOptions) { diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 999c3ec5c..4d8b445e3 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -15,23 +15,35 @@ import { } from './contribution'; import { CoreErrorHandler } from './core-error-handler'; +export type VerifySketchMode = + /** + * When the user explicitly triggers the verify command from the primary UI: menu, toolbar, or keybinding. The UI shows the output, updates the toolbar items state, etc. + */ + | 'explicit' + /** + * When the verify phase automatically runs as part of the upload but there is no UI indication of the command: the toolbar items do not update. + */ + | 'auto' + /** + * The verify does not run. There is no UI indication of the command. For example, when the user decides to disable the auto verify (`'arduino.upload.autoVerify'`) to skips the code recompilation phase. + */ + | 'dry-run'; + export interface VerifySketchParams { /** * Same as `CoreService.Options.Compile#exportBinaries` */ readonly exportBinaries?: boolean; /** - * If `true`, there won't be any UI indication of the verify command in the toolbar. It's `false` by default. + * The mode specifying how verify should run. It's `'explicit'` by default. */ - readonly silent?: boolean; + readonly mode?: VerifySketchMode; } /** - * - `"idle"` when neither verify, nor upload is running, - * - `"explicit-verify"` when only verify is running triggered by the user, and - * - `"automatic-verify"` is when the automatic verify phase is running as part of an upload triggered by the user. + * - `"idle"` when neither verify, nor upload is running */ -type VerifyProgress = 'idle' | 'explicit-verify' | 'automatic-verify'; +type VerifyProgress = 'idle' | VerifySketchMode; @injectable() export class VerifySketch extends CoreServiceContribution { @@ -54,10 +66,10 @@ export class VerifySketch extends CoreServiceContribution { registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, { isVisible: (widget) => ArduinoToolbar.is(widget) && widget.side === 'left', - isEnabled: () => this.verifyProgress !== 'explicit-verify', + isEnabled: () => this.verifyProgress !== 'explicit', // toggled only when verify is running, but not toggled when automatic verify is running before the upload // https://github.com/arduino/arduino-ide/pull/1750#pullrequestreview-1214762975 - isToggled: () => this.verifyProgress === 'explicit-verify', + isToggled: () => this.verifyProgress === 'explicit', execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id), }); @@ -113,19 +125,22 @@ export class VerifySketch extends CoreServiceContribution { } try { - this.verifyProgress = params?.silent - ? 'automatic-verify' - : 'explicit-verify'; + this.verifyProgress = params?.mode ?? 'explicit'; this.onDidChangeEmitter.fire(); this.menuManager.update(); this.clearVisibleNotification(); this.coreErrorHandler.reset(); + const dryRun = this.verifyProgress === 'dry-run'; const options = await this.options(params?.exportBinaries); if (!options) { return undefined; } + if (dryRun) { + return options; + } + await this.doWithProgress({ progressText: nls.localize( 'arduino/sketch/compile', diff --git a/i18n/en.json b/i18n/en.json index c83d280c1..06f6d0f8b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -411,7 +411,9 @@ "survey.notification": "True if users should be notified if a survey is available. True by default.", "unofficialBoardSupport": "Click for a list of unofficial board support URLs", "upload": "upload", + "upload.autoVerify": "True if the IDE should automatically verify the code before the upload. True by default. When this value is false, IDE does not recompile the code before uploading the binary to the board. It's highly advised to only set this value to false if you know what you are doing.", "upload.verbose": "True for verbose upload output. False by default.", + "upload.verify": "After upload, verify that the contents of the memory on the board match the uploaded binary.", "verifyAfterUpload": "Verify code after upload", "window.autoScale": "True if the user interface automatically scales with the font size.", "window.zoomLevel": {