@@ -9,6 +9,7 @@ export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml";
99export const FILESYSTEM_SCHEMA = "isfs" ;
1010export const schemas = [ OBJECTSCRIPT_FILE_SCHEMA , OBJECTSCRIPTXML_FILE_SCHEMA , FILESYSTEM_SCHEMA ] ;
1111
12+ import WebSocket = require( "ws" ) ;
1213import {
1314 importAndCompile ,
1415 importFolder as importFileOrFolder ,
@@ -101,7 +102,7 @@ let reporter: TelemetryReporter;
101102
102103export const checkConnection = ( clearCookies = false ) : void => {
103104 const conn = config ( "conn" ) ;
104- const connInfo = `${ conn . host } :${ conn . port } [${ conn . ns } ]` ;
105+ let connInfo = `${ conn . host } :${ conn . port } [${ conn . ns } ]` ;
105106 panel . text = connInfo ;
106107 panel . tooltip = "" ;
107108 vscode . commands . executeCommand ( "setContext" , "vscode-objectscript.connectActive" , conn . active ) ;
@@ -117,6 +118,7 @@ export const checkConnection = (clearCookies = false): void => {
117118 if ( dockerPort !== conn . port ) {
118119 workspaceState . update ( currentWorkspaceFolder ( ) + ":port" , dockerPort ) ;
119120 }
121+ connInfo = `${ conn . host } :${ dockerPort } [${ conn . ns } ]` ;
120122 }
121123
122124 const api = new AtelierAPI ( currentWorkspaceFolder ( ) ) ;
@@ -131,10 +133,36 @@ export const checkConnection = (clearCookies = false): void => {
131133 serverVersion : info . result . content . version ,
132134 healthshare : hasHS ? "yes" : "no" ,
133135 } ) ;
136+ /// Use xdebug's websocket, to catch when server disconnected
137+ const socket = new WebSocket ( api . xdebugUrl ( ) ) ;
138+ socket . onopen = ( ) => {
139+ panel . text = `${ connInfo } - Connected` ;
140+ } ;
141+ socket . onclose = event => {
142+ panel . text = `${ connInfo } - Disconnected` ;
143+ } ;
134144 } )
135145 . catch ( error => {
136146 let message = error . message ;
137147 if ( error instanceof StatusCodeError && error . statusCode === 401 ) {
148+ setTimeout (
149+ ( ) =>
150+ vscode . window
151+ . showInputBox ( {
152+ password : true ,
153+ placeHolder : "Not Authorized, please enter password to connect" ,
154+ ignoreFocusOut : true ,
155+ } )
156+ . then ( password => {
157+ if ( password ) {
158+ workspaceState . update ( currentWorkspaceFolder ( ) + ":password" , password ) ;
159+ checkConnection ( ) ;
160+ } else {
161+ vscode . workspace . getConfiguration ( ) . update ( "objectscript.conn.active" , false ) ;
162+ }
163+ } ) ,
164+ 1000
165+ ) ;
138166 message = "Not Authorized" ;
139167 outputChannel . appendLine (
140168 `Authorization error: please check your username/password in the settings,
@@ -175,7 +203,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
175203 panel . command = "vscode-objectscript.serverActions" ;
176204 panel . show ( ) ;
177205
178- checkConnection ( ) ;
206+ checkConnection ( true ) ;
179207 vscode . workspace . onDidChangeConfiguration ( ( { affectsConfiguration } ) => {
180208 if ( affectsConfiguration ( "objectscript.conn" ) ) {
181209 checkConnection ( true ) ;
@@ -184,13 +212,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
184212
185213 workspace . onDidSaveTextDocument ( file => {
186214 if ( schemas . includes ( file . uri . scheme ) || languages . includes ( file . languageId ) ) {
187- vscode . commands . executeCommand ( "vscode-objectscript.compile" ) ;
215+ return vscode . commands . executeCommand ( "vscode-objectscript.compile" ) ;
188216 }
189217 } ) ;
190218
191219 vscode . window . onDidChangeActiveTextEditor ( ( textEditor : vscode . TextEditor ) => {
192220 if ( config ( "autoPreviewXML" ) ) {
193- xml2doc ( context , textEditor ) ;
221+ return xml2doc ( context , textEditor ) ;
194222 }
195223 } ) ;
196224
@@ -379,4 +407,5 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
379407export function deactivate ( ) {
380408 // This will ensure all pending events get flushed
381409 reporter . dispose ( ) ;
410+ terminal . dispose ( ) ;
382411}
0 commit comments