15#ifndef LLVM_SUPPORT_LSP_TRANSPORT_H
16#define LLVM_SUPPORT_LSP_TRANSPORT_H
96 bool PrettyOutput =
false)
97 : In(
std::
move(In)), Out(Out), PrettyOutput(PrettyOutput) {}
101 bool PrettyOutput =
false)
103 PrettyOutput(PrettyOutput) {}
121 std::unique_ptr<JSONTransportInput> In;
165 template <
typename T>
171 return std::move(Result);
180 llvm::formatv(
"failed to decode {0} {1}: {2}", PayloadName, PayloadKind,
185 template <
typename Param,
typename Result,
typename ThisT>
195 (ThisPtr->*Handler)(*
Parameter, std::move(Reply));
199 template <
typename Param,
typename ThisT>
201 void (ThisT::*Handler)(
const Param &)) {
209 Logger::error(
"JSON parsing error: {0}",
210 LspError.message.c_str());
218 template <
typename T>
220 return [&,
Method](
const T &Params) {
221 std::lock_guard<std::mutex> TransportLock(TransportOutputMutex);
231 template <
typename Param,
typename Result>
252 std::lock_guard<std::mutex> Lock(ResponseHandlersMutex);
253 ResponseHandlers.insert(
257 std::lock_guard<std::mutex> TransportLock(TransportOutputMutex);
264 template <
typename HandlerT>
273 using ResponseHandlerTy =
274 std::pair<std::string, OutgoingRequestCallback<llvm::json::Value>>;
278 std::mutex ResponseHandlersMutex;
283 std::mutex TransportOutputMutex;
This file defines the StringMap class.
This file supports working with JSON data.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
This class represents success/failure for parsing-like operations that find it important to chain tog...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
The root is the trivial Path to the root value.
LLVM_ABI void printErrorContext(const Value &, llvm::raw_ostream &) const
Print the root value with the error shown inline as a comment.
LLVM_ABI Error getError() const
Returns the last error reported, or else a generic error.
A Value is an JSON value of unknown type.
A transport class that performs the JSON-RPC communication with the LSP client.
void reply(llvm::json::Value Id, llvm::Expected< llvm::json::Value > Result)
llvm::Error run(MessageHandler &Handler)
Start executing the JSON-RPC transport.
void notify(StringRef Method, llvm::json::Value Params)
The following methods are used to send a message to the LSP client.
JSONTransport(std::unique_ptr< JSONTransportInput > In, raw_ostream &Out, bool PrettyOutput=false)
void call(StringRef Method, llvm::json::Value Params, llvm::json::Value Id)
JSONTransport(std::FILE *In, raw_ostream &Out, JSONStreamStyle Style=JSONStreamStyle::Standard, bool PrettyOutput=false)
This class models an LSP error as an llvm::Error.
static void info(const char *Fmt, Ts &&...Vals)
A handler used to process the incoming transport messages.
OutgoingRequest< Param > outgoingRequest(llvm::StringLiteral Method, OutgoingRequestCallback< Result > Callback)
Create an OutgoingRequest function that, when called, sends a request with the given method via the t...
void notification(llvm::StringLiteral Method, ThisT *ThisPtr, void(ThisT::*Handler)(const Param &))
OutgoingNotification< T > outgoingNotification(llvm::StringLiteral Method)
Create an OutgoingNotification object used for the given method.
bool onNotify(StringRef Method, llvm::json::Value Value)
void method(llvm::StringLiteral Method, ThisT *ThisPtr, void(ThisT::*Handler)(const Param &, Callback< Result >))
MessageHandler(JSONTransport &Transport)
static llvm::Expected< T > parse(const llvm::json::Value &Raw, StringRef PayloadName, StringRef PayloadKind)
bool onCall(StringRef Method, llvm::json::Value Params, llvm::json::Value Id)
bool onReply(llvm::json::Value Id, llvm::Expected< llvm::json::Value > Result)
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
unique_function is a type-erasing functor similar to std::function.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
llvm::unique_function< void(const T &, llvm::json::Value Id)> OutgoingRequest
An OutgoingRequest<T> is a function used for outgoing requests to send to the client.
@ Parameter
An inlay hint that is for a parameter.
std::function< void(llvm::json::Value, llvm::Expected< T >)> OutgoingRequestCallback
An OutgoingRequestCallback is invoked when an outgoing request to the client receives a response in t...
bool fromJSON(const llvm::json::Value &value, URIForFile &result, llvm::json::Path path)
JSONStreamStyle
The encoding style of the JSON-RPC messages (both input and output).
@ Standard
Encoding per the LSP specification, with mandatory Content-Length header.
@ Delimited
Messages are delimited by a '// --—' line. Comment lines start with //.
llvm::unique_function< void(const T &)> OutgoingNotification
An OutgoingNotification<T> is a function used for outgoing notifications send to the client.
This is an optimization pass for GlobalISel generic memory operations.
support::detail::ErrorAdapter fmt_consume(Error &&Item)
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
static std::string debugString(T &&Op)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
This class represents an efficient way to signal success or failure.