[clangd] New conventions for JSON-marshalling functions, centralize machinery
Summary:
- JSON<->Obj interface is now ADL functions, so they play nicely with enums
- recursive vector/map parsing and ObjectMapper moved to JSONExpr and tested
- renamed (un)parse to (de)serialize, since text -> JSON is called parse
- Protocol.cpp gets a bit shorter
Sorry for the giant patch, it's prety mechanical though
Reviewers: ilya-biryukov
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D40596
llvm-svn: 319478
diff --git a/clang-tools-extra/clangd/ProtocolHandlers.cpp b/clang-tools-extra/clangd/ProtocolHandlers.cpp
index ff7dae2..3d52dfc 100644
--- a/clang-tools-extra/clangd/ProtocolHandlers.cpp
+++ b/clang-tools-extra/clangd/ProtocolHandlers.cpp
@@ -21,7 +21,7 @@
// Helper for attaching ProtocolCallbacks methods to a JSONRPCDispatcher.
// Invoke like: Registerer("foo", &ProtocolCallbacks::onFoo)
// onFoo should be: void onFoo(Ctx &C, FooParams &Params)
-// FooParams should have a static factory method: parse(const json::Expr&).
+// FooParams should have a fromJSON function.
struct HandlerRegisterer {
template <typename Param>
void operator()(StringRef Method,
@@ -31,11 +31,9 @@
auto *Callbacks = this->Callbacks;
Dispatcher.registerHandler(
Method, [=](RequestContext C, const json::Expr &RawParams) {
- if (auto P = [&] {
- trace::Span Tracer("Parse");
- return std::decay<Param>::type::parse(RawParams);
- }()) {
- (Callbacks->*Handler)(std::move(C), *P);
+ typename std::remove_reference<Param>::type P;
+ if (fromJSON(RawParams, P)) {
+ (Callbacks->*Handler)(std::move(C), P);
} else {
Out->log("Failed to decode " + Method + " request.\n");
}