mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-19 01:06:39 +00:00
Validate workspace/current editor and open file on debug start
Tests whether the current workspace is a sketchfolder and opens the respective ino file or whether the current editor is a ino file. Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
2ba95947de
commit
576f96a502
@ -1,11 +1,16 @@
|
||||
import { injectable, inject } from 'inversify';
|
||||
import { MenuModelRegistry } from '@theia/core';
|
||||
import { MenuModelRegistry, Path, MessageService } from '@theia/core';
|
||||
import { KeybindingRegistry } from '@theia/core/lib/browser';
|
||||
import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||
import { DebugFrontendApplicationContribution, DebugCommands } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
|
||||
import { DebugSessionOptions } from "@theia/debug/lib/browser/debug-session-options";
|
||||
import { EditorMode } from "arduino-ide-extension/lib/browser/editor-mode";
|
||||
import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager';
|
||||
import { ArduinoWorkspaceService } from 'arduino-ide-extension/lib/browser/arduino-workspace-service';
|
||||
import { SketchesService } from 'arduino-ide-extension/lib/common/protocol/sketches-service';
|
||||
import { FileSystem } from '@theia/filesystem/lib/common';
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
import { EditorManager } from '@theia/editor/lib/browser';
|
||||
|
||||
@injectable()
|
||||
export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendApplicationContribution {
|
||||
@ -13,6 +18,21 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
|
||||
@inject(EditorMode)
|
||||
protected readonly editorMode: EditorMode;
|
||||
|
||||
@inject(ArduinoWorkspaceService)
|
||||
protected readonly workspaceService: ArduinoWorkspaceService;
|
||||
|
||||
@inject(SketchesService)
|
||||
protected readonly sketchesService: SketchesService;
|
||||
|
||||
@inject(FileSystem)
|
||||
protected readonly fileSystem: FileSystem;
|
||||
|
||||
@inject(EditorManager)
|
||||
protected readonly editorManager: EditorManager;
|
||||
|
||||
@inject(MessageService)
|
||||
protected readonly messageService: MessageService;
|
||||
|
||||
async start(noDebug?: boolean, debugSessionOptions?: DebugSessionOptions): Promise<void> {
|
||||
const configurations = this.configurations as ArduinoDebugConfigurationManager;
|
||||
let current = debugSessionOptions ? debugSessionOptions : configurations.current;
|
||||
@ -31,7 +51,28 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
|
||||
}
|
||||
};
|
||||
}
|
||||
await this.manager.start(current);
|
||||
if (current.configuration.type === 'arduino') {
|
||||
const wsUri = await this.workspaceService.getDefaultWorkspaceUri();
|
||||
let sketchFileURI: URI | undefined;
|
||||
if (wsUri && await this.sketchesService.isSketchFolder(wsUri)) {
|
||||
const wsPath = new Path(wsUri);
|
||||
const sketchFilePath = wsPath.join(wsPath.name + '.ino').toString();
|
||||
sketchFileURI = new URI(sketchFilePath);
|
||||
} else if (this.editorManager.currentEditor) {
|
||||
const editorURI = this.editorManager.currentEditor.getResourceUri();
|
||||
if (editorURI && editorURI.path && editorURI.path.ext === '.ino') {
|
||||
sketchFileURI = editorURI;
|
||||
}
|
||||
}
|
||||
if (sketchFileURI) {
|
||||
await this.editorManager.open(sketchFileURI);
|
||||
await this.manager.start(current);
|
||||
} else {
|
||||
this.messageService.error('Please open a valid INO file.')
|
||||
}
|
||||
} else {
|
||||
await this.manager.start(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user