using lsRequestId = std::variant<std::monostate, int64_t, std::string>;

Emacs lsp-mode uses (gethash "id" json-data) to handle asynchronous
requests. The JavaScript `Number` type is really a hindrance.
This commit is contained in:
Fangrui Song 2018-01-10 10:45:29 -08:00
parent 38bfd26750
commit a8d403426d
2 changed files with 13 additions and 11 deletions

View File

@ -8,24 +8,26 @@
#include <iostream> #include <iostream>
void Reflect(Reader& visitor, std::variant<std::monostate, int>& version) { void Reflect(Reader& visitor, std::variant<std::monostate, int>& version) {
if (visitor.IsNull()) if (visitor.IsNull()) {
visitor.GetNull();
version = std::monostate(); version = std::monostate();
else } else
version = visitor.GetInt(); version = visitor.GetInt();
} }
void Reflect(Reader& visitor, lsRequestId& id) { void Reflect(Reader& visitor, lsRequestId& id) {
if (visitor.IsInt()) { if (visitor.IsNull()) {
int v; visitor.GetNull();
Reflect(visitor, v); id = std::monostate();
id = v; } else if (visitor.IsString()) {
}
else if (visitor.IsString()) {
std::string v; std::string v;
Reflect(visitor, v); Reflect(visitor, v);
id = v; id = v;
} else } else {
LOG_S(WARNING) << "Unable to deserialize id"; int64_t v;
Reflect(visitor, v);
id = v;
}
} }
MessageRegistry* MessageRegistry::instance_ = nullptr; MessageRegistry* MessageRegistry::instance_ = nullptr;

View File

@ -23,7 +23,7 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
using lsRequestId = std::variant<std::monostate, double, std::string>; using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
void Reflect(Reader& visitor, lsRequestId& id); void Reflect(Reader& visitor, lsRequestId& id);
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////