6#include <llvm/ADT/FunctionExtras.h>
7#include <llvm/ADT/StringMap.h>
8#include <llvm/Support/JSON.h>
13llvm::Expected<T>
parseParam(
const llvm::json::Value &Raw,
14 llvm::StringRef PayloadName,
15 llvm::StringRef PayloadKind) {
17 llvm::json::Path::Root Root;
19 elog(
"Failed to decode {0} {1}: {2}", PayloadName, PayloadKind,
23 llvm::raw_string_ostream OS(Context);
24 Root.printErrorContext(Raw, OS);
25 vlog(
"{0}", OS.str());
27 return llvm::make_error<LSPError>(
28 llvm::formatv(
"failed to decode {0} {1}: {2}", PayloadName, PayloadKind,
29 fmt_consume(Root.getError())),
32 return std::move(Result);
36inline llvm::Expected<llvm::json::Value>
37parseParam(
const llvm::json::Value &Raw, llvm::StringRef PayloadName,
38 llvm::StringRef PayloadKind) {
43 using JSON = llvm::json::Value;
44 template <
typename HandlerT>
45 using HandlerMap = llvm::StringMap<llvm::unique_function<HandlerT>>;
56 template <
typename Param,
typename Result,
typename ThisT>
63 return Reply(P.takeError());
64 (This->*Handler)(*P, std::move(Reply));
72 template <
typename Param,
typename ThisT>
74 void (ThisT::*Handler)(
const Param &)) {
78 return llvm::consumeError(P.takeError());
87 template <
typename Param,
typename Result,
typename ThisT>
94 return Reply(P.takeError());
95 (This->*Handler)(*P, std::move(Reply));
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
llvm::Expected< T > parseParam(const llvm::json::Value &Raw, llvm::StringRef PayloadName, llvm::StringRef PayloadKind)
bool fromJSON(const llvm::json::Value &, URIForFile &, llvm::json::Path)
void elog(const char *Fmt, Ts &&...Vals)
void vlog(const char *Fmt, Ts &&...Vals)
void addMethod(llvm::StringRef Method, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
llvm::StringMap< llvm::unique_function< HandlerT > > HandlerMap
void addNotification(llvm::StringLiteral Method, ThisT *This, void(ThisT::*Handler)(const Param &))
HandlerMap< void(JSON)> NotificationHandlers
HandlerMap< void(JSON, Callback< JSON >)> MethodHandlers
void addCommand(llvm::StringLiteral Command, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
HandlerMap< void(JSON, Callback< JSON >)> CommandHandlers