Skip to content

Commit 7a87d16

Browse files
author
Tyler Deemer
committed
Added changed namespace action and save flag support.
1 parent 309104a commit 7a87d16

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed

src/api/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,14 @@ export class AtelierAPI {
187187
data.result.content = Buffer.from(data.result.content.join(""), "base64");
188188
}
189189
if (data.console) {
190-
outputConsole(data.console);
190+
// Let studio actions handle their console output
191+
const isStudioAction = data.result.content != undefined
192+
&& data.result.content.length !== 0
193+
&& data.result.content[0] != undefined
194+
&& data.result.content[0].action != undefined;
195+
if(!isStudioAction) {
196+
outputConsole(data.console);
197+
}
191198
}
192199
if (data.result.status && data.result.status !== "") {
193200
outputChannel.appendLine(data.result.status);

src/commands/compile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ async function compile(docs: CurrentFile[], flags?: string): Promise<any> {
104104
.then(loadChanges);
105105
}
106106

107-
export async function importAndCompile(askFLags = false): Promise<any> {
108-
const file = currentFile();
107+
export async function importAndCompile(askFLags = false, document?: vscode.TextDocument): Promise<any> {
108+
const file = currentFile(document);
109109
if (!file) {
110110
return;
111111
}

src/commands/studio.ts

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
33
import { config, FILESYSTEM_SCHEMA } from "../extension";
4-
import { outputChannel } from "../utils";
4+
import { outputChannel, outputConsole } from "../utils";
55
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
66
import { ClassNode } from "../explorer/models/classesNode";
77
import { PackageNode } from "../explorer/models/packageNode";
88
import { RoutineNode } from "../explorer/models/routineNode";
99
import { NodeBase } from "../explorer/models/nodeBase";
10+
import { importAndCompile } from "./compile";
11+
12+
export let documentBeingProcessed: vscode.TextDocument = null;
1013

1114
interface StudioAction extends vscode.QuickPickItem {
1215
name: string;
@@ -18,18 +21,20 @@ class StudioActions {
1821
private api: AtelierAPI;
1922
private name: string;
2023

21-
public constructor(uriOrNode: vscode.Uri | PackageNode | ClassNode | RoutineNode) {
24+
public constructor(uriOrNode?: vscode.Uri | PackageNode | ClassNode | RoutineNode) {
2225
if(uriOrNode instanceof vscode.Uri) {
2326
const uri: vscode.Uri = uriOrNode;
2427
this.uri = uri;
2528
this.name = this.uri.path.slice(1).replace(/\//g, ".");
2629
this.api = new AtelierAPI(uri.authority);
27-
} else {
30+
} else if(uriOrNode) {
2831
const node: NodeBase = uriOrNode;
2932
this.api = new AtelierAPI();
3033
this.name = (node instanceof PackageNode)
3134
? node.fullName + ".PKG"
3235
: node.fullName;
36+
} else {
37+
this.api = new AtelierAPI();
3338
}
3439
}
3540

@@ -40,7 +45,7 @@ class StudioActions {
4045
outputChannel.appendLine(errorText);
4146
outputChannel.show();
4247
}
43-
outputChannel.appendLine(JSON.stringify(userAction));
48+
// outputChannel.appendLine(JSON.stringify(userAction));
4449
switch (serverAction) {
4550
case 0:
4651
/// do nothing
@@ -179,11 +184,10 @@ class StudioActions {
179184
const query = `select * from %Atelier_v1_Utils.Extension_${func}`;
180185
let selectedText = "";
181186
const editor = vscode.window.activeTextEditor;
182-
if (!editor) {
183-
selectedText = "";
187+
if (editor) {
188+
const selection = editor.selection;
189+
selectedText = editor.document.getText(selection);
184190
}
185-
const selection = editor.selection;
186-
selectedText = editor.document.getText(selection);
187191

188192
const parameters = afterUserAction
189193
? [type.toString(), action.id, this.name, answer, msg]
@@ -198,12 +202,13 @@ class StudioActions {
198202
() =>
199203
this.api
200204
.actionQuery(query, parameters)
201-
.then(data => {
202-
const actionInfo = data.result.content.pop();
203-
actionInfo.save = action.save;
204-
return actionInfo;
205+
.then(async data => {
206+
if(action.save) {
207+
await this.processSaveFlag(action.save);
208+
}
209+
outputConsole(data.console);
210+
return data.result.content.pop();
205211
})
206-
.then(this.processSaveFlag)
207212
.then(this.processUserAction)
208213
.then(answer => {
209214
if (answer) {
@@ -286,19 +291,38 @@ class StudioActions {
286291
});
287292
}
288293

289-
private async processSaveFlag(userAction) {
290-
if(userAction.save) {
291-
const bitString = userAction.save.toString().padStart(3, "0");
292-
// Save the current document
293-
if(bitString.charAt(0) === "1") {
294-
await vscode.window.activeTextEditor.document.save();
294+
public changedNamespace() {
295+
const changedNamespaceAction = {
296+
id: "5",
297+
label: "Changed Namespace"
298+
};
299+
this.userAction(changedNamespaceAction, false, "", "", 1);
300+
}
301+
302+
private async processSaveFlag(saveFlag: number) {
303+
const bitString = saveFlag.toString().padStart(3, "0");
304+
const saveAndCompile = async (document: vscode.TextDocument) => {
305+
if(document.isDirty) {
306+
// Prevent onDidSave from compiling the file
307+
// in order to await the importAndCompile function
308+
documentBeingProcessed = document;
309+
await document.save();
310+
await importAndCompile(false, document);
311+
documentBeingProcessed = null;
295312
}
296-
// Save all documents
297-
if(bitString.charAt(2) === "1") {
298-
await vscode.workspace.saveAll();
313+
};
314+
315+
// Save the current document
316+
if(bitString.charAt(0) === "1") {
317+
await saveAndCompile(vscode.window.activeTextEditor.document);
318+
}
319+
320+
// Save all documents
321+
if(bitString.charAt(2) === "1") {
322+
for(const document of vscode.workspace.textDocuments) {
323+
await saveAndCompile(document)
299324
}
300325
}
301-
return userAction;
302326
}
303327
}
304328

@@ -330,4 +354,9 @@ export async function contextMenu(node: PackageNode | ClassNode | RoutineNode):
330354
}
331355
const studioActions = new StudioActions(nodeOrUri);
332356
return studioActions && studioActions.getMenu("", true);
357+
}
358+
359+
export async function fireChangedNamespace() {
360+
const studioActions = new StudioActions();
361+
return studioActions && studioActions.changedNamespace();
333362
}

src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { subclass } from "./commands/subclass";
2424
import { superclass } from "./commands/superclass";
2525
import { viewOthers } from "./commands/viewOthers";
2626
import { xml2doc } from "./commands/xml2doc";
27-
import { mainMenu, fireAttemptedEdit, contextMenu } from "./commands/studio";
27+
import { mainMenu, fireAttemptedEdit, contextMenu, fireChangedNamespace, documentBeingProcessed } from "./commands/studio";
2828

2929
import { getLanguageConfiguration } from "./languageConfiguration";
3030

@@ -163,6 +163,7 @@ export const checkConnection = (clearCookies = false): void => {
163163
/// Use xdebug's websocket, to catch when server disconnected
164164
connectionSocket = new WebSocket(api.xdebugUrl());
165165
connectionSocket.onopen = () => {
166+
fireChangedNamespace();
166167
panel.text = `${connInfo} - Connected`;
167168
};
168169
connectionSocket.onclose = event => {
@@ -246,7 +247,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
246247

247248
workspace.onDidSaveTextDocument(file => {
248249
if (schemas.includes(file.uri.scheme) || languages.includes(file.languageId)) {
249-
return vscode.commands.executeCommand("vscode-objectscript.compile");
250+
if(documentBeingProcessed !== file) {
251+
// return vscode.commands.executeCommand("vscode-objectscript.compile");
252+
return importAndCompile(false, file);
253+
}
250254
}
251255
});
252256

0 commit comments

Comments
 (0)