jkorous created this revision.
jkorous added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, MaskRay, ioeric, jkorous-apple,
ilya-biryukov.
Request in delimited input ended by EOF shouldn't be an error state.
Comments should be allowed at the end of test files.
Input mirroring should work for the last request in delimited test file.
Repository:
rCTE Clang Tools Extra
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,7 @@
+# RUN: clangd -input-style=delimited -run-synchronously < %s 2>&1 | FileCheck
%s
+# RUN: clangd -lit-test -run-synchronously < %s 2>&1 | FileCheck %s
+#
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"exit"}
+# CHECK-NOT: Input message terminated by EOF
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);
}
}
Index: clangd/delimited-input-comment-at-the-end.test
===================================================================
--- /dev/null
+++ clangd/delimited-input-comment-at-the-end.test
@@ -0,0 +1,7 @@
+# RUN: clangd -input-style=delimited -run-synchronously < %s 2>&1 | FileCheck %s
+# RUN: clangd -lit-test -run-synchronously < %s 2>&1 | FileCheck %s
+#
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"exit"}
+# CHECK-NOT: Input message terminated by EOF
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);
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits