summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2017-10-10 09:08:47 +0000
committerIlya Biryukov <ibiryukov@google.com>2017-10-10 09:08:47 +0000
commite6dbb58f95c8421a04c77a30c9ce9e43a3be9798 (patch)
treedd7d3c2365d6bb6403e6f7e8dd55251295a88612 /clang-tools-extra/clangd/JSONRPCDispatcher.cpp
parenteac034b992d38eaadd33a9540e0fda6ae059fcd5 (diff)
downloadbcm5719-llvm-e6dbb58f95c8421a04c77a30c9ce9e43a3be9798.tar.gz
bcm5719-llvm-e6dbb58f95c8421a04c77a30c9ce9e43a3be9798.zip
Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
This reverts commit r315242 and restores r315214. To fix original failure, replaced non-portable `diff -Z` with portable alternative: `diff -b`. llvm-svn: 315287
Diffstat (limited to 'clang-tools-extra/clangd/JSONRPCDispatcher.cpp')
-rw-r--r--clang-tools-extra/clangd/JSONRPCDispatcher.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
index 6641aae6a2f..979402c0390 100644
--- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
+++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
@@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Message) {
Logs.flush();
}
+void JSONOutput::mirrorInput(const Twine &Message) {
+ if (!InputMirror)
+ return;
+
+ *InputMirror << Message;
+ InputMirror->flush();
+}
+
void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
Output.log("Method ignored.\n");
// Return that this method is unsupported.
@@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
continue;
}
+ Out.mirrorInput(Line);
+ // Mirror '\n' that gets consumed by std::getline, but is not included in
+ // the resulting Line.
+ // Note that '\r' is part of Line, so we don't need to mirror it
+ // separately.
+ if (!In.eof())
+ Out.mirrorInput("\n");
+
llvm::StringRef LineRef(Line);
// We allow YAML-style comments in headers. Technically this isn't part
@@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
if (LineRef.consume_front("Content-Length: ")) {
if (ContentLength != 0) {
Out.log("Warning: Duplicate Content-Length header received. "
- "The previous value for this message ("
- + std::to_string(ContentLength)
- + ") was ignored.\n");
+ "The previous value for this message (" +
+ std::to_string(ContentLength) + ") was ignored.\n");
}
llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
@@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
// parser.
std::vector<char> JSON(ContentLength + 1, '\0');
In.read(JSON.data(), ContentLength);
+ Out.mirrorInput(StringRef(JSON.data(), In.gcount()));
// If the stream is aborted before we read ContentLength bytes, In
// will have eofbit and failbit set.
if (!In) {
- Out.log("Input was aborted. Read only "
- + std::to_string(In.gcount())
- + " bytes of expected "
- + std::to_string(ContentLength)
- + ".\n");
+ Out.log("Input was aborted. Read only " + std::to_string(In.gcount()) +
+ " bytes of expected " + std::to_string(ContentLength) + ".\n");
break;
}
@@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(std::istream &In, JSONOutput &Out,
if (IsDone)
break;
} else {
- Out.log( "Warning: Missing Content-Length header, or message has zero "
- "length.\n" );
+ Out.log("Warning: Missing Content-Length header, or message has zero "
+ "length.\n");
}
}
}
OpenPOWER on IntegriCloud