Skip to content

Commit 5f888ee

Browse files
authored
Fix issue with cpptools restarting when it should not (#8850)
1 parent c02440c commit 5f888ee

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ export interface Client {
746746
onInterval(): void;
747747
dispose(): void;
748748
addFileAssociations(fileAssociations: string, languageId: string): void;
749+
sendAllSettings(): void;
749750
sendDidChangeSettings(settings: any): void;
750751
}
751752

@@ -1481,15 +1482,15 @@ export class DefaultClient implements Client {
14811482
languageClientCrashedNeedsRestart = true;
14821483
telemetry.logLanguageServerEvent("languageClientCrash");
14831484
if (languageClientCrashTimes.length < 5) {
1484-
allClients.recreateClients(true);
1485+
allClients.recreateClients();
14851486
} else {
14861487
const elapsed: number = languageClientCrashTimes[languageClientCrashTimes.length - 1] - languageClientCrashTimes[0];
14871488
if (elapsed <= 3 * 60 * 1000) {
14881489
vscode.window.showErrorMessage(localize('server.crashed2', "The language server crashed 5 times in the last 3 minutes. It will not be restarted."));
1489-
allClients.recreateClients(false);
1490+
allClients.recreateClients(true);
14901491
} else {
14911492
languageClientCrashTimes.shift();
1492-
allClients.recreateClients(true);
1493+
allClients.recreateClients();
14931494
}
14941495
}
14951496
return CloseAction.DoNotRestart;
@@ -3319,5 +3320,6 @@ class NullClient implements Client {
33193320
this.stringEvent.dispose();
33203321
}
33213322
addFileAssociations(fileAssociations: string, languageId: string): void { }
3323+
sendAllSettings(): void { }
33223324
sendDidChangeSettings(settings: any): void { }
33233325
}

Extension/src/LanguageServer/clientCollection.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export class ClientCollection {
2525
private activeDocument?: vscode.TextDocument;
2626
public timeTelemetryCollector: TimeTelemetryCollector = new TimeTelemetryCollector();
2727

28+
// This is a one-time switch to a mode that suppresses launching of the cpptools client process.
29+
private useFailsafeMode: boolean = false;
30+
2831
public get ActiveClient(): cpptools.Client { return this.activeClient; }
2932
public get Names(): ClientKey[] {
3033
const result: ClientKey[] = [];
@@ -104,22 +107,21 @@ export class ClientCollection {
104107
/**
105108
* creates a new client to replace one that crashed.
106109
*/
107-
public async recreateClients(transferFileOwnership: boolean): Promise<void> {
110+
public async recreateClients(switchToFailsafeMode?: boolean): Promise<void> {
108111

109112
// Swap out the map, so we are not changing it while iterating over it.
110113
const oldLanguageClients: Map<string, cpptools.Client> = this.languageClients;
111114
this.languageClients = new Map<string, cpptools.Client>();
112115

116+
if (switchToFailsafeMode) {
117+
this.useFailsafeMode = true;
118+
}
119+
113120
for (const pair of oldLanguageClients) {
114121
const client: cpptools.Client = pair[1];
115122

116-
let newClient: cpptools.Client;
117-
if (transferFileOwnership) {
118-
newClient = this.createClient(client.RootFolder, true);
119-
client.TrackedDocuments.forEach(document => this.transferOwnership(document, client));
120-
} else {
121-
newClient = cpptools.createNullClient();
122-
}
123+
const newClient: cpptools.Client = this.createClient(client.RootFolder, true);
124+
client.TrackedDocuments.forEach(document => this.transferOwnership(document, client));
123125

124126
if (this.activeClient === client) {
125127
// It cannot be undefined. If there is an active document, we activate it later.
@@ -272,15 +274,14 @@ export class ClientCollection {
272274
}
273275

274276
public createClient(folder?: vscode.WorkspaceFolder, deactivated?: boolean): cpptools.Client {
275-
const newClient: cpptools.Client = cpptools.createClient(this, folder);
277+
const newClient: cpptools.Client = this.useFailsafeMode ? cpptools.createNullClient() : cpptools.createClient(this, folder);
276278
if (deactivated) {
277279
newClient.deactivate(); // e.g. prevent the current config from switching.
278280
}
279281
const key: string = folder ? util.asFolder(folder.uri) : defaultClientKey;
280282
this.languageClients.set(key, newClient);
281283
getCustomConfigProviders().forEach(provider => newClient.onRegisterCustomConfigurationProvider(provider));
282-
const defaultClient: cpptools.DefaultClient = <cpptools.DefaultClient>newClient;
283-
defaultClient.sendAllSettings();
284+
newClient.sendAllSettings();
284285
return newClient;
285286
}
286287

0 commit comments

Comments
 (0)