blob: 9dea83ae896e0789b09cf703cd06b8feb05605c8 [file] [log] [blame]
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +00001//===--- JSONRPCDispatcher.cpp - Main JSON parser entry point -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "JSONRPCDispatcher.h"
Kadir Cetinkaya689bf932018-08-24 13:09:41 +000011#include "Cancellation.h"
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000012#include "ProtocolHandlers.h"
Sam McCall8567cb32017-11-02 09:21:51 +000013#include "Trace.h"
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000014#include "llvm/ADT/SmallString.h"
Sam McCall94362c62017-11-07 14:45:31 +000015#include "llvm/ADT/StringExtras.h"
Sam McCalla90f2572018-02-16 16:41:42 +000016#include "llvm/Support/Chrono.h"
Sam McCall27a07cf2018-06-05 09:34:46 +000017#include "llvm/Support/Errno.h"
Sam McCallbed58852018-07-11 10:35:11 +000018#include "llvm/Support/FormatVariadic.h"
Sam McCalld20d7982018-07-09 14:25:59 +000019#include "llvm/Support/JSON.h"
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000020#include "llvm/Support/SourceMgr.h"
Ilya Biryukov687b92a2017-05-16 15:23:55 +000021#include <istream>
22
Sam McCalld20d7982018-07-09 14:25:59 +000023using namespace llvm;
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000024using namespace clang;
25using namespace clangd;
26
Ilya Biryukov940901e2017-12-13 12:51:22 +000027namespace {
Sam McCalld20d7982018-07-09 14:25:59 +000028static Key<json::Value> RequestID;
Ilya Biryukov940901e2017-12-13 12:51:22 +000029static Key<JSONOutput *> RequestOut;
Sam McCall1b475a12018-01-26 09:00:30 +000030
31// When tracing, we trace a request and attach the repsonse in reply().
32// Because the Span isn't available, we find the current request using Context.
33class RequestSpan {
Sam McCalld20d7982018-07-09 14:25:59 +000034 RequestSpan(llvm::json::Object *Args) : Args(Args) {}
Sam McCall1b475a12018-01-26 09:00:30 +000035 std::mutex Mu;
Sam McCalld20d7982018-07-09 14:25:59 +000036 llvm::json::Object *Args;
Sam McCall24f0fa32018-01-26 11:23:33 +000037 static Key<std::unique_ptr<RequestSpan>> RSKey;
Sam McCall1b475a12018-01-26 09:00:30 +000038
39public:
40 // Return a context that's aware of the enclosing request, identified by Span.
41 static Context stash(const trace::Span &Span) {
Sam McCalld1a7a372018-01-31 13:40:48 +000042 return Context::current().derive(
43 RSKey, std::unique_ptr<RequestSpan>(new RequestSpan(Span.Args)));
Sam McCall1b475a12018-01-26 09:00:30 +000044 }
45
46 // If there's an enclosing request and the tracer is interested, calls \p F
Sam McCalld20d7982018-07-09 14:25:59 +000047 // with a json::Object where request info can be added.
Sam McCalld1a7a372018-01-31 13:40:48 +000048 template <typename Func> static void attach(Func &&F) {
49 auto *RequestArgs = Context::current().get(RSKey);
Sam McCall1b475a12018-01-26 09:00:30 +000050 if (!RequestArgs || !*RequestArgs || !(*RequestArgs)->Args)
51 return;
52 std::lock_guard<std::mutex> Lock((*RequestArgs)->Mu);
53 F(*(*RequestArgs)->Args);
54 }
55};
Sam McCall24f0fa32018-01-26 11:23:33 +000056Key<std::unique_ptr<RequestSpan>> RequestSpan::RSKey;
Ilya Biryukov940901e2017-12-13 12:51:22 +000057} // namespace
58
Sam McCalld20d7982018-07-09 14:25:59 +000059void JSONOutput::writeMessage(const json::Value &Message) {
Sam McCalldd0566b2017-11-06 15:40:30 +000060 std::string S;
61 llvm::raw_string_ostream OS(S);
62 if (Pretty)
63 OS << llvm::formatv("{0:2}", Message);
64 else
65 OS << Message;
66 OS.flush();
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000067
Sam McCalla90f2572018-02-16 16:41:42 +000068 {
69 std::lock_guard<std::mutex> Guard(StreamMutex);
70 Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
71 Outs.flush();
72 }
Sam McCall8d7760c2018-07-12 11:52:18 +000073 vlog(">>> {0}\n", S);
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +000074}
75
Sam McCallbed58852018-07-11 10:35:11 +000076void JSONOutput::log(Logger::Level Level,
77 const llvm::formatv_object_base &Message) {
78 if (Level < MinLevel)
79 return;
Sam McCalla90f2572018-02-16 16:41:42 +000080 llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
Sam McCalld1a7a372018-01-31 13:40:48 +000081 trace::log(Message);
Benjamin Kramere14bd422017-02-15 16:44:11 +000082 std::lock_guard<std::mutex> Guard(StreamMutex);
Sam McCallbed58852018-07-11 10:35:11 +000083 Logs << llvm::formatv("{0}[{1:%H:%M:%S.%L}] {2}\n", indicator(Level),
84 Timestamp, Message);
Benjamin Kramere14bd422017-02-15 16:44:11 +000085 Logs.flush();
86}
87
Ilya Biryukove6dbb582017-10-10 09:08:47 +000088void JSONOutput::mirrorInput(const Twine &Message) {
89 if (!InputMirror)
90 return;
91
92 *InputMirror << Message;
93 InputMirror->flush();
94}
95
Sam McCalld20d7982018-07-09 14:25:59 +000096void clangd::reply(json::Value &&Result) {
Kadir Cetinkaya689bf932018-08-24 13:09:41 +000097 auto ID = getRequestId();
Sam McCalldd0566b2017-11-06 15:40:30 +000098 if (!ID) {
Sam McCallbed58852018-07-11 10:35:11 +000099 elog("Attempted to reply to a notification!");
Sam McCall8a5dded2017-10-12 13:29:58 +0000100 return;
101 }
Sam McCalld20d7982018-07-09 14:25:59 +0000102 RequestSpan::attach([&](json::Object &Args) { Args["Reply"] = Result; });
Sam McCall8d7760c2018-07-12 11:52:18 +0000103 log("--> reply({0})", *ID);
Sam McCalld1a7a372018-01-31 13:40:48 +0000104 Context::current()
105 .getExisting(RequestOut)
Sam McCalld20d7982018-07-09 14:25:59 +0000106 ->writeMessage(json::Object{
Ilya Biryukov940901e2017-12-13 12:51:22 +0000107 {"jsonrpc", "2.0"},
108 {"id", *ID},
109 {"result", std::move(Result)},
110 });
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000111}
112
Ilya Biryukov74f26552018-07-26 12:05:31 +0000113void clangd::replyError(ErrorCode Code, const llvm::StringRef &Message) {
114 elog("Error {0}: {1}", static_cast<int>(Code), Message);
Sam McCalld20d7982018-07-09 14:25:59 +0000115 RequestSpan::attach([&](json::Object &Args) {
Ilya Biryukov74f26552018-07-26 12:05:31 +0000116 Args["Error"] = json::Object{{"code", static_cast<int>(Code)},
Sam McCalld20d7982018-07-09 14:25:59 +0000117 {"message", Message.str()}};
Sam McCall1b475a12018-01-26 09:00:30 +0000118 });
Ilya Biryukov940901e2017-12-13 12:51:22 +0000119
Kadir Cetinkaya689bf932018-08-24 13:09:41 +0000120 if (auto ID = getRequestId()) {
Sam McCall8d7760c2018-07-12 11:52:18 +0000121 log("--> reply({0}) error: {1}", *ID, Message);
Sam McCalld1a7a372018-01-31 13:40:48 +0000122 Context::current()
123 .getExisting(RequestOut)
Sam McCalld20d7982018-07-09 14:25:59 +0000124 ->writeMessage(json::Object{
Ilya Biryukov940901e2017-12-13 12:51:22 +0000125 {"jsonrpc", "2.0"},
126 {"id", *ID},
Ilya Biryukov74f26552018-07-26 12:05:31 +0000127 {"error", json::Object{{"code", static_cast<int>(Code)},
Sam McCalld20d7982018-07-09 14:25:59 +0000128 {"message", Message}}},
Ilya Biryukov940901e2017-12-13 12:51:22 +0000129 });
Sam McCall8a5dded2017-10-12 13:29:58 +0000130 }
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000131}
132
Kadir Cetinkaya689bf932018-08-24 13:09:41 +0000133void clangd::replyError(Error E) {
134 handleAllErrors(std::move(E),
135 [](const CancelledError &TCE) {
136 replyError(ErrorCode::RequestCancelled, TCE.message());
137 },
138 [](const ErrorInfoBase &EIB) {
139 replyError(ErrorCode::InvalidParams, EIB.message());
140 });
141}
142
Sam McCalld20d7982018-07-09 14:25:59 +0000143void clangd::call(StringRef Method, json::Value &&Params) {
Sam McCalld20d7982018-07-09 14:25:59 +0000144 RequestSpan::attach([&](json::Object &Args) {
145 Args["Call"] = json::Object{{"method", Method.str()}, {"params", Params}};
Sam McCall1b475a12018-01-26 09:00:30 +0000146 });
Sam McCall8d7760c2018-07-12 11:52:18 +0000147 // FIXME: Generate/Increment IDs for every request so that we can get proper
148 // replies once we need to.
149 auto ID = 1;
150 log("--> {0}({1})", Method, ID);
Sam McCalld1a7a372018-01-31 13:40:48 +0000151 Context::current()
152 .getExisting(RequestOut)
Sam McCalld20d7982018-07-09 14:25:59 +0000153 ->writeMessage(json::Object{
Ilya Biryukov940901e2017-12-13 12:51:22 +0000154 {"jsonrpc", "2.0"},
Sam McCall8d7760c2018-07-12 11:52:18 +0000155 {"id", ID},
Ilya Biryukov940901e2017-12-13 12:51:22 +0000156 {"method", Method},
157 {"params", std::move(Params)},
158 });
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +0000159}
160
Sam McCall8a5dded2017-10-12 13:29:58 +0000161void JSONRPCDispatcher::registerHandler(StringRef Method, Handler H) {
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000162 assert(!Handlers.count(Method) && "Handler already registered!");
163 Handlers[Method] = std::move(H);
164}
165
Sam McCall8d7760c2018-07-12 11:52:18 +0000166static void logIncomingMessage(const llvm::Optional<json::Value> &ID,
167 llvm::Optional<StringRef> Method,
168 const json::Object *Error) {
169 if (Method) { // incoming request
170 if (ID) // call
171 log("<-- {0}({1})", *Method, *ID);
172 else // notification
173 log("<-- {0}", *Method);
174 } else if (ID) { // response, ID must be provided
175 if (Error)
176 log("<-- reply({0}) error: {1}", *ID,
177 Error->getString("message").getValueOr("<no message>"));
178 else
179 log("<-- reply({0})", *ID);
180 }
181}
182
Sam McCalld20d7982018-07-09 14:25:59 +0000183bool JSONRPCDispatcher::call(const json::Value &Message,
184 JSONOutput &Out) const {
Sam McCallec109022017-11-28 09:37:43 +0000185 // Message must be an object with "jsonrpc":"2.0".
Sam McCalld20d7982018-07-09 14:25:59 +0000186 auto *Object = Message.getAsObject();
Sam McCallec109022017-11-28 09:37:43 +0000187 if (!Object || Object->getString("jsonrpc") != Optional<StringRef>("2.0"))
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000188 return false;
Sam McCallec109022017-11-28 09:37:43 +0000189 // ID may be any JSON value. If absent, this is a notification.
Sam McCalld20d7982018-07-09 14:25:59 +0000190 llvm::Optional<json::Value> ID;
Sam McCallec109022017-11-28 09:37:43 +0000191 if (auto *I = Object->get("id"))
192 ID = std::move(*I);
Sam McCallec109022017-11-28 09:37:43 +0000193 auto Method = Object->getString("method");
Sam McCall8d7760c2018-07-12 11:52:18 +0000194 logIncomingMessage(ID, Method, Object->getObject("error"));
195 if (!Method) // We only handle incoming requests, and ignore responses.
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000196 return false;
Sam McCallec109022017-11-28 09:37:43 +0000197 // Params should be given, use null if not.
Sam McCalld20d7982018-07-09 14:25:59 +0000198 json::Value Params = nullptr;
Sam McCallec109022017-11-28 09:37:43 +0000199 if (auto *P = Object->get("params"))
200 Params = std::move(*P);
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000201
Sam McCallec109022017-11-28 09:37:43 +0000202 auto I = Handlers.find(*Method);
203 auto &Handler = I != Handlers.end() ? I->second : UnknownHandler;
Ilya Biryukov940901e2017-12-13 12:51:22 +0000204
Ilya Biryukovee27d2e2017-12-14 15:04:59 +0000205 // Create a Context that contains request information.
Sam McCalld1a7a372018-01-31 13:40:48 +0000206 WithContextValue WithRequestOut(RequestOut, &Out);
207 llvm::Optional<WithContextValue> WithID;
Ilya Biryukovee27d2e2017-12-14 15:04:59 +0000208 if (ID)
Sam McCalld1a7a372018-01-31 13:40:48 +0000209 WithID.emplace(RequestID, *ID);
Ilya Biryukovee27d2e2017-12-14 15:04:59 +0000210
211 // Create a tracing Span covering the whole request lifetime.
Sam McCalld1a7a372018-01-31 13:40:48 +0000212 trace::Span Tracer(*Method);
Ilya Biryukov940901e2017-12-13 12:51:22 +0000213 if (ID)
Sam McCall1b475a12018-01-26 09:00:30 +0000214 SPAN_ATTACH(Tracer, "ID", *ID);
215 SPAN_ATTACH(Tracer, "Params", Params);
Ilya Biryukov940901e2017-12-13 12:51:22 +0000216
Sam McCall1b475a12018-01-26 09:00:30 +0000217 // Stash a reference to the span args, so later calls can add metadata.
Sam McCalld1a7a372018-01-31 13:40:48 +0000218 WithContext WithRequestSpan(RequestSpan::stash(Tracer));
219 Handler(std::move(Params));
Benjamin Kramerbb1cdb62017-02-07 10:28:20 +0000220 return true;
221}
Ilya Biryukovafb55542017-05-16 14:40:30 +0000222
Sam McCall27a07cf2018-06-05 09:34:46 +0000223// Tries to read a line up to and including \n.
224// If failing, feof() or ferror() will be set.
225static bool readLine(std::FILE *In, std::string &Out) {
226 static constexpr int BufSize = 1024;
227 size_t Size = 0;
228 Out.clear();
229 for (;;) {
230 Out.resize(Size + BufSize);
231 // Handle EINTR which is sent when a debugger attaches on some platforms.
232 if (!llvm::sys::RetryAfterSignal(nullptr, ::fgets, &Out[Size], BufSize, In))
233 return false;
234 clearerr(In);
235 // If the line contained null bytes, anything after it (including \n) will
236 // be ignored. Fortunately this is not a legal header or JSON.
237 size_t Read = std::strlen(&Out[Size]);
238 if (Read > 0 && Out[Size + Read - 1] == '\n') {
239 Out.resize(Size + Read);
240 return true;
241 }
242 Size += Read;
243 }
244}
245
246// Returns None when:
247// - ferror() or feof() are set.
248// - Content-Length is missing or empty (protocol error)
249static llvm::Optional<std::string> readStandardMessage(std::FILE *In,
Sam McCall5ed599e2018-02-06 10:47:30 +0000250 JSONOutput &Out) {
251 // A Language Server Protocol message starts with a set of HTTP headers,
252 // delimited by \r\n, and terminated by an empty line (\r\n).
253 unsigned long long ContentLength = 0;
Sam McCall27a07cf2018-06-05 09:34:46 +0000254 std::string Line;
255 while (true) {
256 if (feof(In) || ferror(In) || !readLine(In, Line))
257 return llvm::None;
Benjamin Kramer1d053792017-10-27 17:06:41 +0000258
Sam McCall5ed599e2018-02-06 10:47:30 +0000259 Out.mirrorInput(Line);
Sam McCall5ed599e2018-02-06 10:47:30 +0000260 llvm::StringRef LineRef(Line);
Sam McCall8567cb32017-11-02 09:21:51 +0000261
Sam McCall5ed599e2018-02-06 10:47:30 +0000262 // We allow comments in headers. Technically this isn't part
263 // of the LSP specification, but makes writing tests easier.
264 if (LineRef.startswith("#"))
265 continue;
266
Sam McCall27a07cf2018-06-05 09:34:46 +0000267 // Content-Length is a mandatory header, and the only one we handle.
Sam McCall5ed599e2018-02-06 10:47:30 +0000268 if (LineRef.consume_front("Content-Length: ")) {
269 if (ContentLength != 0) {
Sam McCallbed58852018-07-11 10:35:11 +0000270 elog("Warning: Duplicate Content-Length header received. "
271 "The previous value for this message ({0}) was ignored.",
272 ContentLength);
Ilya Biryukov1fab4f82017-09-04 12:28:15 +0000273 }
Sam McCall5ed599e2018-02-06 10:47:30 +0000274 llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
275 continue;
276 } else if (!LineRef.trim().empty()) {
277 // It's another header, ignore it.
278 continue;
279 } else {
280 // An empty line indicates the end of headers.
281 // Go ahead and read the JSON.
282 break;
283 }
284 }
285
Sam McCall27a07cf2018-06-05 09:34:46 +0000286 // The fuzzer likes crashing us by sending "Content-Length: 9999999999999999"
Sam McCall5ed599e2018-02-06 10:47:30 +0000287 if (ContentLength > 1 << 30) { // 1024M
Sam McCallbed58852018-07-11 10:35:11 +0000288 elog("Refusing to read message with long Content-Length: {0}. "
289 "Expect protocol errors",
290 ContentLength);
Sam McCall27a07cf2018-06-05 09:34:46 +0000291 return llvm::None;
292 }
293 if (ContentLength == 0) {
294 log("Warning: Missing Content-Length header, or zero-length message.");
Sam McCall5ed599e2018-02-06 10:47:30 +0000295 return llvm::None;
296 }
297
Sam McCall27a07cf2018-06-05 09:34:46 +0000298 std::string JSON(ContentLength, '\0');
299 for (size_t Pos = 0, Read; Pos < ContentLength; Pos += Read) {
300 // Handle EINTR which is sent when a debugger attaches on some platforms.
301 Read = llvm::sys::RetryAfterSignal(0u, ::fread, &JSON[Pos], 1,
302 ContentLength - Pos, In);
303 Out.mirrorInput(StringRef(&JSON[Pos], Read));
304 if (Read == 0) {
Sam McCallbed58852018-07-11 10:35:11 +0000305 elog("Input was aborted. Read only {0} bytes of expected {1}.", Pos,
306 ContentLength);
Sam McCall5ed599e2018-02-06 10:47:30 +0000307 return llvm::None;
308 }
Sam McCall27a07cf2018-06-05 09:34:46 +0000309 clearerr(In); // If we're done, the error was transient. If we're not done,
310 // either it was transient or we'll see it again on retry.
311 Pos += Read;
Sam McCall5ed599e2018-02-06 10:47:30 +0000312 }
Sam McCall27a07cf2018-06-05 09:34:46 +0000313 return std::move(JSON);
Sam McCall5ed599e2018-02-06 10:47:30 +0000314}
315
316// For lit tests we support a simplified syntax:
317// - messages are delimited by '---' on a line by itself
318// - lines starting with # are ignored.
319// This is a testing path, so favor simplicity over performance here.
Sam McCall27a07cf2018-06-05 09:34:46 +0000320// When returning None, feof() or ferror() will be set.
321static llvm::Optional<std::string> readDelimitedMessage(std::FILE *In,
Sam McCall5ed599e2018-02-06 10:47:30 +0000322 JSONOutput &Out) {
323 std::string JSON;
324 std::string Line;
Sam McCall27a07cf2018-06-05 09:34:46 +0000325 while (readLine(In, Line)) {
Sam McCall5ed599e2018-02-06 10:47:30 +0000326 auto LineRef = llvm::StringRef(Line).trim();
327 if (LineRef.startswith("#")) // comment
328 continue;
329
Jan Korous62435152018-04-23 15:55:07 +0000330 // found a delimiter
Jan Korous1bc528c2018-04-23 15:58:42 +0000331 if (LineRef.rtrim() == "---")
Jan Korous62435152018-04-23 15:55:07 +0000332 break;
333
334 JSON += Line;
Sam McCall5ed599e2018-02-06 10:47:30 +0000335 }
336
Sam McCall27a07cf2018-06-05 09:34:46 +0000337 if (ferror(In)) {
Sam McCallbed58852018-07-11 10:35:11 +0000338 elog("Input error while reading message!");
Sam McCall5ed599e2018-02-06 10:47:30 +0000339 return llvm::None;
Sam McCall27a07cf2018-06-05 09:34:46 +0000340 } else { // Including EOF
Jan Korous62435152018-04-23 15:55:07 +0000341 Out.mirrorInput(
342 llvm::formatv("Content-Length: {0}\r\n\r\n{1}", JSON.size(), JSON));
Sam McCall5ed599e2018-02-06 10:47:30 +0000343 return std::move(JSON);
344 }
345}
346
Sam McCall27a07cf2018-06-05 09:34:46 +0000347// The use of C-style std::FILE* IO deserves some explanation.
348// Previously, std::istream was used. When a debugger attached on MacOS, the
349// process received EINTR, the stream went bad, and clangd exited.
350// A retry-on-EINTR loop around reads solved this problem, but caused clangd to
351// sometimes hang rather than exit on other OSes. The interaction between
352// istreams and signals isn't well-specified, so it's hard to get this right.
353// The C APIs seem to be clearer in this respect.
354void clangd::runLanguageServerLoop(std::FILE *In, JSONOutput &Out,
Sam McCall5ed599e2018-02-06 10:47:30 +0000355 JSONStreamStyle InputStyle,
356 JSONRPCDispatcher &Dispatcher,
357 bool &IsDone) {
358 auto &ReadMessage =
359 (InputStyle == Delimited) ? readDelimitedMessage : readStandardMessage;
Sam McCall27a07cf2018-06-05 09:34:46 +0000360 while (!IsDone && !feof(In)) {
361 if (ferror(In)) {
Sam McCallbed58852018-07-11 10:35:11 +0000362 elog("IO error: {0}", llvm::sys::StrError());
Sam McCall27a07cf2018-06-05 09:34:46 +0000363 return;
364 }
Sam McCall5ed599e2018-02-06 10:47:30 +0000365 if (auto JSON = ReadMessage(In, Out)) {
366 if (auto Doc = json::parse(*JSON)) {
Sam McCallec109022017-11-28 09:37:43 +0000367 // Log the formatted message.
Sam McCall8d7760c2018-07-12 11:52:18 +0000368 vlog(Out.Pretty ? "<<< {0:2}\n" : "<<< {0}\n", *Doc);
Sam McCallec109022017-11-28 09:37:43 +0000369 // Finally, execute the action for this JSON message.
370 if (!Dispatcher.call(*Doc, Out))
Sam McCallbed58852018-07-11 10:35:11 +0000371 elog("JSON dispatch failed!");
Sam McCallec109022017-11-28 09:37:43 +0000372 } else {
373 // Parse error. Log the raw message.
Sam McCall8d7760c2018-07-12 11:52:18 +0000374 vlog("<<< {0}\n", *JSON);
Sam McCallbed58852018-07-11 10:35:11 +0000375 elog("JSON parse error: {0}", llvm::toString(Doc.takeError()));
Sam McCallec109022017-11-28 09:37:43 +0000376 }
Ilya Biryukovafb55542017-05-16 14:40:30 +0000377 }
378 }
379}
Kadir Cetinkaya689bf932018-08-24 13:09:41 +0000380
381const json::Value *clangd::getRequestId() {
382 return Context::current().get(RequestID);
383}