@@ -439,14 +439,21 @@ export class LanguageClientManager implements vscode.Disposable {
439
439
}
440
440
441
441
private async startClient ( client : LanguageClient , errorHandler : SourceKitLSPErrorHandler ) {
442
- client . onDidChangeState ( e => {
443
- // if state is now running add in any sub-folder workspaces that
444
- // we have cached. If this is the first time we are starting then
445
- // we won't have any sub folder workspaces, but if the server crashed
446
- // or we forced a restart then we need to do this
447
- if ( e . oldState === State . Starting && e . newState === State . Running ) {
448
- void this . addSubFolderWorkspaces ( client ) ;
449
- }
442
+ const runningPromise = new Promise < void > ( ( res , rej ) => {
443
+ const disposable = client . onDidChangeState ( e => {
444
+ // if state is now running add in any sub-folder workspaces that
445
+ // we have cached. If this is the first time we are starting then
446
+ // we won't have any sub folder workspaces, but if the server crashed
447
+ // or we forced a restart then we need to do this
448
+ if ( e . oldState === State . Starting && e . newState === State . Running ) {
449
+ res ( ) ;
450
+ disposable . dispose ( ) ;
451
+ void this . addSubFolderWorkspaces ( client ) ;
452
+ } else if ( e . oldState === State . Starting && e . newState === State . Stopped ) {
453
+ rej ( "SourceKit-LSP failed to start" ) ;
454
+ disposable . dispose ( ) ;
455
+ }
456
+ } ) ;
450
457
} ) ;
451
458
if ( client . clientOptions . workspaceFolder ) {
452
459
this . folderContext . workspaceContext . outputChannel . log (
@@ -465,6 +472,7 @@ export class LanguageClientManager implements vscode.Disposable {
465
472
// start client
466
473
this . clientReadyPromise = client
467
474
. start ( )
475
+ . then ( ( ) => runningPromise )
468
476
. then ( ( ) => {
469
477
// Now that we've started up correctly, start the error handler to auto-restart
470
478
// if sourcekit-lsp crashes during normal operation.
0 commit comments