From a8d403426d9c093e7ecfe22dec4dce9ea61de8d7 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i@maskray.me>
Date: Wed, 10 Jan 2018 10:45:29 -0800
Subject: [PATCH] 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.
---
 src/language_server_api.cc | 22 ++++++++++++----------
 src/language_server_api.h  |  2 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/language_server_api.cc b/src/language_server_api.cc
index 6a6914ec..1398ff62 100644
--- a/src/language_server_api.cc
+++ b/src/language_server_api.cc
@@ -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;
diff --git a/src/language_server_api.h b/src/language_server_api.h
index 36039d3b..e1563969 100644
--- a/src/language_server_api.h
+++ b/src/language_server_api.h
@@ -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);
 
 /////////////////////////////////////////////////////////////////////////////