Re: [clang-tools-extra] r315287 - Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
Missed that, will do, thanks. On Wed, Oct 11, 2017 at 1:39 AM, Bruno Cardoso Lopes < bruno.card...@gmail.com> wrote: > On Tue, Oct 10, 2017 at 2:08 AM, Ilya Biryukov via cfe-commits >wrote: > > Author: ibiryukov > > Date: Tue Oct 10 02:08:47 2017 > > New Revision: 315287 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=315287=rev > > Log: > > 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`. > > > > Added: > > clang-tools-extra/trunk/test/clangd/input-mirror.test > > Modified: > > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp > > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h > > clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp > > > > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp > > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ > JSONRPCDispatcher.cpp?rev=315287=315286=315287=diff > > > == > > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original) > > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Oct 10 > 02:08:47 2017 > > @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine > >Logs.flush(); > > } > > > > +void JSONOutput::mirrorInput(const Twine ) { > > + 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:: > > 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:: > >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:: > >// parser. > >std::vector 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:: > >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"); > > } > >} > > } > > > > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h > > URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ > JSONRPCDispatcher.h?rev=315287=315286=315287=diff > > > == > > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original) > > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Tue Oct 10 > 02:08:47 2017 > > @@ -24,8 +24,9 @@ namespace clangd { > > /// them. > > class JSONOutput : public Logger { > > public: > > - JSONOutput(llvm::raw_ostream , llvm::raw_ostream ) > > - : Outs(Outs), Logs(Logs) {} > > + JSONOutput(llvm::raw_ostream , llvm::raw_ostream , > > + llvm::raw_ostream *InputMirror = nullptr) > > + :
Re: [clang-tools-extra] r315287 - Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
On Tue, Oct 10, 2017 at 2:08 AM, Ilya Biryukov via cfe-commitswrote: > Author: ibiryukov > Date: Tue Oct 10 02:08:47 2017 > New Revision: 315287 > > URL: http://llvm.org/viewvc/llvm-project?rev=315287=rev > Log: > 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`. > > Added: > clang-tools-extra/trunk/test/clangd/input-mirror.test > Modified: > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp > clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h > clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp > > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp > URL: > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=315287=315286=315287=diff > == > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original) > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Oct 10 02:08:47 > 2017 > @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine >Logs.flush(); > } > > +void JSONOutput::mirrorInput(const Twine ) { > + 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:: > 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:: >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:: >// parser. >std::vector 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:: >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"); > } >} > } > > Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h > URL: > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=315287=315286=315287=diff > == > --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original) > +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Tue Oct 10 02:08:47 > 2017 > @@ -24,8 +24,9 @@ namespace clangd { > /// them. > class JSONOutput : public Logger { > public: > - JSONOutput(llvm::raw_ostream , llvm::raw_ostream ) > - : Outs(Outs), Logs(Logs) {} > + JSONOutput(llvm::raw_ostream , llvm::raw_ostream , > + llvm::raw_ostream *InputMirror = nullptr) > + : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {} > >/// Emit a JSONRPC message. >void writeMessage(const Twine ); > @@ -33,9 +34,15 @@ public: >/// Write to the logging stream. >void log(const Twine ) override; > > + /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror > is > + /// null. > + /// Unlike other methods
[clang-tools-extra] r315287 - Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
Author: ibiryukov Date: Tue Oct 10 02:08:47 2017 New Revision: 315287 URL: http://llvm.org/viewvc/llvm-project?rev=315287=rev Log: 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`. Added: clang-tools-extra/trunk/test/clangd/input-mirror.test Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=315287=315286=315287=diff == --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original) +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue Oct 10 02:08:47 2017 @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine Logs.flush(); } +void JSONOutput::mirrorInput(const Twine ) { + 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:: 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:: 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:: // parser. std::vector 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:: 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"); } } } Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=315287=315286=315287=diff == --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original) +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Tue Oct 10 02:08:47 2017 @@ -24,8 +24,9 @@ namespace clangd { /// them. class JSONOutput : public Logger { public: - JSONOutput(llvm::raw_ostream , llvm::raw_ostream ) - : Outs(Outs), Logs(Logs) {} + JSONOutput(llvm::raw_ostream , llvm::raw_ostream , + llvm::raw_ostream *InputMirror = nullptr) + : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {} /// Emit a JSONRPC message. void writeMessage(const Twine ); @@ -33,9 +34,15 @@ public: /// Write to the logging stream. void log(const Twine ) override; + /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is + /// null. + /// Unlike other methods of JSONOutput, mirrorInput is not thread-safe. + void mirrorInput(const Twine ); + private: llvm::raw_ostream llvm::raw_ostream + llvm::raw_ostream *InputMirror; std::mutex StreamMutex; }; Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp URL: