GH-432: Made compile/verify work on dirty editors

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2021-02-11 17:53:24 +01:00
committed by Akos Kitta
parent ec1abcc989
commit f1c80041fe
5 changed files with 60 additions and 22 deletions

View File

@@ -1,9 +1,11 @@
import { inject, injectable, interfaces } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { ILogger } from '@theia/core/lib/common/logger';
import { Saveable } from '@theia/core/lib/browser/saveable';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { MaybePromise } from '@theia/core/lib/common/types';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
import { MessageService } from '@theia/core/lib/common/message-service';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
@@ -85,6 +87,23 @@ export abstract class SketchContribution extends Contribution {
@inject(ArduinoPreferences)
protected readonly preferences: ArduinoPreferences;
@inject(EditorManager)
protected readonly editorManager: EditorManager;
protected async sourceOverride(): Promise<Record<string, string>> {
const override: Record<string, string> = {};
const sketch = await this.sketchServiceClient.currentSketch();
if (sketch) {
for (const editor of this.editorManager.all) {
const uri = editor.editor.uri;
if (Saveable.isDirty(editor) && Sketch.isInSketch(uri, sketch)) {
override[uri.toString()] = editor.editor.document.getText();
}
}
}
return override;
}
}
export namespace Contribution {

View File

@@ -73,8 +73,8 @@ export class UploadSketch extends SketchContribution {
}
async uploadSketch(usingProgrammer: boolean = false): Promise<void> {
const uri = await this.sketchServiceClient.currentSketchFile();
if (!uri) {
const sketch = await this.sketchServiceClient.currentSketch();
if (!sketch) {
return;
}
let shouldAutoConnect = false;
@@ -88,15 +88,16 @@ export class UploadSketch extends SketchContribution {
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
const [fqbn, { selectedProgrammer }, verify, verbose] = await Promise.all([
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.preferences.get('arduino.upload.verbose'),
this.sourceOverride()
]);
let options: CoreService.Upload.Options | undefined = undefined;
const sketchUri = uri;
const sketchUri = sketch.uri;
const optimizeForDebug = this.editorMode.compileForDebug;
const { selectedPort } = boardsConfig;
const port = selectedPort?.address;
@@ -110,7 +111,8 @@ export class UploadSketch extends SketchContribution {
programmer,
port,
verbose,
verify
verify,
sourceOverride
};
} else {
options = {
@@ -119,7 +121,8 @@ export class UploadSketch extends SketchContribution {
optimizeForDebug,
port,
verbose,
verify
verify,
sourceOverride
};
}
this.outputChannelManager.getChannel('Arduino').clear();

View File

@@ -69,21 +69,25 @@ export class VerifySketch extends SketchContribution {
}
async verifySketch(exportBinaries: boolean = false): Promise<void> {
const uri = await this.sketchServiceClient.currentSketchFile();
if (!uri) {
const sketch = await this.sketchServiceClient.currentSketch();
if (!sketch) {
return;
}
try {
const { boardsConfig } = this.boardsServiceClientImpl;
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn);
const [fqbn, sourceOverride] = await Promise.all([
this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard?.fqbn),
this.sourceOverride()
]);
const verbose = this.preferences.get('arduino.compile.verbose');
this.outputChannelManager.getChannel('Arduino').clear();
await this.coreService.compile({
sketchUri: uri,
sketchUri: sketch.uri,
fqbn,
optimizeForDebug: this.editorMode.compileForDebug,
verbose,
exportBinaries
exportBinaries,
sourceOverride
});
this.messageService.info('Done compiling.', { timeout: 1000 });
} catch (e) {