OSDN Git Service

Reland"[clangd][NFC] Simplify handing on methods with no params"
authorNathan James <n.james93@hotmail.co.uk>
Mon, 25 Jan 2021 20:19:50 +0000 (20:19 +0000)
committerNathan James <n.james93@hotmail.co.uk>
Mon, 25 Jan 2021 20:19:57 +0000 (20:19 +0000)
This reverts commit 9d9ceb37453ffe0186d04f4e9e4ba9fb41200b57.

First time round caused some build bot failures due to older compilers not patched with the Defect Report about full specialization being allowed at class scope.

clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/Protocol.h

index 24d3a35..abfb1b2 100644 (file)
@@ -258,6 +258,15 @@ public:
     };
   }
 
+  template <typename Result>
+  void bind(const char *Method,
+            void (ClangdLSPServer::*Handler)(Callback<Result>)) {
+    Calls[Method] = [Handler, this](llvm::json::Value RawParams,
+                                    ReplyOnce Reply) {
+      (Server.*Handler)(std::move(Reply));
+    };
+  }
+
   // Bind a reply callback to a request. The callback will be invoked when
   // clangd receives the reply from the LSP client.
   // Return a call id of the request.
@@ -301,6 +310,12 @@ public:
     };
   }
 
+  void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
+    Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
+      (Server.*Handler)();
+    };
+  }
+
 private:
   // Function object to reply to an LSP call.
   // Each instance must be called exactly once, otherwise:
@@ -443,6 +458,14 @@ private:
 };
 constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
 
+template <>
+void ClangdLSPServer::MessageHandler::bind<NoParams>(
+    const char *Method, void (ClangdLSPServer::*Handler)(const NoParams &)) {
+  Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
+    (Server.*Handler)(NoParams{});
+  };
+}
+
 // call(), notify(), and reply() wrap the Transport, adding logging and locking.
 void ClangdLSPServer::callRaw(StringRef Method, llvm::json::Value Params,
                               Callback<llvm::json::Value> CB) {
@@ -647,8 +670,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
 
 void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
 
-void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
-                                 Callback<std::nullptr_t> Reply) {
+void ClangdLSPServer::onShutdown(Callback<std::nullptr_t> Reply) {
   // Do essentially nothing, just say we're ready to exit.
   ShutdownRequestReceived = true;
   Reply(nullptr);
@@ -656,8 +678,7 @@ void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
 
 // sync is a clangd extension: it blocks until all background work completes.
 // It blocks the calling thread, so no messages are processed until it returns!
-void ClangdLSPServer::onSync(const NoParams &Params,
-                             Callback<std::nullptr_t> Reply) {
+void ClangdLSPServer::onSync(Callback<std::nullptr_t> Reply) {
   if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
     Reply(nullptr);
   else
@@ -1445,8 +1466,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
       });
 }
 
-void ClangdLSPServer::onMemoryUsage(const NoParams &,
-                                    Callback<MemoryTree> Reply) {
+void ClangdLSPServer::onMemoryUsage(Callback<MemoryTree> Reply) {
   llvm::BumpPtrAllocator DetailAlloc;
   MemoryTree MT(&DetailAlloc);
   profile(MT);
index 3a46bd7..d8ce2db 100644 (file)
@@ -93,8 +93,8 @@ private:
   // Calls have signature void(const Params&, Callback<Response>).
   void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
   void onInitialized(const InitializedParams &);
-  void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
-  void onSync(const NoParams &, Callback<std::nullptr_t>);
+  void onShutdown(Callback<std::nullptr_t>);
+  void onSync(Callback<std::nullptr_t>);
   void onDocumentDidOpen(const DidOpenTextDocumentParams &);
   void onDocumentDidChange(const DidChangeTextDocumentParams &);
   void onDocumentDidClose(const DidCloseTextDocumentParams &);
@@ -161,7 +161,7 @@ private:
                              Callback<SemanticTokensOrDelta>);
   /// This is a clangd extension. Provides a json tree representing memory usage
   /// hierarchy.
-  void onMemoryUsage(const NoParams &, Callback<MemoryTree>);
+  void onMemoryUsage(Callback<MemoryTree>);
 
   std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
 
index 9f0e50f..43c9568 100644 (file)
@@ -265,8 +265,6 @@ inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
   return true;
 }
 using InitializedParams = NoParams;
-using ShutdownParams = NoParams;
-using ExitParams = NoParams;
 
 /// Defines how the host (editor) should sync document changes to the language
 /// server.