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>
void Reflect(Reader& visitor, std::variant<std::monostate, int>& version) {
if (visitor.IsNull())
if (visitor.IsNull()) {
visitor.GetNull();
version = std::monostate();
else
} else
version = visitor.GetInt();
}
void Reflect(Reader& visitor, lsRequestId& id) {
if (visitor.IsInt()) {
int v;
Reflect(visitor, v);
id = v;
}
else if (visitor.IsString()) {
if (visitor.IsNull()) {
visitor.GetNull();
id = std::monostate();
} else if (visitor.IsString()) {
std::string v;
Reflect(visitor, v);
id = v;
} else
LOG_S(WARNING) << "Unable to deserialize id";
} else {
int64_t v;
Reflect(visitor, v);
id = v;
}
}
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);
/////////////////////////////////////////////////////////////////////////////