[clang-tools-extra] r319497 - [clangd] Logger implicitly adds newline

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 30 15:21:34 PST 2017


Author: sammccall
Date: Thu Nov 30 15:21:34 2017
New Revision: 319497

URL: http://llvm.org/viewvc/llvm-project?rev=319497&view=rev
Log:
[clangd] Logger implicitly adds newline

Modified:
    clang-tools-extra/trunk/clangd/ClangdUnit.cpp
    clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
    clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=319497&r1=319496&r2=319497&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Nov 30 15:21:34 2017
@@ -1151,7 +1151,7 @@ CppFile::CppFile(PathRef FileName, tooli
       RebuildInProgress(false), PCHs(std::move(PCHs)), Logger(Logger) {
   Logger.log("Opened file " + FileName + " with command [" +
              this->Command.Directory + "] " +
-             llvm::join(this->Command.CommandLine, " ") + "\n");
+             llvm::join(this->Command.CommandLine, " "));
 
   std::lock_guard<std::mutex> Lock(Mutex);
   LatestAvailablePreamble = nullptr;

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=319497&r1=319496&r2=319497&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Thu Nov 30 15:21:34 2017
@@ -100,8 +100,7 @@ DirectoryBasedGlobalCompilationDatabase:
         tryLoadDatabaseFromPath(CompileCommandsDir.getValue());
     if (ReturnValue == nullptr)
       Logger.log("Failed to find compilation database for " + Twine(File) +
-                 "in overriden directory " + CompileCommandsDir.getValue() +
-                 "\n");
+                 "in overriden directory " + CompileCommandsDir.getValue());
     return ReturnValue;
   }
 
@@ -114,7 +113,7 @@ DirectoryBasedGlobalCompilationDatabase:
     return CDB;
   }
 
-  Logger.log("Failed to find compilation database for " + Twine(File) + "\n");
+  Logger.log("Failed to find compilation database for " + Twine(File));
   return nullptr;
 }
 

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=319497&r1=319496&r2=319497&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Thu Nov 30 15:21:34 2017
@@ -41,7 +41,7 @@ void JSONOutput::writeMessage(const json
 void JSONOutput::log(const Twine &Message) {
   trace::log(Message);
   std::lock_guard<std::mutex> Guard(StreamMutex);
-  Logs << Message;
+  Logs << Message << '\n';
   Logs.flush();
 }
 
@@ -55,7 +55,7 @@ void JSONOutput::mirrorInput(const Twine
 
 void RequestContext::reply(json::Expr &&Result) {
   if (!ID) {
-    Out.log("Attempted to reply to a notification!\n");
+    Out.log("Attempted to reply to a notification!");
     return;
   }
   SPAN_ATTACH(tracer(), "Reply", Result);
@@ -68,7 +68,7 @@ void RequestContext::reply(json::Expr &&
 
 void RequestContext::replyError(ErrorCode code,
                                 const llvm::StringRef &Message) {
-  Out.log("Error " + Twine(static_cast<int>(code)) + ": " + Message + "\n");
+  Out.log("Error " + Twine(static_cast<int>(code)) + ": " + Message);
   SPAN_ATTACH(tracer(), "Error",
               (json::obj{{"code", static_cast<int>(code)},
                          {"message", Message.str()}}));
@@ -166,7 +166,7 @@ void clangd::runLanguageServerLoop(std::
         if (ContentLength != 0) {
           Out.log("Warning: Duplicate Content-Length header received. "
                   "The previous value for this message (" +
-                  std::to_string(ContentLength) + ") was ignored.\n");
+                  std::to_string(ContentLength) + ") was ignored.");
         }
 
         llvm::getAsUnsignedInteger(LineRef.trim(), 0, ContentLength);
@@ -186,7 +186,7 @@ void clangd::runLanguageServerLoop(std::
     if (ContentLength > 1 << 30) { // 1024M
       In.ignore(ContentLength);
       Out.log("Skipped overly large message of " + Twine(ContentLength) +
-              " bytes.\n");
+              " bytes.");
       continue;
     }
 
@@ -202,7 +202,7 @@ void clangd::runLanguageServerLoop(std::
         if (!In) {
           Out.log("Input was aborted. Read only " +
                   std::to_string(In.gcount()) + " bytes of expected " +
-                  std::to_string(ContentLength) + ".\n");
+                  std::to_string(ContentLength) + ".");
           break;
         }
 
@@ -211,15 +211,15 @@ void clangd::runLanguageServerLoop(std::
 
       if (auto Doc = json::parse(JSONRef)) {
         // Log the formatted message.
-        Out.log(llvm::formatv(Out.Pretty ? "<-- {0:2}\n" : "<-- {0}\n", *Doc));
+        Out.log(llvm::formatv(Out.Pretty ? "<-- {0:2}" : "<-- {0}", *Doc));
         // Finally, execute the action for this JSON message.
         if (!Dispatcher.call(*Doc, Out))
-          Out.log("JSON dispatch failed!\n");
+          Out.log("JSON dispatch failed!");
       } else {
         // Parse error. Log the raw message.
-        Out.log("<-- " + JSONRef + "\n");
+        Out.log("<-- " + JSONRef);
         Out.log(llvm::Twine("JSON parse error: ") +
-                llvm::toString(Doc.takeError()) + "\n");
+                llvm::toString(Doc.takeError()));
       }
 
       // If we're done, exit the loop.
@@ -227,7 +227,7 @@ void clangd::runLanguageServerLoop(std::
         break;
     } else {
       Out.log("Warning: Missing Content-Length header, or message has zero "
-              "length.\n");
+              "length.");
     }
   }
 }

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=319497&r1=319496&r2=319497&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Thu Nov 30 15:21:34 2017
@@ -34,8 +34,7 @@ public:
   /// Emit a JSONRPC message.
   void writeMessage(const json::Expr &Result);
 
-  /// Write to the logging stream.
-  /// No newline is implicitly added. (TODO: we should fix this!)
+  /// Write a line to the logging stream.
   void log(const Twine &Message) override;
 
   /// Mirror \p Message into InputMirror stream. Does nothing if InputMirror is

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=319497&r1=319496&r2=319497&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Thu Nov 30 15:21:34 2017
@@ -35,7 +35,7 @@ struct HandlerRegisterer {
           if (fromJSON(RawParams, P)) {
             (Callbacks->*Handler)(std::move(C), P);
           } else {
-            Out->log("Failed to decode " + Method + " request.\n");
+            Out->log("Failed to decode " + Method + " request.");
           }
         });
   }




More information about the cfe-commits mailing list