Skip to content

Commit

Permalink
Output message with SystemMode upon connection to server (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano authored May 13, 2024
1 parent 28a504b commit 2b38059
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,51 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol
}
}

/**
* A map of SystemModes for known servers.
* The key is either `serverName`, or `host:port/pathPrefix`, lowercase.
* The value is the value of `^%SYS("SystemMode")`, uppercase.
*/
const systemModes: Map<string, string> = new Map();

/** Output a message notifying the user of the SystemMode of any servers they are connected to. */
async function systemModeWarning(wsFolders: readonly vscode.WorkspaceFolder[]): Promise<void> {
if (!wsFolders || wsFolders.length == 0) return;
for (const wsFolder of wsFolders) {
const api = new AtelierAPI(wsFolder.uri),
mapKey = api.serverId.toLowerCase(),
serverUrl = `${api.config.host}:${api.config.port}${api.config.pathPrefix}`,
serverStr = ![undefined, ""].includes(api.config.serverName)
? `'${api.config.serverName}' (${serverUrl})`
: serverUrl;
if (!api.active) continue; // Skip inactive connections
let systemMode = systemModes.get(mapKey);
if (systemMode == undefined) {
systemMode = await api
.actionQuery("SELECT UPPER(Value) AS SystemMode FROM %Library.Global_Get(?,'^%SYS(\"SystemMode\")')", [api.ns])
.then((data) => data.result.content[0]?.SystemMode ?? "")
.catch(() => ""); // Swallow any errors, which will likely be SQL permissions errors
}
switch (systemMode) {
case "LIVE":
outputChannel.appendLine(
`WARNING: Workspace folder '${wsFolder.name}' is connected to Live System ${serverStr}`
);
outputChannel.show(); // Steal focus because this is an important message
break;
case "TEST":
case "FAILOVER":
outputChannel.appendLine(
`NOTE: Workspace folder '${wsFolder.name}' is connected to ${
systemMode == "TEST" ? "Test" : "Failover"
} System ${serverStr}`
);
outputChannel.show(true);
}
systemModes.set(mapKey, systemMode);
}
}

/** The URIs of all classes that have been opened. Used when `objectscript.openClassContracted` is true */
let openedClasses: string[];

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

// Warn about SystemMode
systemModeWarning(vscode.workspace.workspaceFolders);

iscIcon = vscode.Uri.joinPath(context.extensionUri, "images", "fileIcon.svg");

macLangConf = vscode.languages.setLanguageConfiguration(macLangId, getLanguageConfiguration(macLangId));
Expand Down Expand Up @@ -1296,6 +1344,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.workspace.onDidChangeWorkspaceFolders((e) => {
// Show the proposed API prompt if required
proposedApiPrompt(proposed.length > 0, e.added);
// Warn about SystemMode
systemModeWarning(e.added);
}),
vscode.commands.registerCommand("vscode-objectscript.importXMLFiles", importXMLFiles),
vscode.commands.registerCommand("vscode-objectscript.exportToXMLFile", exportDocumentsToXMLFile),
Expand Down
8 changes: 8 additions & 0 deletions syntaxes/vscode-objectscript-output.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
{
"match": "\\b(?i:(0?x)?[0-9a-f][0-9a-f]+)\\b",
"name": "constant.numeric"
},
{
"match": "^WARNING:",
"name": "invalid"
},
{
"match": "^NOTE:",
"name": "string.quoted"
}
]
}

0 comments on commit 2b38059

Please sign in to comment.