@@ -258,6 +258,15 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
258
258
};
259
259
}
260
260
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
+
261
270
// Bind a reply callback to a request. The callback will be invoked when
262
271
// clangd receives the reply from the LSP client.
263
272
// Return a call id of the request.
@@ -301,6 +310,12 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
301
310
};
302
311
}
303
312
313
+ void bind (const char *Method, void (ClangdLSPServer::*Handler)()) {
314
+ Notifications[Method] = [Handler, this ](llvm::json::Value RawParams) {
315
+ (Server.*Handler)();
316
+ };
317
+ }
318
+
304
319
private:
305
320
// Function object to reply to an LSP call.
306
321
// Each instance must be called exactly once, otherwise:
@@ -443,6 +458,14 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
443
458
};
444
459
constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
445
460
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
+
446
469
// call(), notify(), and reply() wrap the Transport, adding logging and locking.
447
470
void ClangdLSPServer::callRaw (StringRef Method, llvm::json::Value Params,
448
471
Callback<llvm::json::Value> CB) {
@@ -647,17 +670,15 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
647
670
648
671
void ClangdLSPServer::onInitialized (const InitializedParams &Params) {}
649
672
650
- void ClangdLSPServer::onShutdown (const ShutdownParams &Params,
651
- Callback<std::nullptr_t > Reply) {
673
+ void ClangdLSPServer::onShutdown (Callback<std::nullptr_t > Reply) {
652
674
// Do essentially nothing, just say we're ready to exit.
653
675
ShutdownRequestReceived = true ;
654
676
Reply (nullptr );
655
677
}
656
678
657
679
// sync is a clangd extension: it blocks until all background work completes.
658
680
// 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) {
661
682
if (Server->blockUntilIdleForTest (/* TimeoutSeconds=*/ 60 ))
662
683
Reply (nullptr );
663
684
else
@@ -1445,8 +1466,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
1445
1466
});
1446
1467
}
1447
1468
1448
- void ClangdLSPServer::onMemoryUsage (const NoParams &,
1449
- Callback<MemoryTree> Reply) {
1469
+ void ClangdLSPServer::onMemoryUsage (Callback<MemoryTree> Reply) {
1450
1470
llvm::BumpPtrAllocator DetailAlloc;
1451
1471
MemoryTree MT (&DetailAlloc);
1452
1472
profile (MT);
0 commit comments