@@ -103,6 +103,7 @@ export class SessionManager implements Middleware {
103
103
private sessionDetails : IEditorServicesSessionDetails ;
104
104
private sessionsFolder : vscode . Uri ;
105
105
private bundledModulesPath : string ;
106
+ private starting : boolean = false ;
106
107
private started : boolean = false ;
107
108
108
109
// Initialized by the start() method, since this requires settings
@@ -160,6 +161,19 @@ export class SessionManager implements Middleware {
160
161
}
161
162
162
163
public async start ( exeNameOverride ?: string ) {
164
+ // A simple lock because this function isn't re-entrant.
165
+ if ( this . started || this . starting ) {
166
+ return await this . waitUntilStarted ( ) ;
167
+ }
168
+ try {
169
+ this . starting = true ;
170
+ await this . _start ( exeNameOverride ) ;
171
+ } finally {
172
+ this . starting = false ;
173
+ }
174
+ }
175
+
176
+ private async _start ( exeNameOverride ?: string ) {
163
177
await Settings . validateCwdSetting ( ) ;
164
178
this . sessionSettings = Settings . load ( ) ;
165
179
@@ -275,31 +289,41 @@ Type 'help' to get help.
275
289
public async stop ( ) {
276
290
this . log . write ( "Shutting down language client..." ) ;
277
291
278
- if ( this . sessionStatus === SessionStatus . Failed ) {
279
- // Before moving further, clear out the client and process if
280
- // the process is already dead (i.e. it crashed).
281
- this . languageClient = undefined ;
282
- this . languageServerProcess = undefined ;
283
- }
292
+ try {
293
+ if ( this . sessionStatus === SessionStatus . Failed ) {
294
+ // Before moving further, clear out the client and process if
295
+ // the process is already dead (i.e. it crashed).
296
+ this . languageClient . dispose ( ) ;
297
+ this . languageClient = undefined ;
298
+ this . languageServerProcess . dispose ( ) ;
299
+ this . languageServerProcess = undefined ;
300
+ }
284
301
285
- this . sessionStatus = SessionStatus . Stopping ;
302
+ this . sessionStatus = SessionStatus . Stopping ;
286
303
287
- // Stop the language client.
288
- if ( this . languageClient !== undefined ) {
289
- await this . languageClient . stop ( ) ;
290
- this . languageClient = undefined ;
291
- }
304
+ // Stop the language client.
305
+ if ( this . languageClient !== undefined ) {
306
+ await this . languageClient . stop ( ) ;
307
+ this . languageClient . dispose ( ) ;
308
+ this . languageClient = undefined ;
309
+ }
292
310
293
- // Kill the PowerShell process(es) we spawned.
294
- if ( this . debugSessionProcess ) {
295
- this . debugSessionProcess . dispose ( ) ;
296
- this . debugEventHandler . dispose ( ) ;
297
- }
298
- if ( this . languageServerProcess ) {
299
- this . languageServerProcess . dispose ( ) ;
300
- }
311
+ // Kill the PowerShell process(es) we spawned.
312
+ if ( this . debugSessionProcess ) {
313
+ this . debugSessionProcess . dispose ( ) ;
314
+ this . debugSessionProcess = undefined ;
315
+ this . debugEventHandler . dispose ( ) ;
316
+ this . debugEventHandler = undefined ;
317
+ }
301
318
302
- this . sessionStatus = SessionStatus . NotStarted ;
319
+ if ( this . languageServerProcess ) {
320
+ this . languageServerProcess . dispose ( ) ;
321
+ this . languageServerProcess = undefined ;
322
+ }
323
+ } finally {
324
+ this . sessionStatus = SessionStatus . NotStarted ;
325
+ this . started = false ;
326
+ }
303
327
}
304
328
305
329
public async restartSession ( exeNameOverride ?: string ) {
0 commit comments