[clangd][NFC] Simplify handing on methods with no params
Add bind methods handling the case when a method has an empty params interface and when it has no parameters. Remove ShutdownParams and ExitParams from Protocol, In LSP they aren't defined, instead the methods are defined to have void as the params. This signature now better reflects that. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D95270
This commit is contained in:
parent
239cfbccb0
commit
f05b492aae
@ -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
|
// Bind a reply callback to a request. The callback will be invoked when
|
||||||
// clangd receives the reply from the LSP client.
|
// clangd receives the reply from the LSP client.
|
||||||
// Return a call id of the request.
|
// Return a call id of the request.
|
||||||
@ -301,6 +310,20 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
|
||||||
|
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
|
||||||
|
(Server.*Handler)();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void bind<NoParams>(const char *Method,
|
||||||
|
void (ClangdLSPServer::*Handler)(const NoParams &)) {
|
||||||
|
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
|
||||||
|
(Server.*Handler)(NoParams{});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Function object to reply to an LSP call.
|
// Function object to reply to an LSP call.
|
||||||
// Each instance must be called exactly once, otherwise:
|
// Each instance must be called exactly once, otherwise:
|
||||||
@ -647,8 +670,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
|
|||||||
|
|
||||||
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
|
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
|
||||||
|
|
||||||
void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
|
void ClangdLSPServer::onShutdown(Callback<std::nullptr_t> Reply) {
|
||||||
Callback<std::nullptr_t> Reply) {
|
|
||||||
// Do essentially nothing, just say we're ready to exit.
|
// Do essentially nothing, just say we're ready to exit.
|
||||||
ShutdownRequestReceived = true;
|
ShutdownRequestReceived = true;
|
||||||
Reply(nullptr);
|
Reply(nullptr);
|
||||||
@ -656,8 +678,7 @@ void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
|
|||||||
|
|
||||||
// sync is a clangd extension: it blocks until all background work completes.
|
// 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!
|
// It blocks the calling thread, so no messages are processed until it returns!
|
||||||
void ClangdLSPServer::onSync(const NoParams &Params,
|
void ClangdLSPServer::onSync(Callback<std::nullptr_t> Reply) {
|
||||||
Callback<std::nullptr_t> Reply) {
|
|
||||||
if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
|
if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
|
||||||
Reply(nullptr);
|
Reply(nullptr);
|
||||||
else
|
else
|
||||||
@ -1445,8 +1466,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdLSPServer::onMemoryUsage(const NoParams &,
|
void ClangdLSPServer::onMemoryUsage(Callback<MemoryTree> Reply) {
|
||||||
Callback<MemoryTree> Reply) {
|
|
||||||
llvm::BumpPtrAllocator DetailAlloc;
|
llvm::BumpPtrAllocator DetailAlloc;
|
||||||
MemoryTree MT(&DetailAlloc);
|
MemoryTree MT(&DetailAlloc);
|
||||||
profile(MT);
|
profile(MT);
|
||||||
|
@ -93,8 +93,8 @@ private:
|
|||||||
// Calls have signature void(const Params&, Callback<Response>).
|
// Calls have signature void(const Params&, Callback<Response>).
|
||||||
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
|
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
|
||||||
void onInitialized(const InitializedParams &);
|
void onInitialized(const InitializedParams &);
|
||||||
void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
|
void onShutdown(Callback<std::nullptr_t>);
|
||||||
void onSync(const NoParams &, Callback<std::nullptr_t>);
|
void onSync(Callback<std::nullptr_t>);
|
||||||
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
|
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
|
||||||
void onDocumentDidChange(const DidChangeTextDocumentParams &);
|
void onDocumentDidChange(const DidChangeTextDocumentParams &);
|
||||||
void onDocumentDidClose(const DidCloseTextDocumentParams &);
|
void onDocumentDidClose(const DidCloseTextDocumentParams &);
|
||||||
@ -161,7 +161,7 @@ private:
|
|||||||
Callback<SemanticTokensOrDelta>);
|
Callback<SemanticTokensOrDelta>);
|
||||||
/// This is a clangd extension. Provides a json tree representing memory usage
|
/// This is a clangd extension. Provides a json tree representing memory usage
|
||||||
/// hierarchy.
|
/// hierarchy.
|
||||||
void onMemoryUsage(const NoParams &, Callback<MemoryTree>);
|
void onMemoryUsage(Callback<MemoryTree>);
|
||||||
|
|
||||||
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
|
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
|
||||||
|
|
||||||
|
@ -265,8 +265,6 @@ inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
using InitializedParams = NoParams;
|
using InitializedParams = NoParams;
|
||||||
using ShutdownParams = NoParams;
|
|
||||||
using ExitParams = NoParams;
|
|
||||||
|
|
||||||
/// Defines how the host (editor) should sync document changes to the language
|
/// Defines how the host (editor) should sync document changes to the language
|
||||||
/// server.
|
/// server.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user