Skip to content

Commit 2ec5c30

Browse files
Bertik23kcloudy0717
authored andcommitted
[SupportLSP] Add ShowMessageParams (llvm#164626)
Adds ShowMessageParams to LSP support according to the [LSP specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#showMessageRequestParams).
1 parent a14d699 commit 2ec5c30

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/include/llvm/Support/LSP/Protocol.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,33 @@ struct CodeAction {
12691269
/// Add support for JSON serialization.
12701270
LLVM_ABI_FOR_TEST llvm::json::Value toJSON(const CodeAction &);
12711271

1272+
//===----------------------------------------------------------------------===//
1273+
// ShowMessageParams
1274+
//===----------------------------------------------------------------------===//
1275+
1276+
enum class MessageType { Error = 1, Warning = 2, Info = 3, Log = 4, Debug = 5 };
1277+
1278+
struct MessageActionItem {
1279+
/// A short title like 'Retry', 'Open Log' etc.
1280+
std::string title;
1281+
};
1282+
1283+
struct ShowMessageParams {
1284+
ShowMessageParams(MessageType Type, std::string Message)
1285+
: type(Type), message(Message) {}
1286+
MessageType type;
1287+
/// The actual message.
1288+
std::string message;
1289+
/// The message action items to present.
1290+
std::optional<std::vector<MessageActionItem>> actions;
1291+
};
1292+
1293+
/// Add support for JSON serialization.
1294+
llvm::json::Value toJSON(const MessageActionItem &Params);
1295+
1296+
/// Add support for JSON serialization.
1297+
llvm::json::Value toJSON(const ShowMessageParams &Params);
1298+
12721299
} // namespace lsp
12731300
} // namespace llvm
12741301

llvm/lib/Support/LSP/Protocol.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,3 +1037,21 @@ llvm::json::Value llvm::lsp::toJSON(const CodeAction &Value) {
10371037
CodeAction["edit"] = *Value.edit;
10381038
return std::move(CodeAction);
10391039
}
1040+
1041+
//===----------------------------------------------------------------------===//
1042+
// ShowMessageParams
1043+
//===----------------------------------------------------------------------===//
1044+
1045+
llvm::json::Value llvm::lsp::toJSON(const ShowMessageParams &Params) {
1046+
auto Out = llvm::json::Object{
1047+
{"type", static_cast<int>(Params.type)},
1048+
{"message", Params.message},
1049+
};
1050+
if (Params.actions)
1051+
Out["actions"] = *Params.actions;
1052+
return Out;
1053+
}
1054+
1055+
llvm::json::Value llvm::lsp::toJSON(const MessageActionItem &Params) {
1056+
return llvm::json::Object{{"title", Params.title}};
1057+
}

0 commit comments

Comments
 (0)