diff --git a/llvm/include/llvm/Support/LSP/Protocol.h b/llvm/include/llvm/Support/LSP/Protocol.h index e38203a8b4a39..00bd3eb73234a 100644 --- a/llvm/include/llvm/Support/LSP/Protocol.h +++ b/llvm/include/llvm/Support/LSP/Protocol.h @@ -1244,6 +1244,33 @@ struct CodeAction { /// Add support for JSON serialization. llvm::json::Value toJSON(const CodeAction &); +//===----------------------------------------------------------------------===// +// ShowMessageParams +//===----------------------------------------------------------------------===// + +enum class MessageType { Error = 1, Warning = 2, Info = 3, Log = 4, Debug = 5 }; + +struct MessageActionItem { + /// A short title like 'Retry', 'Open Log' etc. + std::string title; +}; + +struct ShowMessageParams { + ShowMessageParams(MessageType Type, std::string Message) + : type(Type), message(Message) {} + MessageType type; + /// The actual message. + std::string message; + /// The message action items to present. + std::optional> actions; +}; + +/// Add support for JSON serialization. +llvm::json::Value toJSON(const MessageActionItem &Params); + +/// Add support for JSON serialization. +llvm::json::Value toJSON(const ShowMessageParams &Params); + } // namespace lsp } // namespace llvm diff --git a/llvm/lib/Support/LSP/Protocol.cpp b/llvm/lib/Support/LSP/Protocol.cpp index f22126345a435..968e2141d4f08 100644 --- a/llvm/lib/Support/LSP/Protocol.cpp +++ b/llvm/lib/Support/LSP/Protocol.cpp @@ -1041,3 +1041,21 @@ llvm::json::Value llvm::lsp::toJSON(const CodeAction &Value) { CodeAction["edit"] = *Value.edit; return std::move(CodeAction); } + +//===----------------------------------------------------------------------===// +// ShowMessageParams +//===----------------------------------------------------------------------===// + +llvm::json::Value llvm::lsp::toJSON(const ShowMessageParams &Params) { + auto Out = llvm::json::Object{ + {"type", static_cast(Params.type)}, + {"message", Params.message}, + }; + if (Params.actions) + Out["actions"] = *Params.actions; + return Out; +} + +llvm::json::Value llvm::lsp::toJSON(const MessageActionItem &Params) { + return llvm::json::Object{{"title", Params.title}}; +}