@@ -9,6 +9,7 @@ export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml";
9
9
export const FILESYSTEM_SCHEMA = "isfs" ;
10
10
export const schemas = [ OBJECTSCRIPT_FILE_SCHEMA , OBJECTSCRIPTXML_FILE_SCHEMA , FILESYSTEM_SCHEMA ] ;
11
11
12
+ import WebSocket = require( "ws" ) ;
12
13
import {
13
14
importAndCompile ,
14
15
importFolder as importFileOrFolder ,
@@ -101,7 +102,7 @@ let reporter: TelemetryReporter;
101
102
102
103
export const checkConnection = ( clearCookies = false ) : void => {
103
104
const conn = config ( "conn" ) ;
104
- const connInfo = `${ conn . host } :${ conn . port } [${ conn . ns } ]` ;
105
+ let connInfo = `${ conn . host } :${ conn . port } [${ conn . ns } ]` ;
105
106
panel . text = connInfo ;
106
107
panel . tooltip = "" ;
107
108
vscode . commands . executeCommand ( "setContext" , "vscode-objectscript.connectActive" , conn . active ) ;
@@ -117,6 +118,7 @@ export const checkConnection = (clearCookies = false): void => {
117
118
if ( dockerPort !== conn . port ) {
118
119
workspaceState . update ( currentWorkspaceFolder ( ) + ":port" , dockerPort ) ;
119
120
}
121
+ connInfo = `${ conn . host } :${ dockerPort } [${ conn . ns } ]` ;
120
122
}
121
123
122
124
const api = new AtelierAPI ( currentWorkspaceFolder ( ) ) ;
@@ -131,10 +133,36 @@ export const checkConnection = (clearCookies = false): void => {
131
133
serverVersion : info . result . content . version ,
132
134
healthshare : hasHS ? "yes" : "no" ,
133
135
} ) ;
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
+ } ;
134
144
} )
135
145
. catch ( error => {
136
146
let message = error . message ;
137
147
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
+ ) ;
138
166
message = "Not Authorized" ;
139
167
outputChannel . appendLine (
140
168
`Authorization error: please check your username/password in the settings,
@@ -175,7 +203,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
175
203
panel . command = "vscode-objectscript.serverActions" ;
176
204
panel . show ( ) ;
177
205
178
- checkConnection ( ) ;
206
+ checkConnection ( true ) ;
179
207
vscode . workspace . onDidChangeConfiguration ( ( { affectsConfiguration } ) => {
180
208
if ( affectsConfiguration ( "objectscript.conn" ) ) {
181
209
checkConnection ( true ) ;
@@ -184,13 +212,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
184
212
185
213
workspace . onDidSaveTextDocument ( file => {
186
214
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" ) ;
188
216
}
189
217
} ) ;
190
218
191
219
vscode . window . onDidChangeActiveTextEditor ( ( textEditor : vscode . TextEditor ) => {
192
220
if ( config ( "autoPreviewXML" ) ) {
193
- xml2doc ( context , textEditor ) ;
221
+ return xml2doc ( context , textEditor ) ;
194
222
}
195
223
} ) ;
196
224
@@ -379,4 +407,5 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
379
407
export function deactivate ( ) {
380
408
// This will ensure all pending events get flushed
381
409
reporter . dispose ( ) ;
410
+ terminal . dispose ( ) ;
382
411
}
0 commit comments