[clang-tools-extra] r330608 - [clangd][tests] Fix handling of EOF in delimited input

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 23 08:55:07 PDT 2018


Author: jkorous
Date: Mon Apr 23 08:55:07 2018
New Revision: 330608

URL: http://llvm.org/viewvc/llvm-project?rev=330608&view=rev
Log:
[clangd][tests] Fix handling of EOF in delimited input

Request in delimited input ended by EOF shouldn't be an error state.
Comments at the end of test file shouldn't be logged as an error state.
Input mirroring should work for the last request in delimited test file.

Added:
    clang-tools-extra/trunk/test/clangd/delimited-input-comment-at-the-end.test
Modified:
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=330608&r1=330607&r2=330608&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Mon Apr 23 08:55:07 2018
@@ -277,21 +277,19 @@ static llvm::Optional<std::string> readD
     if (LineRef.startswith("#")) // comment
       continue;
 
-    bool IsDelim = LineRef.find_first_not_of('-') == llvm::StringRef::npos;
-    if (!IsDelim) // Line is part of a JSON message.
-      JSON += Line;
-    if (IsDelim) {
-      Out.mirrorInput(
-          llvm::formatv("Content-Length: {0}\r\n\r\n{1}", JSON.size(), JSON));
-      return std::move(JSON);
-    }
+    // found a delimiter
+    if (LineRef.find_first_not_of('-') == llvm::StringRef::npos)
+      break;
+
+    JSON += Line;
   }
 
   if (In.bad()) {
     log("Input error while reading message!");
     return llvm::None;
   } else {
-    log("Input message terminated by EOF");
+    Out.mirrorInput(
+        llvm::formatv("Content-Length: {0}\r\n\r\n{1}", JSON.size(), JSON));
     return std::move(JSON);
   }
 }

Added: clang-tools-extra/trunk/test/clangd/delimited-input-comment-at-the-end.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/delimited-input-comment-at-the-end.test?rev=330608&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clangd/delimited-input-comment-at-the-end.test (added)
+++ clang-tools-extra/trunk/test/clangd/delimited-input-comment-at-the-end.test Mon Apr 23 08:55:07 2018
@@ -0,0 +1,12 @@
+# RUN: clangd -input-style=delimited -run-synchronously -input-mirror-file %t < %s
+# RUN: grep '{"jsonrpc":"2.0","id":3,"method":"exit"}' %t
+#
+# RUN: clangd -lit-test -input-mirror-file %t < %s
+# RUN: grep '{"jsonrpc":"2.0","id":3,"method":"exit"}' %t
+#
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","id":3,"method":"exit"}
+# comment at the end




More information about the cfe-commits mailing list