-
Notifications
You must be signed in to change notification settings - Fork 8
/
wait_stdin.patch
31 lines (31 loc) · 930 Bytes
/
wait_stdin.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
diff --git a/clang-tools-extra/clangd/JSONTransport.cpp b/clang-tools-extra/clangd/JSONTransport.cpp
index 9dc0df807..b1a4e9bd1 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -1,3 +1,26 @@
+#ifdef __EMSCRIPTEN__
+
+#include <emscripten.h>
+
+#include "support/Shutdown.h"
+#include <utility>
+
+EM_ASYNC_JS(void, waitForStdin, (), {
+ await Module.stdinReady();
+})
+
+template <typename Fun, typename Ret = decltype(std::declval<Fun>()())>
+Ret doUntilStdinAvailable(
+ const std::enable_if_t<true, Ret>& fail,
+ const Fun& f) {
+ waitForStdin();
+ return clang::clangd::retryAfterSignalUnlessShutdown(fail, f);
+}
+
+#define retryAfterSignalUnlessShutdown doUntilStdinAvailable
+
+#endif
+
//===--- JSONTransport.cpp - sending and receiving LSP messages over JSON -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.