Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions llvm/include/llvm/Support/LSP/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<MessageActionItem>> 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

Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/Support/LSP/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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}};
}