Fix issue with cpptools restarting when it should not (#8850)

This commit is contained in:
Colen Garoutte-Carson 2022-02-11 16:58:21 -08:00 коммит произвёл GitHub
Родитель c02440cfe1
Коммит 5f888eef30
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 17 добавлений и 14 удалений

Просмотреть файл

@ -746,6 +746,7 @@ export interface Client {
onInterval(): void;
dispose(): void;
addFileAssociations(fileAssociations: string, languageId: string): void;
sendAllSettings(): void;
sendDidChangeSettings(settings: any): void;
}
@ -1481,15 +1482,15 @@ export class DefaultClient implements Client {
languageClientCrashedNeedsRestart = true;
telemetry.logLanguageServerEvent("languageClientCrash");
if (languageClientCrashTimes.length < 5) {
allClients.recreateClients(true);
allClients.recreateClients();
} else {
const elapsed: number = languageClientCrashTimes[languageClientCrashTimes.length - 1] - languageClientCrashTimes[0];
if (elapsed <= 3 * 60 * 1000) {
vscode.window.showErrorMessage(localize('server.crashed2', "The language server crashed 5 times in the last 3 minutes. It will not be restarted."));
allClients.recreateClients(false);
allClients.recreateClients(true);
} else {
languageClientCrashTimes.shift();
allClients.recreateClients(true);
allClients.recreateClients();
}
}
return CloseAction.DoNotRestart;
@ -3319,5 +3320,6 @@ class NullClient implements Client {
this.stringEvent.dispose();
}
addFileAssociations(fileAssociations: string, languageId: string): void { }
sendAllSettings(): void { }
sendDidChangeSettings(settings: any): void { }
}

Просмотреть файл

@ -25,6 +25,9 @@ export class ClientCollection {
private activeDocument?: vscode.TextDocument;
public timeTelemetryCollector: TimeTelemetryCollector = new TimeTelemetryCollector();
// This is a one-time switch to a mode that suppresses launching of the cpptools client process.
private useFailsafeMode: boolean = false;
public get ActiveClient(): cpptools.Client { return this.activeClient; }
public get Names(): ClientKey[] {
const result: ClientKey[] = [];
@ -104,22 +107,21 @@ export class ClientCollection {
/**
* creates a new client to replace one that crashed.
*/
public async recreateClients(transferFileOwnership: boolean): Promise<void> {
public async recreateClients(switchToFailsafeMode?: boolean): Promise<void> {
// Swap out the map, so we are not changing it while iterating over it.
const oldLanguageClients: Map<string, cpptools.Client> = this.languageClients;
this.languageClients = new Map<string, cpptools.Client>();
if (switchToFailsafeMode) {
this.useFailsafeMode = true;
}
for (const pair of oldLanguageClients) {
const client: cpptools.Client = pair[1];
let newClient: cpptools.Client;
if (transferFileOwnership) {
newClient = this.createClient(client.RootFolder, true);
client.TrackedDocuments.forEach(document => this.transferOwnership(document, client));
} else {
newClient = cpptools.createNullClient();
}
const newClient: cpptools.Client = this.createClient(client.RootFolder, true);
client.TrackedDocuments.forEach(document => this.transferOwnership(document, client));
if (this.activeClient === client) {
// It cannot be undefined. If there is an active document, we activate it later.
@ -272,15 +274,14 @@ export class ClientCollection {
}
public createClient(folder?: vscode.WorkspaceFolder, deactivated?: boolean): cpptools.Client {
const newClient: cpptools.Client = cpptools.createClient(this, folder);
const newClient: cpptools.Client = this.useFailsafeMode ? cpptools.createNullClient() : cpptools.createClient(this, folder);
if (deactivated) {
newClient.deactivate(); // e.g. prevent the current config from switching.
}
const key: string = folder ? util.asFolder(folder.uri) : defaultClientKey;
this.languageClients.set(key, newClient);
getCustomConfigProviders().forEach(provider => newClient.onRegisterCustomConfigurationProvider(provider));
const defaultClient: cpptools.DefaultClient = <cpptools.DefaultClient>newClient;
defaultClient.sendAllSettings();
newClient.sendAllSettings();
return newClient;
}