diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -93,8 +93,8 @@ // Calls have signature void(const Params&, Callback). void onInitialize(const InitializeParams &, Callback); void onInitialized(const InitializedParams &); - void onShutdown(const ShutdownParams &, Callback); - void onSync(const NoParams &, Callback); + void onShutdown(Callback); + void onSync(Callback); void onDocumentDidOpen(const DidOpenTextDocumentParams &); void onDocumentDidChange(const DidChangeTextDocumentParams &); void onDocumentDidClose(const DidCloseTextDocumentParams &); @@ -161,7 +161,7 @@ Callback); /// This is a clangd extension. Provides a json tree representing memory usage /// hierarchy. - void onMemoryUsage(const NoParams &, Callback); + void onMemoryUsage(Callback); std::vector getFixes(StringRef File, const clangd::Diagnostic &D); diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -258,6 +258,15 @@ }; } + template + void bind(const char *Method, + void (ClangdLSPServer::*Handler)(Callback)) { + 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,20 @@ }; } + void bind(const char *Method, void (ClangdLSPServer::*Handler)()) { + Notifications[Method] = [Handler, this](llvm::json::Value RawParams) { + (Server.*Handler)(); + }; + } + + template <> + void bind(const char *Method, + void (ClangdLSPServer::*Handler)(const NoParams &)) { + Notifications[Method] = [Handler, this](llvm::json::Value RawParams) { + (Server.*Handler)(NoParams{}); + }; + } + private: // Function object to reply to an LSP call. // Each instance must be called exactly once, otherwise: @@ -647,8 +670,7 @@ void ClangdLSPServer::onInitialized(const InitializedParams &Params) {} -void ClangdLSPServer::onShutdown(const ShutdownParams &Params, - Callback Reply) { +void ClangdLSPServer::onShutdown(Callback Reply) { // Do essentially nothing, just say we're ready to exit. ShutdownRequestReceived = true; Reply(nullptr); @@ -656,8 +678,7 @@ // 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 Reply) { +void ClangdLSPServer::onSync(Callback Reply) { if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60)) Reply(nullptr); else @@ -1445,8 +1466,7 @@ }); } -void ClangdLSPServer::onMemoryUsage(const NoParams &, - Callback Reply) { +void ClangdLSPServer::onMemoryUsage(Callback Reply) { llvm::BumpPtrAllocator DetailAlloc; MemoryTree MT(&DetailAlloc); profile(MT); diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -265,8 +265,6 @@ return true; } using InitializedParams = NoParams; -using ShutdownParams = NoParams; -using ExitParams = NoParams; /// Defines how the host (editor) should sync document changes to the language /// server.