llvm/clang-tools-extra/clangd/LSPBinder.h

//===--- LSPBinder.h - Tables of LSP handlers --------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_LSPBINDER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_LSPBINDER_H

#include "Protocol.h"
#include "support/Function.h"
#include "support/Logger.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/JSON.h"

namespace clang {
namespace clangd {

/// 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.
class LSPBinder {};

template <typename T>
llvm::Expected<T> LSPBinder::parse(const llvm::json::Value &Raw,
                                   llvm::StringRef PayloadName,
                                   llvm::StringRef PayloadKind) {}

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

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

template <typename Param, typename Result, typename ThisT>
void LSPBinder::command(llvm::StringLiteral Method, ThisT *This,
                        void (ThisT::*Handler)(const Param &,
                                               Callback<Result>)) {}

class LSPBinder::UntypedOutgoingNotification {};

inline LSPBinder::UntypedOutgoingNotification
LSPBinder::outgoingNotification(llvm::StringLiteral Method) {}

class LSPBinder::UntypedOutgoingMethod {};

inline LSPBinder::UntypedOutgoingMethod
LSPBinder::outgoingMethod(llvm::StringLiteral Method) {}

} // namespace clangd
} // namespace clang

#endif