[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:52:18 PST 2019


hokein updated this revision to Diff 185737.
hokein added a comment.

update


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57884/new/

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.185737.patch
Type: text/x-patch
Size: 1743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/ad62687a/attachment.bin>


More information about the cfe-commits mailing list