feat: can skip verify before upload

Adds a new preference to control whether the
verify command should automatically run before the
upload. If the `arduino.upload.autoVerify` setting
value is `false`, IDE does not recompile the
sketch code before uploading it to the board.

Signed-off-by: dankeboy36 <dankeboy36@gmail.com>
This commit is contained in:
dankeboy36 2024-03-10 09:54:43 +01:00 committed by Giacomo Cusinato
parent d1065886ef
commit 48d6d37539
4 changed files with 43 additions and 12 deletions

View File

@ -137,6 +137,18 @@ const properties: ArduinoPreferenceSchemaProperties = {
'arduino.upload.verify': { 'arduino.upload.verify': {
type: 'boolean', type: 'boolean',
default: false, 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': { 'arduino.window.autoScale': {
type: 'boolean', type: 'boolean',
@ -327,6 +339,7 @@ export interface ArduinoConfiguration {
'arduino.compile.warnings': CompilerWarnings; 'arduino.compile.warnings': CompilerWarnings;
'arduino.upload.verbose': boolean; 'arduino.upload.verbose': boolean;
'arduino.upload.verify': boolean; 'arduino.upload.verify': boolean;
'arduino.upload.autoVerify': boolean;
'arduino.window.autoScale': boolean; 'arduino.window.autoScale': boolean;
'arduino.ide.updateChannel': UpdateChannel; 'arduino.ide.updateChannel': UpdateChannel;
'arduino.ide.updateBaseUrl': string; 'arduino.ide.updateBaseUrl': string;

View File

@ -104,6 +104,7 @@ export class UploadSketch extends CoreServiceContribution {
} }
try { try {
const autoVerify = this.preferences['arduino.upload.autoVerify'];
// toggle the toolbar button and menu item state. // toggle the toolbar button and menu item state.
// uploadInProgress will be set to false whether the upload fails or not // uploadInProgress will be set to false whether the upload fails or not
this.uploadInProgress = true; this.uploadInProgress = true;
@ -116,7 +117,7 @@ export class UploadSketch extends CoreServiceContribution {
'arduino-verify-sketch', 'arduino-verify-sketch',
<VerifySketchParams>{ <VerifySketchParams>{
exportBinaries: false, exportBinaries: false,
silent: true, mode: autoVerify ? 'auto' : 'dry-run',
} }
); );
if (!verifyOptions) { if (!verifyOptions) {

View File

@ -15,23 +15,35 @@ import {
} from './contribution'; } from './contribution';
import { CoreErrorHandler } from './core-error-handler'; 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 { export interface VerifySketchParams {
/** /**
* Same as `CoreService.Options.Compile#exportBinaries` * Same as `CoreService.Options.Compile#exportBinaries`
*/ */
readonly exportBinaries?: boolean; 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, * - `"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.
*/ */
type VerifyProgress = 'idle' | 'explicit-verify' | 'automatic-verify'; type VerifyProgress = 'idle' | VerifySketchMode;
@injectable() @injectable()
export class VerifySketch extends CoreServiceContribution { export class VerifySketch extends CoreServiceContribution {
@ -54,10 +66,10 @@ export class VerifySketch extends CoreServiceContribution {
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, { registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
isVisible: (widget) => isVisible: (widget) =>
ArduinoToolbar.is(widget) && widget.side === 'left', 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 // 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 // https://github.com/arduino/arduino-ide/pull/1750#pullrequestreview-1214762975
isToggled: () => this.verifyProgress === 'explicit-verify', isToggled: () => this.verifyProgress === 'explicit',
execute: () => execute: () =>
registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id), registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id),
}); });
@ -113,19 +125,22 @@ export class VerifySketch extends CoreServiceContribution {
} }
try { try {
this.verifyProgress = params?.silent this.verifyProgress = params?.mode ?? 'explicit';
? 'automatic-verify'
: 'explicit-verify';
this.onDidChangeEmitter.fire(); this.onDidChangeEmitter.fire();
this.menuManager.update(); this.menuManager.update();
this.clearVisibleNotification(); this.clearVisibleNotification();
this.coreErrorHandler.reset(); this.coreErrorHandler.reset();
const dryRun = this.verifyProgress === 'dry-run';
const options = await this.options(params?.exportBinaries); const options = await this.options(params?.exportBinaries);
if (!options) { if (!options) {
return undefined; return undefined;
} }
if (dryRun) {
return options;
}
await this.doWithProgress({ await this.doWithProgress({
progressText: nls.localize( progressText: nls.localize(
'arduino/sketch/compile', 'arduino/sketch/compile',

View File

@ -415,7 +415,9 @@
"survey.notification": "True if users should be notified if a survey is available. True by default.", "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", "unofficialBoardSupport": "Click for a list of unofficial board support URLs",
"upload": "upload", "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.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", "verifyAfterUpload": "Verify code after upload",
"window.autoScale": "True if the user interface automatically scales with the font size.", "window.autoScale": "True if the user interface automatically scales with the font size.",
"window.zoomLevel": { "window.zoomLevel": {