Skip to content

Commit 72f6c56

Browse files
authored
Add a New File... command for creating an Interoperability Message (#1629)
1 parent b83438b commit 72f6c56

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@
287287
"command": "vscode-objectscript.newFile.kpi",
288288
"when": "false"
289289
},
290+
{
291+
"command": "vscode-objectscript.newFile.message",
292+
"when": "false"
293+
},
290294
{
291295
"command": "vscode-objectscript.importLocalFilesServerSide",
292296
"when": "false"
@@ -650,6 +654,11 @@
650654
"command": "vscode-objectscript.newFile.dtl",
651655
"when": "workspaceFolderCount != 0",
652656
"group": "file"
657+
},
658+
{
659+
"command": "vscode-objectscript.newFile.message",
660+
"when": "workspaceFolderCount != 0",
661+
"group": "file"
653662
}
654663
]
655664
},
@@ -1116,6 +1125,11 @@
11161125
"command": "vscode-objectscript.newFile.dtl",
11171126
"title": "Data Transformation"
11181127
},
1128+
{
1129+
"category": "ObjectScript",
1130+
"command": "vscode-objectscript.newFile.message",
1131+
"title": "Interoperability Message"
1132+
},
11191133
{
11201134
"category": "ObjectScript",
11211135
"command": "vscode-objectscript.importLocalFilesServerSide",

src/commands/newFile.ts

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export enum NewFileType {
228228
DTL = "Data Transformation",
229229
Rule = "Business Rule",
230230
KPI = "Business Intelligence KPI",
231+
Message = "Interoperability Message",
231232
}
232233

233234
interface RuleAssistClasses {
@@ -716,7 +717,10 @@ ClassMethod Transform(source As ${sourceCls}, ByRef target As ${targetCls}) As %
716717
// Prompt for the production, if required
717718
let production: string;
718719
if (Object.keys(ruleAssists).length && assistCls in ruleAssists && ruleAssists[assistCls].hasProduction) {
719-
const productions: string[] = await api.getEnsClassList(11).then((data) => data.result.content);
720+
const productions: string[] = await api
721+
.getEnsClassList(11)
722+
.then((data) => data.result.content)
723+
.catch(() => []);
720724
if (productions.length) {
721725
production = await vscode.window.showQuickPick(productions, {
722726
ignoreFocusOut: true,
@@ -827,6 +831,108 @@ ClassMethod %OnDashboardAction(pAction As %String, pContext As %ZEN.proxyObject)
827831
Return $$$OK
828832
}
829833
834+
}
835+
`;
836+
} else if (type == NewFileType.Message) {
837+
// Create the prompt for message type
838+
inputSteps.push({
839+
type: "quickPick",
840+
title: "Pick the message type",
841+
items: [
842+
{
843+
label: "Request",
844+
value: "Request",
845+
},
846+
{
847+
label: "Response",
848+
value: "Response",
849+
},
850+
],
851+
});
852+
853+
// Prompt the user
854+
const results = await multiStepInput(inputSteps);
855+
if (!results) {
856+
return;
857+
}
858+
cls = results[0];
859+
const [, desc, msgType] = results;
860+
861+
let respClass: string;
862+
if (msgType == "Request") {
863+
// Prompt the user for the response type
864+
const respClasses: vscode.QuickPickItem[] = api
865+
? await api
866+
.getEnsClassList(4)
867+
.then((data) =>
868+
data.result.content.map((label: string) => {
869+
return { label };
870+
})
871+
)
872+
.catch(() => [])
873+
: [];
874+
if (respClasses.length) {
875+
// Use a QuickPick
876+
respClass = await new Promise((resolve) => {
877+
const quickPick = vscode.window.createQuickPick();
878+
quickPick.items = respClasses;
879+
quickPick.title =
880+
"Pick an optional response class for this request. You may also enter a class name that is not in the list and press 'Enter' to use it. Press 'Escape' to skip.";
881+
quickPick.ignoreFocusOut = true;
882+
quickPick.onDidAccept(() => {
883+
const pickedClass = quickPick.selectedItems[0]?.label ?? quickPick.value.trim();
884+
if (!quickPick.selectedItems.length) {
885+
// The class name came from the value text, so validate it first
886+
const validationMsg = validateClassName(pickedClass);
887+
if (validationMsg) {
888+
// The class name is invalid
889+
vscode.window.showErrorMessage(
890+
`${validationMsg}. Please pick a class or enter a valid class name.`,
891+
"Dismiss"
892+
);
893+
} else {
894+
// The class name is valid
895+
resolve(pickedClass);
896+
quickPick.hide();
897+
}
898+
} else {
899+
// The class name came from an item so no validation is required
900+
resolve(pickedClass);
901+
quickPick.hide();
902+
}
903+
});
904+
quickPick.onDidHide(() => {
905+
resolve(undefined);
906+
quickPick.dispose();
907+
});
908+
quickPick.show();
909+
});
910+
} else {
911+
// Fall back to using an InputBox
912+
respClass = await vscode.window.showInputBox({
913+
title: "Enter an optional response class for this request. Press 'Escape' to skip.",
914+
ignoreFocusOut: true,
915+
validateInput: validateClassName,
916+
});
917+
}
918+
}
919+
920+
// Generate the file's content
921+
clsContent = `
922+
${typeof desc == "string" ? "/// " + desc.replace(/\n/g, "\n/// ") : ""}
923+
Class ${cls} Extends (%Persistent, Ens.${msgType})
924+
{
925+
${
926+
respClass
927+
? `
928+
/// The corresponding response class for this request
929+
Parameter RESPONSECLASSNAME As CLASSNAME = "${respClass}";`
930+
: ""
931+
}
932+
933+
/// InterSystems IRIS purges message bodies based on the class when the option to purge message bodies is enabled
934+
Parameter ENSPURGE As BOOLEAN = 1;
935+
830936
}
831937
`;
832938
}

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
16781678
sendCommandTelemetryEvent("newFile.kpi");
16791679
newFile(NewFileType.KPI);
16801680
}),
1681+
vscode.commands.registerCommand("vscode-objectscript.newFile.message", () => {
1682+
sendCommandTelemetryEvent("newFile.message");
1683+
newFile(NewFileType.Message);
1684+
}),
16811685
vscode.window.registerFileDecorationProvider(fileDecorationProvider),
16821686
vscode.workspace.onDidOpenTextDocument((doc) => !doc.isUntitled && fileDecorationProvider.emitter.fire(doc.uri)),
16831687
vscode.commands.registerCommand("vscode-objectscript.importLocalFilesServerSide", (wsFolderUri) => {

0 commit comments

Comments
 (0)