Skip to content

Commit 71af5a1

Browse files
committed
Reland"[clangd][NFC] Simplify handing on methods with no params"
This reverts commit 9d9ceb3. 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.
1 parent 12b34ff commit 71af5a1

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
258258
};
259259
}
260260

261+
template <typename Result>
262+
void bind(const char *Method,
263+
void (ClangdLSPServer::*Handler)(Callback<Result>)) {
264+
Calls[Method] = [Handler, this](llvm::json::Value RawParams,
265+
ReplyOnce Reply) {
266+
(Server.*Handler)(std::move(Reply));
267+
};
268+
}
269+
261270
// Bind a reply callback to a request. The callback will be invoked when
262271
// clangd receives the reply from the LSP client.
263272
// Return a call id of the request.
@@ -301,6 +310,12 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
301310
};
302311
}
303312

313+
void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
314+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
315+
(Server.*Handler)();
316+
};
317+
}
318+
304319
private:
305320
// Function object to reply to an LSP call.
306321
// Each instance must be called exactly once, otherwise:
@@ -443,6 +458,14 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
443458
};
444459
constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
445460

461+
template <>
462+
void ClangdLSPServer::MessageHandler::bind<NoParams>(
463+
const char *Method, void (ClangdLSPServer::*Handler)(const NoParams &)) {
464+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
465+
(Server.*Handler)(NoParams{});
466+
};
467+
}
468+
446469
// call(), notify(), and reply() wrap the Transport, adding logging and locking.
447470
void ClangdLSPServer::callRaw(StringRef Method, llvm::json::Value Params,
448471
Callback<llvm::json::Value> CB) {
@@ -647,17 +670,15 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
647670

648671
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
649672

650-
void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
651-
Callback<std::nullptr_t> Reply) {
673+
void ClangdLSPServer::onShutdown(Callback<std::nullptr_t> Reply) {
652674
// Do essentially nothing, just say we're ready to exit.
653675
ShutdownRequestReceived = true;
654676
Reply(nullptr);
655677
}
656678

657679
// sync is a clangd extension: it blocks until all background work completes.
658680
// It blocks the calling thread, so no messages are processed until it returns!
659-
void ClangdLSPServer::onSync(const NoParams &Params,
660-
Callback<std::nullptr_t> Reply) {
681+
void ClangdLSPServer::onSync(Callback<std::nullptr_t> Reply) {
661682
if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
662683
Reply(nullptr);
663684
else
@@ -1445,8 +1466,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
14451466
});
14461467
}
14471468

1448-
void ClangdLSPServer::onMemoryUsage(const NoParams &,
1449-
Callback<MemoryTree> Reply) {
1469+
void ClangdLSPServer::onMemoryUsage(Callback<MemoryTree> Reply) {
14501470
llvm::BumpPtrAllocator DetailAlloc;
14511471
MemoryTree MT(&DetailAlloc);
14521472
profile(MT);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
9393
// Calls have signature void(const Params&, Callback<Response>).
9494
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
9595
void onInitialized(const InitializedParams &);
96-
void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
97-
void onSync(const NoParams &, Callback<std::nullptr_t>);
96+
void onShutdown(Callback<std::nullptr_t>);
97+
void onSync(Callback<std::nullptr_t>);
9898
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
9999
void onDocumentDidChange(const DidChangeTextDocumentParams &);
100100
void onDocumentDidClose(const DidCloseTextDocumentParams &);
@@ -161,7 +161,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
161161
Callback<SemanticTokensOrDelta>);
162162
/// This is a clangd extension. Provides a json tree representing memory usage
163163
/// hierarchy.
164-
void onMemoryUsage(const NoParams &, Callback<MemoryTree>);
164+
void onMemoryUsage(Callback<MemoryTree>);
165165

166166
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
167167

clang-tools-extra/clangd/Protocol.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
265265
return true;
266266
}
267267
using InitializedParams = NoParams;
268-
using ShutdownParams = NoParams;
269-
using ExitParams = NoParams;
270268

271269
/// Defines how the host (editor) should sync document changes to the language
272270
/// server.

0 commit comments

Comments
 (0)