Skip to content

#1089: IDE falls back to new sketch if opening failed #1152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
get rid of old editor mode. use a preference.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Jul 18, 2022
commit baa9936b70f23e87698e66c4e25c3be1de611e7e
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import { BoardsToolBarItem } from './boards/boards-toolbar-item';
import { OpenSketchFiles } from './contributions/open-sketch-files';
import { SaveAsSketch } from './contributions/save-as-sketch';
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
import { EditorMode } from './editor-mode';
import { ArduinoMenus } from './menu/arduino-menus';
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
Expand Down Expand Up @@ -96,9 +95,6 @@ export class ArduinoFrontendContribution
@inject(StatusBar)
private readonly statusBar: StatusBar;

@inject(EditorMode)
private readonly editorMode: EditorMode;

@inject(ArduinoPreferences)
private readonly arduinoPreferences: ArduinoPreferences;

Expand Down Expand Up @@ -295,10 +291,6 @@ export class ArduinoFrontendContribution
}

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
execute: () => this.editorMode.toggleCompileForDebug(),
isToggled: () => this.editorMode.compileForDebug,
});
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
execute: async (query?: string | undefined) => {
const boardsConfig = await this.boardsConfigDialog.open(query);
Expand Down Expand Up @@ -340,14 +332,6 @@ export class ArduinoFrontendContribution
ArduinoMenus.TOOLS,
nls.localize('arduino/menu/tools', 'Tools')
);
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id,
label: nls.localize(
'arduino/debug/optimizeForDebugging',
'Optimize for Debugging'
),
order: '5',
});
}

registerColors(colors: ColorRegistry): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import { ProblemManager as TheiaProblemManager } from '@theia/markers/lib/browse
import { ProblemManager } from './theia/markers/problem-manager';
import { BoardsAutoInstaller } from './boards/boards-auto-installer';
import { ShellLayoutRestorer } from './theia/core/shell-layout-restorer';
import { EditorMode } from './editor-mode';
import { ListItemRenderer } from './widgets/component-list/list-item-renderer';
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
import { MonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
Expand Down Expand Up @@ -489,10 +488,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
WorkspaceVariableContribution
);

// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
bind(EditorMode).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(EditorMode);

