@@ -89,7 +89,7 @@ export function hasTrustedCompilerPaths(): boolean {
8989
9090// Data shared by all clients.
9191let languageClient : LanguageClient ;
92- let firstClientStarted : Promise < void > ;
92+ let firstClientStarted : Promise < { wasShutdown : boolean } > ;
9393let languageClientCrashedNeedsRestart : boolean = false ;
9494const languageClientCrashTimes : number [ ] = [ ] ;
9595let compilerDefaults : configs . CompilerDefaults | undefined ;
@@ -508,6 +508,10 @@ interface CppInitializationParams {
508508 settings : SettingsParams ;
509509}
510510
511+ interface CppInitializationResult {
512+ shouldShutdown : boolean ;
513+ }
514+
511515interface TagParseStatus {
512516 localizeStringParams : LocalizeStringParams ;
513517 isPaused : boolean ;
@@ -585,7 +589,7 @@ export interface CopilotCompletionContextParams {
585589
586590// Requests
587591const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
588- const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
592+ const InitializationRequest : RequestType < CppInitializationParams , CppInitializationResult , void > = new RequestType < CppInitializationParams , CppInitializationResult , void > ( 'cpptools/initialize' ) ;
589593const QueryCompilerDefaultsRequest : RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > = new RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > ( 'cpptools/queryCompilerDefaults' ) ;
590594const SwitchHeaderSourceRequest : RequestType < SwitchHeaderSourceParams , string , void > = new RequestType < SwitchHeaderSourceParams , string , void > ( 'cpptools/didSwitchHeaderSource' ) ;
591595const GetDiagnosticsRequest : RequestType < void , GetDiagnosticsResult , void > = new RequestType < void , GetDiagnosticsResult , void > ( 'cpptools/getDiagnostics' ) ;
@@ -1310,7 +1314,12 @@ export class DefaultClient implements Client {
13101314 private async init ( rootUri : vscode . Uri | undefined , isFirstClient : boolean ) {
13111315 ui = getUI ( ) ;
13121316 ui . bind ( this ) ;
1313- await firstClientStarted ;
1317+ if ( ( await firstClientStarted ) . wasShutdown ) {
1318+ this . isSupported = false ;
1319+ DefaultClient . isStarted . resolve ( ) ;
1320+ return ;
1321+ }
1322+
13141323 try {
13151324 const workspaceFolder : vscode . WorkspaceFolder | undefined = this . rootFolder ;
13161325 this . innerConfiguration = new configs . CppProperties ( this , rootUri , workspaceFolder ) ;
@@ -1580,7 +1589,7 @@ export class DefaultClient implements Client {
15801589 } ;
15811590 }
15821591
1583- private async createLanguageClient ( ) : Promise < void > {
1592+ private async createLanguageClient ( ) : Promise < { wasShutdown : boolean } > {
15841593 this . currentCaseSensitiveFileSupport = new PersistentWorkspaceState < boolean > ( "CPP.currentCaseSensitiveFileSupport" , false ) ;
15851594 let resetDatabase : boolean = false ;
15861595 const serverModule : string = getLanguageServerFileName ( ) ;
@@ -1713,7 +1722,15 @@ export class DefaultClient implements Client {
17131722 // Move initialization to a separate message, so we can see log output from it.
17141723 // A request is used in order to wait for completion and ensure that no subsequent
17151724 // higher priority message may be processed before the Initialization request.
1716- await languageClient . sendRequest ( InitializationRequest , cppInitializationParams ) ;
1725+ const initializeResult = await languageClient . sendRequest ( InitializationRequest , cppInitializationParams ) ;
1726+
1727+ // If the server requested shutdown, then reload with the failsafe (null) client.
1728+ if ( initializeResult . shouldShutdown ) {
1729+ await languageClient . stop ( ) ;
1730+ await clients . recreateClients ( true ) ;
1731+ }
1732+
1733+ return { wasShutdown : initializeResult . shouldShutdown } ;
17171734 }
17181735
17191736 public async sendDidChangeSettings ( ) : Promise < void > {
0 commit comments