Skip to content

Commit f1bffaa

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Fixed Save As when overwriting existing sketch.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 3191a09 commit f1bffaa

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ import { EditorCommandContribution } from './theia/editor/editor-command';
128128
import { NavigatorTabBarDecorator as TheiaNavigatorTabBarDecorator } from '@theia/navigator/lib/browser/navigator-tab-bar-decorator';
129129
import { NavigatorTabBarDecorator } from './theia/navigator/navigator-tab-bar-decorator';
130130
import { Debug } from './contributions/debug';
131+
import { DebugSessionManager } from './theia/debug/debug-session-manager';
132+
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
131133

132134
const ElementQueries = require('css-element-queries/src/ElementQueries');
133135

@@ -355,4 +357,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
355357
// Silent the badge decoration in the Explorer view.
356358
bind(NavigatorTabBarDecorator).toSelf().inSingletonScope();
357359
rebind(TheiaNavigatorTabBarDecorator).toService(NavigatorTabBarDecorator);
360+
361+
// To avoid running `Save All` when there are no dirty editors before starting the debug session.
362+
bind(DebugSessionManager).toSelf().inSingletonScope();
363+
rebind(TheiaDebugSessionManager).toService(DebugSessionManager);
358364
});

Diff for: arduino-ide-extension/src/browser/theia/core/application-shell.ts

-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ export class ApplicationShell extends TheiaApplicationShell {
6868
}
6969

7070
async saveAll(): Promise<void> {
71-
if (!this.canSaveAll()) { // This is a quick fix for not saving the editor when there are no dirty editors.
72-
return; // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
73-
}
7471
if (this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE) {
7572
this.messageService.error('Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.');
7673
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { injectable } from 'inversify';
2+
import { DebugError } from '@theia/debug/lib/common/debug-service';
3+
import { DebugSession } from '@theia/debug/lib/browser/debug-session';
4+
import { DebugSessionOptions } from '@theia/debug/lib/browser/debug-session-options';
5+
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
6+
7+
@injectable()
8+
export class DebugSessionManager extends TheiaDebugSessionManager {
9+
10+
async start(options: DebugSessionOptions): Promise<DebugSession | undefined> {
11+
return this.progressService.withProgress('Start...', 'debug', async () => {
12+
try {
13+
// Only save when dirty. To avoid saving temporary sketches.
14+
// This is a quick fix for not saving the editor when there are no dirty editors.
15+
// // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
16+
if (this.shell.canSaveAll()) {
17+
await this.shell.saveAll();
18+
}
19+
await this.fireWillStartDebugSession();
20+
const resolved = await this.resolveConfiguration(options);
21+
22+
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
23+
if (!options.configuration.__restart) {
24+
const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
25+
if (!taskRun) {
26+
return undefined;
27+
}
28+
}
29+
30+
const sessionId = await this.debug.createDebugSession(resolved.configuration);
31+
return this.doStart(sessionId, resolved);
32+
} catch (e) {
33+
if (DebugError.NotFound.is(e)) {
34+
this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
35+
return undefined;
36+
}
37+
38+
this.messageService.error('There was an error starting the debug session, check the logs for more details.');
39+
console.error('Error starting the debug session', e);
40+
throw e;
41+
}
42+
});
43+
}
44+
45+
}

Diff for: arduino-ide-extension/src/node/sketches-service-impl.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ void loop() {
383383
try {
384384
const oldPath = path.join(destination, new URI(sketch.mainFileUri).path.base);
385385
const newPath = path.join(destination, `${newName}.ino`);
386-
await fs.rename(oldPath, newPath);
386+
if (oldPath !== newPath) {
387+
await fs.rename(oldPath, newPath);
388+
}
387389
await this.loadSketch(destinationUri); // Sanity check.
388390
resolve();
389391
} catch (e) {

0 commit comments

Comments
 (0)