Skip to content

Commit 2fbf3cb

Browse files
author
Akos Kitta
committed
Resolve and cache current sketch.
Signed-off-by: Akos Kitta <[email protected]>
1 parent b947be0 commit 2fbf3cb

24 files changed

+132
-71
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ import { ArduinoMenus } from './menu/arduino-menus';
6666
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
6767
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
6868
import { ArduinoPreferences } from './arduino-preferences';
69-
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
69+
import {
70+
CurrentSketch,
71+
SketchesServiceClientImpl,
72+
} from '../common/protocol/sketches-service-client-impl';
7073
import { SaveAsSketch } from './contributions/save-as-sketch';
7174
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
7275
import { IDEUpdater } from '../common/protocol/ide-updater';
@@ -219,7 +222,10 @@ export class ArduinoFrontendContribution
219222
updateStatusBar(this.boardsServiceClientImpl.boardsConfig);
220223
this.appStateService.reachedState('ready').then(async () => {
221224
const sketch = await this.sketchServiceClient.currentSketch();
222-
if (sketch && !(await this.sketchService.isTemp(sketch))) {
225+
if (
226+
CurrentSketch.isValid(sketch) &&
227+
!(await this.sketchService.isTemp(sketch))
228+
) {
223229
this.toDisposeOnStop.push(this.fileService.watch(new URI(sketch.uri)));
224230
this.toDisposeOnStop.push(
225231
this.fileService.onDidFilesChange(async (event) => {
@@ -373,7 +379,7 @@ export class ArduinoFrontendContribution
373379
let currentSketchPath: string | undefined = undefined;
374380
if (log) {
375381
const currentSketch = await this.sketchServiceClient.currentSketch();
376-
if (currentSketch) {
382+
if (CurrentSketch.isValid(currentSketch)) {
377383
currentSketchPath = await this.fileService.fsPath(
378384
new URI(currentSketch.uri)
379385
);

arduino-ide-extension/src/browser/contributions/add-file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from './contribution';
1111
import { FileDialogService } from '@theia/filesystem/lib/browser';
1212
import { nls } from '@theia/core/lib/common';
13+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1314

1415
@injectable()
1516
export class AddFile extends SketchContribution {
@@ -32,7 +33,7 @@ export class AddFile extends SketchContribution {
3233

3334
protected async addFile(): Promise<void> {
3435
const sketch = await this.sketchServiceClient.currentSketch();
35-
if (!sketch) {
36+
if (!CurrentSketch.isValid(sketch)) {
3637
return;
3738
}
3839
const toAddUri = await this.fileDialogService.showOpenDialog({

arduino-ide-extension/src/browser/contributions/archive-sketch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
MenuModelRegistry,
1111
} from './contribution';
1212
import { nls } from '@theia/core/lib/common';
13+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1314

1415
@injectable()
1516
export class ArchiveSketch extends SketchContribution {
@@ -32,7 +33,7 @@ export class ArchiveSketch extends SketchContribution {
3233
this.sketchServiceClient.currentSketch(),
3334
this.configService.getConfiguration(),
3435
]);
35-
if (!sketch) {
36+
if (!CurrentSketch.isValid(sketch)) {
3637
return;
3738
}
3839
const archiveBasename = `${sketch.name}-${dateFormat(

arduino-ide-extension/src/browser/contributions/close.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
URI,
1717
} from './contribution';
1818
import { nls } from '@theia/core/lib/common';
19+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1920

2021
/**
2122
* Closes the `current` closeable editor, or any closeable current widget from the main area, or the current sketch window.
@@ -54,7 +55,7 @@ export class Close extends SketchContribution {
5455

5556
// Close the sketch (window).
5657
const sketch = await this.sketchServiceClient.currentSketch();
57-
if (!sketch) {
58+
if (!CurrentSketch.isValid(sketch)) {
5859
return;
5960
}
6061
const isTemp = await this.sketchService.isTemp(sketch);

arduino-ide-extension/src/browser/contributions/contribution.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import {
3939
} from '@theia/core/lib/common/command';
4040
import { EditorMode } from '../editor-mode';
4141
import { SettingsService } from '../dialogs/settings/settings';
42-
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
42+
import {
43+
CurrentSketch,
44+
SketchesServiceClientImpl,
45+
} from '../../common/protocol/sketches-service-client-impl';
4346
import {
4447
SketchesService,
4548
ConfigService,
@@ -149,7 +152,7 @@ export abstract class SketchContribution extends Contribution {
149152
protected async sourceOverride(): Promise<Record<string, string>> {
150153
const override: Record<string, string> = {};
151154
const sketch = await this.sketchServiceClient.currentSketch();
152-
if (sketch) {
155+
if (CurrentSketch.isValid(sketch)) {
153156
for (const editor of this.editorManager.all) {
154157
const uri = editor.editor.uri;
155158
if (Saveable.isDirty(editor) && Sketch.isInSketch(uri, sketch)) {

arduino-ide-extension/src/browser/contributions/debug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
TabBarToolbarRegistry,
1414
} from './contribution';
1515
import { MaybePromise, nls } from '@theia/core/lib/common';
16+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1617

1718
@injectable()
1819
export class Debug extends SketchContribution {
@@ -160,7 +161,7 @@ export class Debug extends SketchContribution {
160161
this.sketchServiceClient.currentSketch(),
161162
this.executableService.list(),
162163
]);
163-
if (!sketch) {
164+
if (!CurrentSketch.isValid(sketch)) {
164165
return;
165166
}
166167
const ideTempFolderUri = await this.sketchService.getIdeTempFolderUri(

arduino-ide-extension/src/browser/contributions/include-library.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { SketchContribution, Command, CommandRegistry } from './contribution';
1717
import { NotificationCenter } from '../notification-center';
1818
import { nls } from '@theia/core/lib/common';
1919
import * as monaco from '@theia/monaco-editor-core';
20+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
2021

2122
@injectable()
2223
export class IncludeLibrary extends SketchContribution {
@@ -172,7 +173,7 @@ export class IncludeLibrary extends SketchContribution {
172173

173174
protected async includeLibrary(library: LibraryPackage): Promise<void> {
174175
const sketch = await this.sketchServiceClient.currentSketch();
175-
if (!sketch) {
176+
if (!CurrentSketch.isValid(sketch)) {
176177
return;
177178
}
178179
// If the current editor is one of the additional files from the sketch, we use that.

arduino-ide-extension/src/browser/contributions/save-as-sketch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { nls } from '@theia/core/lib/common';
1414
import { ApplicationShell, NavigatableWidget, Saveable } from '@theia/core/lib/browser';
1515
import { EditorManager } from '@theia/editor/lib/browser';
1616
import { WindowService } from '@theia/core/lib/browser/window/window-service';
17+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1718

1819
@injectable()
1920
export class SaveAsSketch extends SketchContribution {
@@ -59,7 +60,7 @@ export class SaveAsSketch extends SketchContribution {
5960
}: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT
6061
): Promise<boolean> {
6162
const sketch = await this.sketchServiceClient.currentSketch();
62-
if (!sketch) {
63+
if (!CurrentSketch.isValid(sketch)) {
6364
return false;
6465
}
6566

arduino-ide-extension/src/browser/contributions/save-sketch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
TabBarToolbarRegistry,
1313
} from './contribution';
1414
import { nls } from '@theia/core/lib/common';
15+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1516

1617
@injectable()
1718
export class SaveSketch extends SketchContribution {
@@ -53,7 +54,7 @@ export class SaveSketch extends SketchContribution {
5354

5455
async saveSketch(): Promise<void> {
5556
const sketch = await this.sketchServiceClient.currentSketch();
56-
if (!sketch) {
57+
if (!CurrentSketch.isValid(sketch)) {
5758
return;
5859
}
5960
const isTemp = await this.sketchService.isTemp(sketch);

arduino-ide-extension/src/browser/contributions/sketch-control.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import {
1919
} from './contribution';
2020
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
2121
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
22-
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
22+
import {
23+
CurrentSketch,
24+
SketchesServiceClientImpl,
25+
} from '../../common/protocol/sketches-service-client-impl';
2326
import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider';
2427
import { nls } from '@theia/core/lib/common';
2528

@@ -55,7 +58,7 @@ export class SketchControl extends SketchContribution {
5558
execute: async () => {
5659
this.toDisposeBeforeCreateNewContextMenu.dispose();
5760
const sketch = await this.sketchServiceClient.currentSketch();
58-
if (!sketch) {
61+
if (!CurrentSketch.isValid(sketch)) {
5962
return;
6063
}
6164

@@ -70,25 +73,22 @@ export class SketchControl extends SketchContribution {
7073
return;
7174
}
7275

73-
const { mainFileUri, rootFolderFileUris } =
74-
await this.sketchService.loadSketch(sketch.uri);
76+
const { mainFileUri, rootFolderFileUris } = sketch;
7577
const uris = [mainFileUri, ...rootFolderFileUris];
7678

77-
const currentSketch =
78-
await this.sketchesServiceClient.currentSketch();
79-
const parentsketchUri = this.editorManager.currentEditor
79+
const parentSketchUri = this.editorManager.currentEditor
8080
?.getResourceUri()
8181
?.toString();
82-
const parentsketch = await this.sketchService.getSketchFolder(
83-
parentsketchUri || ''
82+
const parentSketch = await this.sketchService.getSketchFolder(
83+
parentSketchUri || ''
8484
);
8585

8686
// if the current file is in the current opened sketch, show extra menus
8787
if (
88-
currentSketch &&
89-
parentsketch &&
90-
parentsketch.uri === currentSketch.uri &&
91-
this.allowRename(parentsketch.uri)
88+
sketch &&
89+
parentSketch &&
90+
parentSketch.uri === sketch.uri &&
91+
this.allowRename(parentSketch.uri)
9292
) {
9393
this.menuRegistry.registerMenuAction(
9494
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,
@@ -122,10 +122,10 @@ export class SketchControl extends SketchContribution {
122122
}
123123

124124
if (
125-
currentSketch &&
126-
parentsketch &&
127-
parentsketch.uri === currentSketch.uri &&
128-
this.allowDelete(parentsketch.uri)
125+
sketch &&
126+
parentSketch &&
127+
parentSketch.uri === sketch.uri &&
128+
this.allowDelete(parentSketch.uri)
129129
) {
130130
this.menuRegistry.registerMenuAction(
131131
ArduinoMenus.SKETCH_CONTROL__CONTEXT__MAIN_GROUP,

0 commit comments

Comments
 (0)