clang-tools 20.0.0git
Classes | Public Types | Public Member Functions | List of all members
clang::clangd::LSPBinder Class Reference

LSPBinder collects a table of functions that handle LSP calls. More...

#include <LSPBinder.h>

Classes

struct  RawHandlers
 
class  RawOutgoing
 
class  UntypedOutgoingMethod
 
class  UntypedOutgoingNotification
 

Public Types

using JSON = llvm::json::Value
 
template<typename P , typename R >
using OutgoingMethod = llvm::unique_function< void(const P &, Callback< R >)>
 
template<typename P >
using OutgoingNotification = llvm::unique_function< void(const P &)>
 

Public Member Functions

 LSPBinder (RawHandlers &Raw, RawOutgoing &Out)
 
template<typename Param , typename Result , typename ThisT >
void method (llvm::StringLiteral Method, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
 Bind a handler for an LSP method.
 
template<typename Param , typename ThisT >
void notification (llvm::StringLiteral Method, ThisT *This, void(ThisT::*Handler)(const Param &))
 Bind a handler for an LSP notification.
 
template<typename Param , typename Result , typename ThisT >
void command (llvm::StringLiteral Command, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
 Bind a handler for an LSP command.
 
UntypedOutgoingMethod outgoingMethod (llvm::StringLiteral Method)
 Bind a function object to be used for outgoing method calls.
 
UntypedOutgoingNotification outgoingNotification (llvm::StringLiteral Method)
 Bind a function object to be used for outgoing notifications.
 

Detailed Description

LSPBinder collects a table of functions that handle LSP calls.

It translates a handler method's signature, e.g. void codeComplete(CompletionParams, Callback<CompletionList>) into a wrapper with a generic signature: void(json::Value, Callback<json::Value>) The wrapper takes care of parsing/serializing responses.

Incoming calls can be methods, notifications, or commands - all are similar.

FIXME: this should also take responsibility for wrapping outgoing calls, replacing the typed ClangdLSPServer::call<> etc.

Definition at line 34 of file LSPBinder.h.

Member Typedef Documentation

◆ JSON

using clang::clangd::LSPBinder::JSON = llvm::json::Value

Definition at line 36 of file LSPBinder.h.

◆ OutgoingMethod

template<typename P , typename R >
using clang::clangd::LSPBinder::OutgoingMethod = llvm::unique_function<void(const P &, Callback<R>)>

Definition at line 81 of file LSPBinder.h.

◆ OutgoingNotification

template<typename P >
using clang::clangd::LSPBinder::OutgoingNotification = llvm::unique_function<void(const P &)>

Definition at line 90 of file LSPBinder.h.

Constructor & Destructor Documentation

◆ LSPBinder()

clang::clangd::LSPBinder::LSPBinder ( RawHandlers Raw,
RawOutgoing Out 
)
inline

Definition at line 54 of file LSPBinder.h.

References Out.

Member Function Documentation

◆ command()

template<typename Param , typename Result , typename ThisT >
void clang::clangd::LSPBinder::command ( llvm::StringLiteral  Command,
ThisT *  This,
void(ThisT::*)(const Param &, Callback< Result >)  Handler 
)

Bind a handler for an LSP command.

e.g. Bind.command("load", this, &ThisModule::load); Handler should be e.g. void load(const LoadParams&, Callback<LoadResult>); LoadParams must be JSON-parseable and LoadResult must be serializable.

Definition at line 158 of file LSPBinder.h.

References clang::clangd::Method.

◆ method()

template<typename Param , typename Result , typename ThisT >
void clang::clangd::LSPBinder::method ( llvm::StringLiteral  Method,
ThisT *  This,
void(ThisT::*)(const Param &, Callback< Result >)  Handler 
)

Bind a handler for an LSP method.

e.g. Bind.method("peek", this, &ThisModule::peek); Handler should be e.g. void peek(const PeekParams&, Callback<PeekResult>); PeekParams must be JSON-parseable and PeekResult must be serializable.

Definition at line 133 of file LSPBinder.h.

References clang::clangd::Method.

Referenced by clang::clangd::ClangdLSPServer::ClangdLSPServer().

◆ notification()

template<typename Param , typename ThisT >
void clang::clangd::LSPBinder::notification ( llvm::StringLiteral  Method,
ThisT *  This,
void(ThisT::*)(const Param &)  Handler 
)

Bind a handler for an LSP notification.

e.g. Bind.notification("poke", this, &ThisModule::poke); Handler should be e.g. void poke(const PokeParams&); PokeParams must be JSON-parseable.

Definition at line 146 of file LSPBinder.h.

References clang::clangd::Method.

◆ outgoingMethod()

LSPBinder::UntypedOutgoingMethod clang::clangd::LSPBinder::outgoingMethod ( llvm::StringLiteral  Method)
inline

Bind a function object to be used for outgoing method calls.

e.g. OutgoingMethod<EParams, EResult> Edit = Bind.outgoingMethod("edit"); EParams must be JSON-serializable, EResult must be parseable.

Definition at line 216 of file LSPBinder.h.

References clang::clangd::Method.

◆ outgoingNotification()

LSPBinder::UntypedOutgoingNotification clang::clangd::LSPBinder::outgoingNotification ( llvm::StringLiteral  Method)
inline

Bind a function object to be used for outgoing notifications.

e.g. OutgoingNotification<LogParams> Log = Bind.outgoingMethod("log"); LogParams must be JSON-serializable.

Definition at line 186 of file LSPBinder.h.

References clang::clangd::Method.


The documentation for this class was generated from the following file: