[PATCH] D57884: [clangd] Don't restart clangd in vscode extension.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 7 03:48:31 PST 2019


hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric.
Herald added a project: clang.

This would make the life of tracking/reporting crashes easier, and
restarting clangd doesn't help as file state is usually broken.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D57884

Files:
  clangd/clients/clangd-vscode/src/extension.ts


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<T>(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<vscodelc.TextDocumentIdentifier, string|undefined,
@@ -88,6 +107,7 @@
             protocol2Code: (value: string) =>
                 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
     };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57884.185735.patch
Type: text/x-patch
Size: 1701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/035f35bd/attachment.bin>


More information about the cfe-commits mailing list