[PATCH] D45763: [clangd][tests] Fix handling of EOF in delimited input

Jan Korous via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 19 06:05:29 PDT 2018


jkorous updated this revision to Diff 143079.
jkorous added a comment.

Include the correct test.


https://reviews.llvm.org/D45763

Files:
  JSONRPCDispatcher.cpp
  clangd/delimited-input-comment-at-the-end.test


Index: clangd/delimited-input-comment-at-the-end.test
===================================================================
--- /dev/null
+++ clangd/delimited-input-comment-at-the-end.test
@@ -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
Index: JSONRPCDispatcher.cpp
===================================================================
--- JSONRPCDispatcher.cpp
+++ JSONRPCDispatcher.cpp
@@ -277,21 +277,19 @@
     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);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45763.143079.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180419/192b2f4c/attachment.bin>


More information about the cfe-commits mailing list