Skip to content

Commit a66c75e

Browse files
committed
Replace undo with workbench.action.files.revert
Also updated where we reload based on action feedback to use this - it's cleaner.
1 parent f58416c commit a66c75e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/commands/studio.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
33
import { config, FILESYSTEM_SCHEMA } from "../extension";
4-
import { outputChannel, outputConsole, currentFile, getServerName } from "../utils";
4+
import { outputChannel, outputConsole, getServerName } from "../utils";
55
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
66
import { ClassNode } from "../explorer/models/classNode";
77
import { PackageNode } from "../explorer/models/packageNode";
88
import { RoutineNode } from "../explorer/models/routineNode";
99
import { NodeBase } from "../explorer/models/nodeBase";
10-
import { importAndCompile, loadChanges } from "./compile";
10+
import { importAndCompile } from "./compile";
1111

1212
export let documentBeingProcessed: vscode.TextDocument = null;
1313

@@ -272,34 +272,38 @@ class StudioActions {
272272
const actionToProcess = data.result.content.pop();
273273

274274
if (actionToProcess.reload) {
275-
const document = vscode.window.activeTextEditor.document;
276-
const file = currentFile(document);
277275
// Avoid the reload triggering the edit listener here
278-
suppressEditListenerMap.set(file.uri.toString(), true);
279-
await loadChanges([file]);
276+
suppressEditListenerMap.set(this.uri.toString(), true);
277+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
280278
}
281279

282280
// CSP pages should not have a progress bar
283281
if (actionToProcess.action === 2) {
284282
resolve();
285283
}
286-
return actionToProcess;
287-
})
288-
.then((actionToProcess) => {
284+
285+
const attemptedEditLabel = getOtherStudioActionLabel(OtherStudioAction.AttemptedEdit);
289286
if (afterUserAction && actionToProcess.errorText !== "") {
287+
if (action.label === attemptedEditLabel) {
288+
suppressEditListenerMap.set(this.uri.toString(), true);
289+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
290+
}
290291
outputChannel.appendLine(actionToProcess.errorText);
291292
outputChannel.show();
292293
}
293-
actionToProcess &&
294-
!afterUserAction &&
295-
this.processUserAction(actionToProcess).then((answer) => {
296-
// call AfterUserAction only if there is a valid answer
297-
if (answer) {
298-
answer.msg || answer.msg === ""
299-
? this.userAction(action, true, answer.answer, answer.msg, type)
300-
: this.userAction(action, true, answer, "", type);
301-
}
302-
});
294+
if (actionToProcess && !afterUserAction) {
295+
const answer = await this.processUserAction(actionToProcess);
296+
// call AfterUserAction only if there is a valid answer
297+
if ((action.label = attemptedEditLabel) && answer !== "1") {
298+
suppressEditListenerMap.set(this.uri.toString(), true);
299+
await vscode.commands.executeCommand("workbench.action.files.revert", this.uri);
300+
}
301+
if (answer) {
302+
answer.msg || answer.msg === ""
303+
? this.userAction(action, true, answer.answer, answer.msg, type)
304+
: this.userAction(action, true, answer, "", type);
305+
}
306+
}
303307
})
304308
.then(() => resolve())
305309
.catch((err) => {

0 commit comments

Comments
 (0)