Index: clangd/clients/clangd-vscode/src/extension.ts =================================================================== --- clangd/clients/clangd-vscode/src/extension.ts +++ clangd/clients/clangd-vscode/src/extension.ts @@ -12,6 +12,25 @@ return config.get(option, defaultValue); } +class NoRestartErrorHandler implements vscodelc.ErrorHandler { + // Mirror the implementation of DefaultErrorHandler which is not exposed in + // vscode-languageclient. + public error(_error: Error, _message: vscodelc.Message, count: number): vscodelc.ErrorAction { + if (count && count <= 3) { + return vscodelc.ErrorAction.Continue; + } + return vscodelc.ErrorAction.Shutdown; + } + public closed(): vscodelc.CloseAction { + // The default implementation will restarts clangd up to 5 times if clangd + // crashes. We don't restart clangd -- this'd make the life of tracking/reporting + // crashes easier, and sometimes restart doesn't help as the file state + // is usually broken (files are not opened, etc). + vscode.window.showErrorMessage(`The clangd crashed, please reload the window to restart.`); + return vscodelc.CloseAction.DoNotRestart; + } +} + namespace SwitchSourceHeaderRequest { export const type = new vscodelc.RequestType vscode.Uri.file(realpathSync(vscode.Uri.parse(value).fsPath)) }, + errorHandler: new NoRestartErrorHandler(), // Do not switch to output window when clangd returns output revealOutputChannelOn: vscodelc.RevealOutputChannelOn.Never };