@@ -89,7 +89,7 @@ export function hasTrustedCompilerPaths(): boolean {
89
89
90
90
// Data shared by all clients.
91
91
let languageClient : LanguageClient ;
92
- let firstClientStarted : Promise < void > ;
92
+ let firstClientStarted : Promise < { wasShutdown : boolean } > ;
93
93
let languageClientCrashedNeedsRestart : boolean = false ;
94
94
const languageClientCrashTimes : number [ ] = [ ] ;
95
95
let compilerDefaults : configs . CompilerDefaults | undefined ;
@@ -508,6 +508,10 @@ interface CppInitializationParams {
508
508
settings : SettingsParams ;
509
509
}
510
510
511
+ interface CppInitializationResult {
512
+ shouldShutdown : boolean ;
513
+ }
514
+
511
515
interface TagParseStatus {
512
516
localizeStringParams : LocalizeStringParams ;
513
517
isPaused : boolean ;
@@ -585,7 +589,7 @@ export interface CopilotCompletionContextParams {
585
589
586
590
// Requests
587
591
const 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' ) ;
589
593
const QueryCompilerDefaultsRequest : RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > = new RequestType < QueryDefaultCompilerParams , configs . CompilerDefaults , void > ( 'cpptools/queryCompilerDefaults' ) ;
590
594
const SwitchHeaderSourceRequest : RequestType < SwitchHeaderSourceParams , string , void > = new RequestType < SwitchHeaderSourceParams , string , void > ( 'cpptools/didSwitchHeaderSource' ) ;
591
595
const GetDiagnosticsRequest : RequestType < void , GetDiagnosticsResult , void > = new RequestType < void , GetDiagnosticsResult , void > ( 'cpptools/getDiagnostics' ) ;
@@ -1310,7 +1314,12 @@ export class DefaultClient implements Client {
1310
1314
private async init ( rootUri : vscode . Uri | undefined , isFirstClient : boolean ) {
1311
1315
ui = getUI ( ) ;
1312
1316
ui . bind ( this ) ;
1313
- await firstClientStarted ;
1317
+ if ( ( await firstClientStarted ) . wasShutdown ) {
1318
+ this . isSupported = false ;
1319
+ DefaultClient . isStarted . resolve ( ) ;
1320
+ return ;
1321
+ }
1322
+
1314
1323
try {
1315
1324
const workspaceFolder : vscode . WorkspaceFolder | undefined = this . rootFolder ;
1316
1325
this . innerConfiguration = new configs . CppProperties ( this , rootUri , workspaceFolder ) ;
@@ -1574,7 +1583,7 @@ export class DefaultClient implements Client {
1574
1583
} ;
1575
1584
}
1576
1585
1577
- private async createLanguageClient ( ) : Promise < void > {
1586
+ private async createLanguageClient ( ) : Promise < { wasShutdown : boolean } > {
1578
1587
this . currentCaseSensitiveFileSupport = new PersistentWorkspaceState < boolean > ( "CPP.currentCaseSensitiveFileSupport" , false ) ;
1579
1588
let resetDatabase : boolean = false ;
1580
1589
const serverModule : string = getLanguageServerFileName ( ) ;
@@ -1707,7 +1716,15 @@ export class DefaultClient implements Client {
1707
1716
// Move initialization to a separate message, so we can see log output from it.
1708
1717
// A request is used in order to wait for completion and ensure that no subsequent
1709
1718
// higher priority message may be processed before the Initialization request.
1710
- await languageClient . sendRequest ( InitializationRequest , cppInitializationParams ) ;
1719
+ const initializeResult = await languageClient . sendRequest ( InitializationRequest , cppInitializationParams ) ;
1720
+
1721
+ // If the server requested shutdown, then reload with the failsafe (null) client.
1722
+ if ( initializeResult . shouldShutdown ) {
1723
+ await languageClient . stop ( ) ;
1724
+ await clients . recreateClients ( true ) ;
1725
+ }
1726
+
1727
+ return { wasShutdown : initializeResult . shouldShutdown } ;
1711
1728
}
1712
1729
1713
1730
public async sendDidChangeSettings ( ) : Promise < void > {
0 commit comments