<div dir="ltr">Missed that, will do, thanks.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 11, 2017 at 1:39 AM, Bruno Cardoso Lopes <span dir="ltr"><<a href="mailto:bruno.cardoso@gmail.com" target="_blank">bruno.cardoso@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Oct 10, 2017 at 2:08 AM, Ilya Biryukov via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: ibiryukov<br>
> Date: Tue Oct 10 02:08:47 2017<br>
> New Revision: 315287<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=315287&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=315287&view=rev</a><br>
> Log:<br>
> Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"<br>
><br>
> This reverts commit r315242 and restores r315214.<br>
><br>
> To fix original failure, replaced non-portable `diff -Z` with portable<br>
> alternative: `diff -b`.<br>
><br>
> Added:<br>
>     clang-tools-extra/trunk/test/<wbr>clangd/input-mirror.test<br>
> Modified:<br>
>     clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.cpp<br>
>     clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.h<br>
>     clang-tools-extra/trunk/<wbr>clangd/tool/ClangdMain.cpp<br>
><br>
> Modified: clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=315287&r1=315286&r2=315287&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clangd/<wbr>JSONRPCDispatcher.cpp?rev=<wbr>315287&r1=315286&r2=315287&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.cpp (original)<br>
> +++ clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.cpp Tue Oct 10 02:08:47 2017<br>
> @@ -37,6 +37,14 @@ void JSONOutput::log(const Twine &Messag<br>
>    Logs.flush();<br>
>  }<br>
><br>
> +void JSONOutput::mirrorInput(const Twine &Message) {<br>
> +  if (!InputMirror)<br>
> +    return;<br>
> +<br>
> +  *InputMirror << Message;<br>
> +  InputMirror->flush();<br>
> +}<br>
> +<br>
>  void Handler::handleMethod(llvm::<wbr>yaml::MappingNode *Params, StringRef ID) {<br>
>    Output.log("Method ignored.\n");<br>
>    // Return that this method is unsupported.<br>
> @@ -147,6 +155,14 @@ void clangd::runLanguageServerLoop(<wbr>std::<br>
>          continue;<br>
>        }<br>
><br>
> +      Out.mirrorInput(Line);<br>
> +      // Mirror '\n' that gets consumed by std::getline, but is not included in<br>
> +      // the resulting Line.<br>
> +      // Note that '\r' is part of Line, so we don't need to mirror it<br>
> +      // separately.<br>
> +      if (!In.eof())<br>
> +        Out.mirrorInput("\n");<br>
> +<br>
>        llvm::StringRef LineRef(Line);<br>
><br>
>        // We allow YAML-style comments in headers. Technically this isn't part<br>
> @@ -163,9 +179,8 @@ void clangd::runLanguageServerLoop(<wbr>std::<br>
>        if (LineRef.consume_front("<wbr>Content-Length: ")) {<br>
>          if (ContentLength != 0) {<br>
>            Out.log("Warning: Duplicate Content-Length header received. "<br>
> -                  "The previous value for this message ("<br>
> -                  + std::to_string(ContentLength)<br>
> -                  + ") was ignored.\n");<br>
> +                  "The previous value for this message (" +<br>
> +                  std::to_string(ContentLength) + ") was ignored.\n");<br>
>          }<br>
><br>
>          llvm::getAsUnsignedInteger(<wbr>LineRef.trim(), 0, ContentLength);<br>
> @@ -185,15 +200,13 @@ void clangd::runLanguageServerLoop(<wbr>std::<br>
>        // parser.<br>
>        std::vector<char> JSON(ContentLength + 1, '\0');<br>
>        In.read(JSON.data(), ContentLength);<br>
> +      Out.mirrorInput(StringRef(<wbr>JSON.data(), In.gcount()));<br>
><br>
>        // If the stream is aborted before we read ContentLength bytes, In<br>
>        // will have eofbit and failbit set.<br>
>        if (!In) {<br>
> -        Out.log("Input was aborted. Read only "<br>
> -                + std::to_string(In.gcount())<br>
> -                + " bytes of expected "<br>
> -                + std::to_string(ContentLength)<br>
> -                + ".\n");<br>
> +        Out.log("Input was aborted. Read only " + std::to_string(In.gcount()) +<br>
> +                " bytes of expected " + std::to_string(ContentLength) + ".\n");<br>
>          break;<br>
>        }<br>
><br>
> @@ -209,8 +222,8 @@ void clangd::runLanguageServerLoop(<wbr>std::<br>
>        if (IsDone)<br>
>          break;<br>
>      } else {<br>
> -      Out.log( "Warning: Missing Content-Length header, or message has zero "<br>
> -               "length.\n" );<br>
> +      Out.log("Warning: Missing Content-Length header, or message has zero "<br>
> +              "length.\n");<br>
>      }<br>
>    }<br>
>  }<br>
><br>
> Modified: clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=315287&r1=315286&r2=315287&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clangd/<wbr>JSONRPCDispatcher.h?rev=<wbr>315287&r1=315286&r2=315287&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.h (original)<br>
> +++ clang-tools-extra/trunk/<wbr>clangd/JSONRPCDispatcher.h Tue Oct 10 02:08:47 2017<br>
> @@ -24,8 +24,9 @@ namespace clangd {<br>
>  /// them.<br>
>  class JSONOutput : public Logger {<br>
>  public:<br>
> -  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs)<br>
> -      : Outs(Outs), Logs(Logs) {}<br>
> +  JSONOutput(llvm::raw_ostream &Outs, llvm::raw_ostream &Logs,<br>
> +             llvm::raw_ostream *InputMirror = nullptr)<br>
> +      : Outs(Outs), Logs(Logs), InputMirror(InputMirror) {}<br>
><br>
>    /// Emit a JSONRPC message.<br>
>    void writeMessage(const Twine &Message);<br>
> @@ -33,9 +34,15 @@ public:<br>
>    /// Write to the logging stream.<br>
>    void log(const Twine &Message) override;<br>
><br>
> +  /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is<br>
> +  /// null.<br>
> +  /// Unlike other methods of JSONOutput, mirrorInput is not thread-safe.<br>
> +  void mirrorInput(const Twine &Message);<br>
> +<br>
>  private:<br>
>    llvm::raw_ostream &Outs;<br>
>    llvm::raw_ostream &Logs;<br>
> +  llvm::raw_ostream *InputMirror;<br>
><br>
>    std::mutex StreamMutex;<br>
>  };<br>
><br>
> Modified: clang-tools-extra/trunk/<wbr>clangd/tool/ClangdMain.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=315287&r1=315286&r2=315287&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clangd/tool/ClangdMain.<wbr>cpp?rev=315287&r1=315286&r2=<wbr>315287&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/<wbr>clangd/tool/ClangdMain.cpp (original)<br>
> +++ clang-tools-extra/trunk/<wbr>clangd/tool/ClangdMain.cpp Tue Oct 10 02:08:47 2017<br>
> @@ -9,10 +9,12 @@<br>
><br>
>  #include "ClangdLSPServer.h"<br>
>  #include "JSONRPCDispatcher.h"<br>
> +#include "Path.h"<br>
>  #include "llvm/Support/CommandLine.h"<br>
>  #include "llvm/Support/FileSystem.h"<br>
>  #include "llvm/Support/Path.h"<br>
>  #include "llvm/Support/Program.h"<br>
> +#include "llvm/Support/raw_ostream.h"<br>
>  #include <iostream><br>
>  #include <memory><br>
>  #include <string><br>
> @@ -43,11 +45,17 @@ static llvm::cl::opt<bool> RunSynchronou<br>
>      llvm::cl::desc("Parse on main thread. If set, -j is ignored"),<br>
>      llvm::cl::init(false), llvm::cl::Hidden);<br>
><br>
> -static llvm::cl::opt<std::string><br>
> +static llvm::cl::opt<Path><br>
>      ResourceDir("resource-dir",<br>
>                  llvm::cl::desc("Directory for system clang headers"),<br>
>                  llvm::cl::init(""), llvm::cl::Hidden);<br>
><br>
> +static llvm::cl::opt<Path> InputMirrorFile(<br>
> +    "input-mirror-file",<br>
> +    llvm::cl::desc(<br>
> +        "Mirror all LSP input to the specified file. Useful for debugging."),<br>
> +    llvm::cl::init(""), llvm::cl::Hidden);<br>
> +<br>
>  int main(int argc, char *argv[]) {<br>
>    llvm::cl::<wbr>ParseCommandLineOptions(argc, argv, "clangd");<br>
><br>
> @@ -63,9 +71,21 @@ int main(int argc, char *argv[]) {<br>
>      WorkerThreadsCount = 0;<br>
><br>
>    /// Validate command line arguments.<br>
> +  llvm::Optional<llvm::raw_fd_<wbr>ostream> InputMirrorStream;<br>
> +  if (!InputMirrorFile.empty()) {<br>
> +    std::error_code EC;<br>
> +    InputMirrorStream.emplace(<wbr>InputMirrorFile, /*ref*/ EC, llvm::sys::fs::F_RW);<br>
> +    if (EC) {<br>
> +      InputMirrorStream.reset();<br>
> +      llvm::errs() << "Error while opening an input mirror file: "<br>
> +                   << EC.message();<br>
> +    }<br>
> +  }<br>
> +<br>
>    llvm::raw_ostream &Outs = llvm::outs();<br>
>    llvm::raw_ostream &Logs = llvm::errs();<br>
> -  JSONOutput Out(Outs, Logs);<br>
> +  JSONOutput Out(Outs, Logs,<br>
> +                 InputMirrorStream ? InputMirrorStream.getPointer() : nullptr);<br>
><br>
>    // If --compile-commands-dir arg was invoked, check value and override default<br>
>    // path.<br>
><br>
> Added: clang-tools-extra/trunk/test/<wbr>clangd/input-mirror.test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/input-mirror.test?rev=315287&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/test/clangd/input-<wbr>mirror.test?rev=315287&view=<wbr>auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- clang-tools-extra/trunk/test/<wbr>clangd/input-mirror.test (added)<br>
> +++ clang-tools-extra/trunk/test/<wbr>clangd/input-mirror.test Tue Oct 10 02:08:47 2017<br>
> @@ -0,0 +1,154 @@<br>
> +# RUN: clangd -run-synchronously -input-mirror-file %t < %s<br>
> +# Note that we have to use '-Z' as -input-mirror-file does not have a newline at the end of file.<br>
<br>
</div></div>Maybe also update the comment above?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Bruno Cardoso Lopes<br>
<a href="http://www.brunocardoso.cc" rel="noreferrer" target="_blank">http://www.brunocardoso.cc</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>
</div>