Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 1 | //===--- JSONTransport.cpp - sending and receiving LSP messages over JSON -===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | #include "Logger.h" |
| 9 | #include "Protocol.h" // For LSPError |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 10 | #include "Shutdown.h" |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 11 | #include "Transport.h" |
| 12 | #include "llvm/Support/Errno.h" |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 13 | #include "llvm/Support/Error.h" |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 14 | |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 15 | namespace clang { |
| 16 | namespace clangd { |
| 17 | namespace { |
| 18 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 19 | llvm::json::Object encodeError(llvm::Error E) { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 20 | std::string Message; |
| 21 | ErrorCode Code = ErrorCode::UnknownErrorCode; |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 22 | if (llvm::Error Unhandled = llvm::handleErrors( |
| 23 | std::move(E), [&](const LSPError &L) -> llvm::Error { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 24 | Message = L.Message; |
| 25 | Code = L.Code; |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 26 | return llvm::Error::success(); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 27 | })) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 28 | Message = llvm::toString(std::move(Unhandled)); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 29 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 30 | return llvm::json::Object{ |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 31 | {"message", std::move(Message)}, |
| 32 | {"code", int64_t(Code)}, |
| 33 | }; |
| 34 | } |
| 35 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 36 | llvm::Error decodeError(const llvm::json::Object &O) { |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame^] | 37 | std::string Msg = |
| 38 | std::string(O.getString("message").getValueOr("Unspecified error")); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 39 | if (auto Code = O.getInteger("code")) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 40 | return llvm::make_error<LSPError>(std::move(Msg), ErrorCode(*Code)); |
| 41 | return llvm::make_error<llvm::StringError>(std::move(Msg), |
| 42 | llvm::inconvertibleErrorCode()); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | class JSONTransport : public Transport { |
| 46 | public: |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 47 | JSONTransport(std::FILE *In, llvm::raw_ostream &Out, |
| 48 | llvm::raw_ostream *InMirror, bool Pretty, JSONStreamStyle Style) |
| 49 | : In(In), Out(Out), InMirror(InMirror ? *InMirror : llvm::nulls()), |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 50 | Pretty(Pretty), Style(Style) {} |
| 51 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 52 | void notify(llvm::StringRef Method, llvm::json::Value Params) override { |
| 53 | sendMessage(llvm::json::Object{ |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 54 | {"jsonrpc", "2.0"}, |
| 55 | {"method", Method}, |
| 56 | {"params", std::move(Params)}, |
| 57 | }); |
| 58 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 59 | void call(llvm::StringRef Method, llvm::json::Value Params, |
| 60 | llvm::json::Value ID) override { |
| 61 | sendMessage(llvm::json::Object{ |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 62 | {"jsonrpc", "2.0"}, |
| 63 | {"id", std::move(ID)}, |
| 64 | {"method", Method}, |
| 65 | {"params", std::move(Params)}, |
| 66 | }); |
| 67 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 68 | void reply(llvm::json::Value ID, |
| 69 | llvm::Expected<llvm::json::Value> Result) override { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 70 | if (Result) { |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 71 | sendMessage(llvm::json::Object{ |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 72 | {"jsonrpc", "2.0"}, |
| 73 | {"id", std::move(ID)}, |
| 74 | {"result", std::move(*Result)}, |
| 75 | }); |
| 76 | } else { |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 77 | sendMessage(llvm::json::Object{ |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 78 | {"jsonrpc", "2.0"}, |
| 79 | {"id", std::move(ID)}, |
| 80 | {"error", encodeError(Result.takeError())}, |
| 81 | }); |
| 82 | } |
| 83 | } |
| 84 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 85 | llvm::Error loop(MessageHandler &Handler) override { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 86 | while (!feof(In)) { |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 87 | if (shutdownRequested()) |
| 88 | return llvm::createStringError( |
| 89 | std::make_error_code(std::errc::operation_canceled), |
| 90 | "Got signal, shutting down"); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 91 | if (ferror(In)) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 92 | return llvm::errorCodeToError( |
| 93 | std::error_code(errno, std::system_category())); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 94 | if (auto JSON = readRawMessage()) { |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 95 | if (auto Doc = llvm::json::parse(*JSON)) { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 96 | vlog(Pretty ? "<<< {0:2}\n" : "<<< {0}\n", *Doc); |
| 97 | if (!handleMessage(std::move(*Doc), Handler)) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 98 | return llvm::Error::success(); // we saw the "exit" notification. |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 99 | } else { |
| 100 | // Parse error. Log the raw message. |
| 101 | vlog("<<< {0}\n", *JSON); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 102 | elog("JSON parse error: {0}", llvm::toString(Doc.takeError())); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 106 | return llvm::errorCodeToError(std::make_error_code(std::errc::io_error)); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | private: |
| 110 | // Dispatches incoming message to Handler onNotify/onCall/onReply. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 111 | bool handleMessage(llvm::json::Value Message, MessageHandler &Handler); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 112 | // Writes outgoing message to Out stream. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 113 | void sendMessage(llvm::json::Value Message) { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 114 | std::string S; |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 115 | llvm::raw_string_ostream OS(S); |
| 116 | OS << llvm::formatv(Pretty ? "{0:2}" : "{0}", Message); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 117 | OS.flush(); |
| 118 | Out << "Content-Length: " << S.size() << "\r\n\r\n" << S; |
| 119 | Out.flush(); |
| 120 | vlog(">>> {0}\n", S); |
| 121 | } |
| 122 | |
| 123 | // Read raw string messages from input stream. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 124 | llvm::Optional<std::string> readRawMessage() { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 125 | return Style == JSONStreamStyle::Delimited ? readDelimitedMessage() |
| 126 | : readStandardMessage(); |
| 127 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 128 | llvm::Optional<std::string> readDelimitedMessage(); |
| 129 | llvm::Optional<std::string> readStandardMessage(); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 130 | |
| 131 | std::FILE *In; |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 132 | llvm::raw_ostream &Out; |
| 133 | llvm::raw_ostream &InMirror; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 134 | bool Pretty; |
| 135 | JSONStreamStyle Style; |
| 136 | }; |
| 137 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 138 | bool JSONTransport::handleMessage(llvm::json::Value Message, |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 139 | MessageHandler &Handler) { |
| 140 | // Message must be an object with "jsonrpc":"2.0". |
| 141 | auto *Object = Message.getAsObject(); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 142 | if (!Object || |
| 143 | Object->getString("jsonrpc") != llvm::Optional<llvm::StringRef>("2.0")) { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 144 | elog("Not a JSON-RPC 2.0 message: {0:2}", Message); |
| 145 | return false; |
| 146 | } |
| 147 | // ID may be any JSON value. If absent, this is a notification. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 148 | llvm::Optional<llvm::json::Value> ID; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 149 | if (auto *I = Object->get("id")) |
| 150 | ID = std::move(*I); |
| 151 | auto Method = Object->getString("method"); |
| 152 | if (!Method) { // This is a response. |
| 153 | if (!ID) { |
| 154 | elog("No method and no response ID: {0:2}", Message); |
| 155 | return false; |
| 156 | } |
| 157 | if (auto *Err = Object->getObject("error")) |
| 158 | return Handler.onReply(std::move(*ID), decodeError(*Err)); |
| 159 | // Result should be given, use null if not. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 160 | llvm::json::Value Result = nullptr; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 161 | if (auto *R = Object->get("result")) |
| 162 | Result = std::move(*R); |
| 163 | return Handler.onReply(std::move(*ID), std::move(Result)); |
| 164 | } |
| 165 | // Params should be given, use null if not. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 166 | llvm::json::Value Params = nullptr; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 167 | if (auto *P = Object->get("params")) |
| 168 | Params = std::move(*P); |
| 169 | |
| 170 | if (ID) |
| 171 | return Handler.onCall(*Method, std::move(Params), std::move(*ID)); |
| 172 | else |
| 173 | return Handler.onNotify(*Method, std::move(Params)); |
| 174 | } |
| 175 | |
| 176 | // Tries to read a line up to and including \n. |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 177 | // If failing, feof(), ferror(), or shutdownRequested() will be set. |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 178 | bool readLine(std::FILE *In, std::string &Out) { |
| 179 | static constexpr int BufSize = 1024; |
| 180 | size_t Size = 0; |
| 181 | Out.clear(); |
| 182 | for (;;) { |
| 183 | Out.resize(Size + BufSize); |
| 184 | // Handle EINTR which is sent when a debugger attaches on some platforms. |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 185 | if (!retryAfterSignalUnlessShutdown( |
| 186 | nullptr, [&] { return std::fgets(&Out[Size], BufSize, In); })) |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 187 | return false; |
| 188 | clearerr(In); |
| 189 | // If the line contained null bytes, anything after it (including \n) will |
| 190 | // be ignored. Fortunately this is not a legal header or JSON. |
| 191 | size_t Read = std::strlen(&Out[Size]); |
| 192 | if (Read > 0 && Out[Size + Read - 1] == '\n') { |
| 193 | Out.resize(Size + Read); |
| 194 | return true; |
| 195 | } |
| 196 | Size += Read; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // Returns None when: |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 201 | // - ferror(), feof(), or shutdownRequested() are set. |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 202 | // - Content-Length is missing or empty (protocol error) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 203 | llvm::Optional<std::string> JSONTransport::readStandardMessage() { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 204 | // A Language Server Protocol message starts with a set of HTTP headers, |
| 205 | // delimited by \r\n, and terminated by an empty line (\r\n). |
| 206 | unsigned long long ContentLength = 0; |
| 207 | std::string Line; |
| 208 | while (true) { |
| 209 | if (feof(In) || ferror(In) || !readLine(In, Line)) |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 210 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 211 | InMirror << Line; |
| 212 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 213 | llvm::StringRef LineRef(Line); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 214 | |
| 215 | // We allow comments in headers. Technically this isn't part |
| 216 | |
| 217 | // of the LSP specification, but makes writing tests easier. |
| 218 | if (LineRef.startswith("#")) |
| 219 | continue; |
| 220 | |
| 221 | // Content-Length is a mandatory header, and the only one we handle. |
| 222 | if (LineRef.consume_front("Content-Length: ")) { |
| 223 | if (ContentLength != 0) { |
| 224 | elog("Warning: Duplicate Content-Length header received. " |
| 225 | "The previous value for this message ({0}) was ignored.", |
| 226 | ContentLength); |
| 227 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 228 | llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 229 | continue; |
| 230 | } else if (!LineRef.trim().empty()) { |
| 231 | // It's another header, ignore it. |
| 232 | continue; |
| 233 | } else { |
| 234 | // An empty line indicates the end of headers. |
| 235 | // Go ahead and read the JSON. |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // The fuzzer likes crashing us by sending "Content-Length: 9999999999999999" |
| 241 | if (ContentLength > 1 << 30) { // 1024M |
| 242 | elog("Refusing to read message with long Content-Length: {0}. " |
| 243 | "Expect protocol errors", |
| 244 | ContentLength); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 245 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 246 | } |
| 247 | if (ContentLength == 0) { |
| 248 | log("Warning: Missing Content-Length header, or zero-length message."); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 249 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | std::string JSON(ContentLength, '\0'); |
| 253 | for (size_t Pos = 0, Read; Pos < ContentLength; Pos += Read) { |
| 254 | // Handle EINTR which is sent when a debugger attaches on some platforms. |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 255 | Read = retryAfterSignalUnlessShutdown(0, [&]{ |
| 256 | return std::fread(&JSON[Pos], 1, ContentLength - Pos, In); |
| 257 | }); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 258 | if (Read == 0) { |
| 259 | elog("Input was aborted. Read only {0} bytes of expected {1}.", Pos, |
| 260 | ContentLength); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 261 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 262 | } |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 263 | InMirror << llvm::StringRef(&JSON[Pos], Read); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 264 | clearerr(In); // If we're done, the error was transient. If we're not done, |
| 265 | // either it was transient or we'll see it again on retry. |
| 266 | Pos += Read; |
| 267 | } |
| 268 | return std::move(JSON); |
| 269 | } |
| 270 | |
| 271 | // For lit tests we support a simplified syntax: |
| 272 | // - messages are delimited by '---' on a line by itself |
| 273 | // - lines starting with # are ignored. |
| 274 | // This is a testing path, so favor simplicity over performance here. |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 275 | // When returning None, feof(), ferror(), or shutdownRequested() will be set. |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 276 | llvm::Optional<std::string> JSONTransport::readDelimitedMessage() { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 277 | std::string JSON; |
| 278 | std::string Line; |
| 279 | while (readLine(In, Line)) { |
| 280 | InMirror << Line; |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 281 | auto LineRef = llvm::StringRef(Line).trim(); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 282 | if (LineRef.startswith("#")) // comment |
| 283 | continue; |
| 284 | |
| 285 | // found a delimiter |
| 286 | if (LineRef.rtrim() == "---") |
| 287 | break; |
| 288 | |
| 289 | JSON += Line; |
| 290 | } |
| 291 | |
Sam McCall | 19ac0eaf | 2019-11-25 19:51:07 +0100 | [diff] [blame] | 292 | if (shutdownRequested()) |
| 293 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 294 | if (ferror(In)) { |
| 295 | elog("Input error while reading message!"); |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 296 | return llvm::None; |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 297 | } |
| 298 | return std::move(JSON); // Including at EOF |
| 299 | } |
| 300 | |
| 301 | } // namespace |
| 302 | |
Ilya Biryukov | f2001aa | 2019-01-07 15:45:19 +0000 | [diff] [blame] | 303 | std::unique_ptr<Transport> newJSONTransport(std::FILE *In, |
| 304 | llvm::raw_ostream &Out, |
| 305 | llvm::raw_ostream *InMirror, |
| 306 | bool Pretty, |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 307 | JSONStreamStyle Style) { |
Jonas Devlieghere | 1c705d9 | 2019-08-14 23:52:23 +0000 | [diff] [blame] | 308 | return std::make_unique<JSONTransport>(In, Out, InMirror, Pretty, Style); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | } // namespace clangd |
| 312 | } // namespace clang |