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': {
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',
@ -327,6 +339,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;

View File

@ -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',
<VerifySketchParams>{
exportBinaries: false,
silent: true,
mode: autoVerify ? 'auto' : 'dry-run',
}
);
if (!verifyOptions) {

View File

@ -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',

View File

@ -415,7 +415,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": {