Skip to content

Commit 2b38059

Browse files
authored
Output message with SystemMode upon connection to server (#1361)
1 parent 28a504b commit 2b38059

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/extension.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,51 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol
547547
}
548548
}
549549

550+
/**
551+
* A map of SystemModes for known servers.
552+
* The key is either `serverName`, or `host:port/pathPrefix`, lowercase.
553+
* The value is the value of `^%SYS("SystemMode")`, uppercase.
554+
*/
555+
const systemModes: Map<string, string> = new Map();
556+
557+
/** Output a message notifying the user of the SystemMode of any servers they are connected to. */
558+
async function systemModeWarning(wsFolders: readonly vscode.WorkspaceFolder[]): Promise<void> {
559+
if (!wsFolders || wsFolders.length == 0) return;
560+
for (const wsFolder of wsFolders) {
561+
const api = new AtelierAPI(wsFolder.uri),
562+
mapKey = api.serverId.toLowerCase(),
563+
serverUrl = `${api.config.host}:${api.config.port}${api.config.pathPrefix}`,
564+
serverStr = ![undefined, ""].includes(api.config.serverName)
565+
? `'${api.config.serverName}' (${serverUrl})`
566+
: serverUrl;
567+
if (!api.active) continue; // Skip inactive connections
568+
let systemMode = systemModes.get(mapKey);
569+
if (systemMode == undefined) {
570+
systemMode = await api
571+
.actionQuery("SELECT UPPER(Value) AS SystemMode FROM %Library.Global_Get(?,'^%SYS(\"SystemMode\")')", [api.ns])
572+
.then((data) => data.result.content[0]?.SystemMode ?? "")
573+
.catch(() => ""); // Swallow any errors, which will likely be SQL permissions errors
574+
}
575+
switch (systemMode) {
576+
case "LIVE":
577+
outputChannel.appendLine(
578+
`WARNING: Workspace folder '${wsFolder.name}' is connected to Live System ${serverStr}`
579+
);
580+
outputChannel.show(); // Steal focus because this is an important message
581+
break;
582+
case "TEST":
583+
case "FAILOVER":
584+
outputChannel.appendLine(
585+
`NOTE: Workspace folder '${wsFolder.name}' is connected to ${
586+
systemMode == "TEST" ? "Test" : "Failover"
587+
} System ${serverStr}`
588+
);
589+
outputChannel.show(true);
590+
}
591+
systemModes.set(mapKey, systemMode);
592+
}
593+
}
594+
550595
/** The URIs of all classes that have been opened. Used when `objectscript.openClassContracted` is true */
551596
let openedClasses: string[];
552597

@@ -747,6 +792,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
747792
// Show the proposed API prompt if required
748793
proposedApiPrompt(proposed.length > 0);
749794

795+
// Warn about SystemMode
796+
systemModeWarning(vscode.workspace.workspaceFolders);
797+
750798
iscIcon = vscode.Uri.joinPath(context.extensionUri, "images", "fileIcon.svg");
751799

752800
macLangConf = vscode.languages.setLanguageConfiguration(macLangId, getLanguageConfiguration(macLangId));
@@ -1296,6 +1344,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12961344
vscode.workspace.onDidChangeWorkspaceFolders((e) => {
12971345
// Show the proposed API prompt if required
12981346
proposedApiPrompt(proposed.length > 0, e.added);
1347+
// Warn about SystemMode
1348+
systemModeWarning(e.added);
12991349
}),
13001350
vscode.commands.registerCommand("vscode-objectscript.importXMLFiles", importXMLFiles),
13011351
vscode.commands.registerCommand("vscode-objectscript.exportToXMLFile", exportDocumentsToXMLFile),

syntaxes/vscode-objectscript-output.tmLanguage.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878
{
7979
"match": "\\b(?i:(0?x)?[0-9a-f][0-9a-f]+)\\b",
8080
"name": "constant.numeric"
81+
},
82+
{
83+
"match": "^WARNING:",
84+
"name": "invalid"
85+
},
86+
{
87+
"match": "^NOTE:",
88+
"name": "string.quoted"
8189
}
8290
]
8391
}

0 commit comments

Comments
 (0)