diff --git a/arduino-ide-extension/src/browser/arduino-preferences.ts b/arduino-ide-extension/src/browser/arduino-preferences.ts index 3db30a72f..f9875a6fc 100644 --- a/arduino-ide-extension/src/browser/arduino-preferences.ts +++ b/arduino-ide-extension/src/browser/arduino-preferences.ts @@ -92,14 +92,6 @@ export const ArduinoConfigSchema: PreferenceSchema = { ), default: 'None', }, - 'arduino.compile.optimizeForDebug': { - type: 'boolean', - description: nls.localize( - 'arduino/preferences/compile.optimizeForDebug', - "Optimize compile output for debug, not for release. It's 'false' by default." - ), - default: false, - }, 'arduino.upload.verbose': { type: 'boolean', description: nls.localize( @@ -259,7 +251,6 @@ export interface ArduinoConfiguration { 'arduino.compile.experimental': boolean; 'arduino.compile.revealRange': ErrorRevealStrategy; 'arduino.compile.warnings': CompilerWarnings; - 'arduino.compile.optimizeForDebug': boolean; 'arduino.upload.verbose': boolean; 'arduino.upload.verify': boolean; 'arduino.window.autoScale': boolean; diff --git a/arduino-ide-extension/src/browser/contributions/debug.ts b/arduino-ide-extension/src/browser/contributions/debug.ts index b7f97b4b2..6f1f70826 100644 --- a/arduino-ide-extension/src/browser/contributions/debug.ts +++ b/arduino-ide-extension/src/browser/contributions/debug.ts @@ -14,11 +14,10 @@ import { import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common'; import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl'; import { ArduinoMenus } from '../menu/arduino-menus'; -import { - PreferenceScope, - PreferenceService, -} from '@theia/core/lib/browser/preferences/preference-service'; +import { MainMenuManager } from '../../common/main-menu-manager'; + +const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug'; @injectable() export class Debug extends SketchContribution { @inject(HostedPluginSupport) @@ -36,8 +35,8 @@ export class Debug extends SketchContribution { @inject(BoardsServiceProvider) private readonly boardsServiceProvider: BoardsServiceProvider; - @inject(PreferenceService) - private readonly preferenceService: PreferenceService; + @inject(MainMenuManager) + private readonly mainMenuManager: MainMenuManager; /** * If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled. @@ -105,16 +104,19 @@ export class Debug extends SketchContribution { ArduinoToolbar.is(widget) && widget.side === 'left', isEnabled: () => !this.disabledMessage, }); - registry.registerCommand(Debug.Commands.OPTIMIZE_FOR_DEBUG, { - execute: () => this.toggleOptimizeForDebug(), - isToggled: () => this.isOptimizeForDebug(), + registry.registerCommand(Debug.Commands.TOGGLE_OPTIMIZE_FOR_DEBUG, { + execute: () => this.toggleCompileForDebug(), + isToggled: () => this.compileForDebug, + }); + registry.registerCommand(Debug.Commands.IS_OPTIMIZE_FOR_DEBUG, { + execute: () => this.compileForDebug, }); } override registerMenus(registry: MenuModelRegistry): void { registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, { - commandId: Debug.Commands.OPTIMIZE_FOR_DEBUG.id, - label: Debug.Commands.OPTIMIZE_FOR_DEBUG.label, + commandId: Debug.Commands.TOGGLE_OPTIMIZE_FOR_DEBUG.id, + label: Debug.Commands.TOGGLE_OPTIMIZE_FOR_DEBUG.label, order: '5', }); } @@ -199,16 +201,16 @@ export class Debug extends SketchContribution { return this.commandService.executeCommand('arduino.debug.start', config); } - private isOptimizeForDebug(): boolean { - return this.preferences.get('arduino.compile.optimizeForDebug'); + get compileForDebug(): boolean { + const value = window.localStorage.getItem(COMPILE_FOR_DEBUG_KEY); + return value === 'true'; } - private async toggleOptimizeForDebug(): Promise { - return this.preferenceService.set( - 'arduino.compile.optimizeForDebug', - !this.isOptimizeForDebug(), - PreferenceScope.User - ); + async toggleCompileForDebug(): Promise { + const oldState = this.compileForDebug; + const newState = !oldState; + window.localStorage.setItem(COMPILE_FOR_DEBUG_KEY, String(newState)); + this.mainMenuManager.update(); } } export namespace Debug { @@ -221,13 +223,16 @@ export namespace Debug { }, 'vscode/debug.contribution/startDebuggingHelp' ); - export const OPTIMIZE_FOR_DEBUG = Command.toLocalizedCommand( + export const TOGGLE_OPTIMIZE_FOR_DEBUG = Command.toLocalizedCommand( { - id: 'arduino-optimize-for-debug', + id: 'arduino-toggle-optimize-for-debug', label: 'Optimize for Debugging', category: 'Arduino', }, 'arduino/debug/optimizeForDebugging' ); + export const IS_OPTIMIZE_FOR_DEBUG: Command = { + id: 'arduino-is-optimize-for-debug', + }; } } diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 0c16daf09..8da2b618d 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -210,16 +210,25 @@ export class UploadSketch extends CoreServiceContribution { this.coreErrorHandler.reset(); this.onDidChangeEmitter.fire(); const { boardsConfig } = this.boardsServiceClientImpl; - const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] = - await Promise.all([ - this.boardsDataStore.appendConfigToFqbn( - boardsConfig.selectedBoard?.fqbn - ), - this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn), - this.preferences.get('arduino.upload.verify'), - this.preferences.get('arduino.upload.verbose'), - this.sourceOverride(), - ]); + const [ + fqbn, + { selectedProgrammer }, + verify, + verbose, + sourceOverride, + optimizeForDebug, + ] = await Promise.all([ + this.boardsDataStore.appendConfigToFqbn( + boardsConfig.selectedBoard?.fqbn + ), + this.boardsDataStore.getData(boardsConfig.selectedBoard?.fqbn), + this.preferences.get('arduino.upload.verify'), + this.preferences.get('arduino.upload.verbose'), + this.sourceOverride(), + this.commandService.executeCommand( + 'arduino-is-optimize-for-debug' + ), + ]); const board = { ...boardsConfig.selectedBoard, @@ -227,9 +236,6 @@ export class UploadSketch extends CoreServiceContribution { fqbn, }; let options: CoreService.Upload.Options | undefined = undefined; - const optimizeForDebug = this.preferences.get( - 'arduino.compile.optimizeForDebug' - ); const { selectedPort } = boardsConfig; const port = selectedPort; const userFields = @@ -249,7 +255,7 @@ export class UploadSketch extends CoreServiceContribution { options = { sketch, board, - optimizeForDebug, + optimizeForDebug: Boolean(optimizeForDebug), programmer, port, verbose, @@ -261,7 +267,7 @@ export class UploadSketch extends CoreServiceContribution { options = { sketch, board, - optimizeForDebug, + optimizeForDebug: Boolean(optimizeForDebug), port, verbose, verify, diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 638cbfa16..a7cd1e197 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -114,14 +114,15 @@ export class VerifySketch extends CoreServiceContribution { }; const verbose = this.preferences.get('arduino.compile.verbose'); const compilerWarnings = this.preferences.get('arduino.compile.warnings'); - const optimizeForDebug = this.preferences.get( - 'arduino.compile.optimizeForDebug' - ); + const optimizeForDebug = + await this.commandService.executeCommand( + 'arduino-is-optimize-for-debug' + ); this.outputChannelManager.getChannel('Arduino').clear(); await this.coreService.compile({ sketch, board, - optimizeForDebug, + optimizeForDebug: Boolean(optimizeForDebug), verbose, exportBinaries, sourceOverride, diff --git a/i18n/en.json b/i18n/en.json index d20ac2a63..19a3645e0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -257,7 +257,6 @@ "cloud.sketchSyncEndpoint": "The endpoint used to push and pull sketches from a backend. By default it points to Arduino Cloud API.", "compile": "compile", "compile.experimental": "True if the IDE should handle multiple compiler errors. False by default", - "compile.optimizeForDebug": "Optimize compile output for debug, not for release. It's 'false' by default.", "compile.revealRange": "Adjusts how compiler errors are revealed in the editor after a failed verify/upload. Possible values: 'auto': Scroll vertically as necessary and reveal a line. 'center': Scroll vertically as necessary and reveal a line centered vertically. 'top': Scroll vertically as necessary and reveal a line close to the top of the viewport, optimized for viewing a code definition. 'centerIfOutsideViewport': Scroll vertically as necessary and reveal a line centered vertically only if it lies outside the viewport. The default value is '{0}'.", "compile.verbose": "True for verbose compile output. False by default", "compile.warnings": "Tells gcc which warning level to use. It's 'None' by default",