summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
diff options
context:
space:
mode:
authorKadir Cetinkaya <kadircet@google.com>2018-08-24 13:09:41 +0000
committerKadir Cetinkaya <kadircet@google.com>2018-08-24 13:09:41 +0000
commit689bf93b2ff10ee1d94249274353bb819618a16d (patch)
tree935ff3b9f11d8e9f359ad8ddbc859530965f36e8 /clang-tools-extra/clangd/JSONRPCDispatcher.cpp
parent406f1ff1cdfe3ef065a3ac3414ff1672dcfb9049 (diff)
downloadbcm5719-llvm-689bf93b2ff10ee1d94249274353bb819618a16d.tar.gz
bcm5719-llvm-689bf93b2ff10ee1d94249274353bb819618a16d.zip
[clangd] Initial cancellation mechanism for LSP requests.
Reviewers: ilya-biryukov, ioeric, hokein Reviewed By: ilya-biryukov Subscribers: mgorny, ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50502 llvm-svn: 340607
Diffstat (limited to 'clang-tools-extra/clangd/JSONRPCDispatcher.cpp')
-rw-r--r--clang-tools-extra/clangd/JSONRPCDispatcher.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
index 2741c665093..9dea83ae896 100644
--- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
+++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "JSONRPCDispatcher.h"
+#include "Cancellation.h"
#include "ProtocolHandlers.h"
#include "Trace.h"
#include "llvm/ADT/SmallString.h"
@@ -93,7 +94,7 @@ void JSONOutput::mirrorInput(const Twine &Message) {
}
void clangd::reply(json::Value &&Result) {
- auto ID = Context::current().get(RequestID);
+ auto ID = getRequestId();
if (!ID) {
elog("Attempted to reply to a notification!");
return;
@@ -116,7 +117,7 @@ void clangd::replyError(ErrorCode Code, const llvm::StringRef &Message) {
{"message", Message.str()}};
});
- if (auto ID = Context::current().get(RequestID)) {
+ if (auto ID = getRequestId()) {
log("--> reply({0}) error: {1}", *ID, Message);
Context::current()
.getExisting(RequestOut)
@@ -129,6 +130,16 @@ void clangd::replyError(ErrorCode Code, const llvm::StringRef &Message) {
}
}
+void clangd::replyError(Error E) {
+ handleAllErrors(std::move(E),
+ [](const CancelledError &TCE) {
+ replyError(ErrorCode::RequestCancelled, TCE.message());
+ },
+ [](const ErrorInfoBase &EIB) {
+ replyError(ErrorCode::InvalidParams, EIB.message());
+ });
+}
+
void clangd::call(StringRef Method, json::Value &&Params) {
RequestSpan::attach([&](json::Object &Args) {
Args["Call"] = json::Object{{"method", Method.str()}, {"params", Params}};
@@ -366,3 +377,7 @@ void clangd::runLanguageServerLoop(std::FILE *In, JSONOutput &Out,
}
}
}
+
+const json::Value *clangd::getRequestId() {
+ return Context::current().get(RequestID);
+}
OpenPOWER on IntegriCloud