@@ -547,6 +547,51 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol
547
547
}
548
548
}
549
549
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
+
550
595
/** The URIs of all classes that have been opened. Used when `objectscript.openClassContracted` is true */
551
596
let openedClasses : string [ ] ;
552
597
@@ -747,6 +792,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
747
792
// Show the proposed API prompt if required
748
793
proposedApiPrompt ( proposed . length > 0 ) ;
749
794
795
+ // Warn about SystemMode
796
+ systemModeWarning ( vscode . workspace . workspaceFolders ) ;
797
+
750
798
iscIcon = vscode . Uri . joinPath ( context . extensionUri , "images" , "fileIcon.svg" ) ;
751
799
752
800
macLangConf = vscode . languages . setLanguageConfiguration ( macLangId , getLanguageConfiguration ( macLangId ) ) ;
@@ -1296,6 +1344,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
1296
1344
vscode . workspace . onDidChangeWorkspaceFolders ( ( e ) => {
1297
1345
// Show the proposed API prompt if required
1298
1346
proposedApiPrompt ( proposed . length > 0 , e . added ) ;
1347
+ // Warn about SystemMode
1348
+ systemModeWarning ( e . added ) ;
1299
1349
} ) ,
1300
1350
vscode . commands . registerCommand ( "vscode-objectscript.importXMLFiles" , importXMLFiles ) ,
1301
1351
vscode . commands . registerCommand ( "vscode-objectscript.exportToXMLFile" , exportDocumentsToXMLFile ) ,
0 commit comments