bind(SurveyNotificationService)
.toDynamicValue((context) => {
return ElectronIpcConnectionProvider.createProxy(
Expand Down
9 changes: 9 additions & 0 deletions arduino-ide-extension/src/browser/arduino-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ 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(
Expand Down Expand Up @@ -251,6 +259,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
CommandContribution,
CommandService,
} from '@theia/core/lib/common/command';
import { EditorMode } from '../editor-mode';
import { SettingsService } from '../dialogs/settings/settings';
import {
CurrentSketch,
Expand Down Expand Up @@ -90,9 +89,6 @@ export abstract class Contribution
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

@inject(EditorMode)
protected readonly editorMode: EditorMode;

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

Expand Down
67 changes: 53 additions & 14 deletions arduino-ide-extension/src/browser/contributions/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,54 @@ import {
SketchContribution,
TabBarToolbarRegistry,
} from './contribution';
import { MaybePromise, nls } from '@theia/core/lib/common';
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';

@injectable()
export class Debug extends SketchContribution {
@inject(HostedPluginSupport)
protected hostedPluginSupport: HostedPluginSupport;
private readonly hostedPluginSupport: HostedPluginSupport;

@inject(NotificationCenter)
protected readonly notificationCenter: NotificationCenter;
private readonly notificationCenter: NotificationCenter;

@inject(ExecutableService)
protected readonly executableService: ExecutableService;
private readonly executableService: ExecutableService;

@inject(BoardsService)
protected readonly boardService: BoardsService;
private readonly boardService: BoardsService;

@inject(BoardsServiceProvider)
protected readonly boardsServiceProvider: BoardsServiceProvider;
private readonly boardsServiceProvider: BoardsServiceProvider;

@inject(PreferenceService)
private readonly preferenceService: PreferenceService;

/**
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
*/
protected _disabledMessages?: string = nls.localize(
private _disabledMessages?: string = nls.localize(
'arduino/common/noBoardSelected',
'No board selected'
); // Initial pessimism.
protected disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
protected onDisabledMessageDidChange =
private disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
private onDisabledMessageDidChange =
this.disabledMessageDidChangeEmitter.event;

protected get disabledMessage(): string | undefined {
private get disabledMessage(): string | undefined {
return this._disabledMessages;
}
protected set disabledMessage(message: string | undefined) {
private set disabledMessage(message: string | undefined) {
this._disabledMessages = message;
this.disabledMessageDidChangeEmitter.fire(this._disabledMessages);
}

protected readonly debugToolbarItem = {
private readonly debugToolbarItem = {
id: Debug.Commands.START_DEBUGGING.id,
command: Debug.Commands.START_DEBUGGING.id,
tooltip: `${
Expand Down Expand Up @@ -98,12 +106,24 @@ 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(),
});
}

override registerToolbarItems(registry: TabBarToolbarRegistry): void {
registry.registerItem(this.debugToolbarItem);
}

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,
order: '5',
});
}

private async refreshState(
board: Board | undefined = this.boardsServiceProvider.boardsConfig
.selectedBoard
Expand Down Expand Up @@ -145,7 +165,7 @@ export class Debug extends SketchContribution {
}
}

protected async startDebug(
private async startDebug(
board: Board | undefined = this.boardsServiceProvider.boardsConfig
.selectedBoard
): Promise<void> {
Expand Down Expand Up @@ -183,8 +203,19 @@ export class Debug extends SketchContribution {
};
return this.commandService.executeCommand('arduino.debug.start', config);
}
}

private isOptimizeForDebug(): boolean {
return this.preferences.get('arduino.compile.optimizeForDebug');
}

private async toggleOptimizeForDebug(): Promise<void> {
return this.preferenceService.set(
'arduino.compile.optimizeForDebug',
!this.isOptimizeForDebug(),
PreferenceScope.User
);
}
}
export namespace Debug {
export namespace Commands {
export const START_DEBUGGING = Command.toLocalizedCommand(
Expand All @@ -195,5 +226,13 @@ export namespace Debug {
},
'vscode/debug.contribution/startDebuggingHelp'
);
export const OPTIMIZE_FOR_DEBUG = Command.toLocalizedCommand(
{
id: 'arduino-optimize-for-debug',
label: 'Optimize for Debugging',
category: 'Arduino',
},
'arduino/debug/optimizeForDebugging'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { HostedPluginEvents } from '../hosted-plugin-events';
import { SketchContribution, URI } from './contribution';
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
import { ArduinoPreferences } from '../arduino-preferences';
import { BoardsConfig } from '../boards/boards-config';
import { BoardsServiceProvider } from '../boards/boards-service-provider';

Expand All @@ -29,9 +28,6 @@ export class InoLanguage extends SketchContribution {
@inject(BoardsServiceProvider)
private readonly boardsServiceProvider: BoardsServiceProvider;

@inject(ArduinoPreferences)
private readonly arduinoPreferences: ArduinoPreferences;

private languageServerFqbn?: string;
private languageServerStartMutex = new Mutex();

Expand All @@ -51,7 +47,7 @@ export class InoLanguage extends SketchContribution {
this.hostedPluginEvents.onPluginsWillUnload(
() => (this.languageServerFqbn = undefined)
);
this.arduinoPreferences.onPreferenceChanged(
this.preferences.onPreferenceChanged(
({ preferenceName, oldValue, newValue }) => {
if (
preferenceName === 'arduino.language.log' &&
Expand Down Expand Up @@ -105,7 +101,7 @@ export class InoLanguage extends SketchContribution {
return;
}
this.logger.info(`Starting language server: ${fqbn}`);
const log = this.arduinoPreferences.get('arduino.language.log');
const log = this.preferences.get('arduino.language.log');
let currentSketchPath: string | undefined = undefined;
if (log) {
const currentSketch = await this.sketchServiceClient.currentSketch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export class UploadSketch extends CoreServiceContribution {
fqbn,
};
let options: CoreService.Upload.Options | undefined = undefined;
const optimizeForDebug = this.editorMode.compileForDebug;
const optimizeForDebug = this.preferences.get(
'arduino.compile.optimizeForDebug'
);
const { selectedPort } = boardsConfig;
const port = selectedPort;
const userFields =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ 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'
);
this.outputChannelManager.getChannel('Arduino').clear();
await this.coreService.compile({
sketch,
board,
optimizeForDebug: this.editorMode.compileForDebug,
optimizeForDebug,
verbose,
exportBinaries,
sourceOverride,
Expand Down
37 changes: 0 additions & 37 deletions arduino-ide-extension/src/browser/editor-mode.ts

This file was deleted.