From 034bd1615f0fbde5722fbb8e09260c9a13ffe2a8 Mon Sep 17 00:00:00 2001 From: Riatre Foo Date: Tue, 16 Jul 2019 14:39:35 +0800 Subject: [PATCH] Change RequestId::value from int to std::string to allow non-numeric IDs. --- src/lsp.cc | 13 ++++++------- src/lsp.hh | 3 ++- src/pipeline.cc | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lsp.cc b/src/lsp.cc index 1559ef42..f687c085 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -14,16 +14,16 @@ namespace ccls { void Reflect(JsonReader &vis, RequestId &v) { if (vis.m->IsInt64()) { v.type = RequestId::kInt; - v.value = int(vis.m->GetInt64()); + v.value = std::to_string(int(vis.m->GetInt64())); } else if (vis.m->IsInt()) { v.type = RequestId::kInt; - v.value = vis.m->GetInt(); + v.value = std::to_string(vis.m->GetInt()); } else if (vis.m->IsString()) { v.type = RequestId::kString; - v.value = atoll(vis.m->GetString()); + v.value = vis.m->GetString(); } else { v.type = RequestId::kNone; - v.value = -1; + v.value.clear(); } } @@ -33,11 +33,10 @@ void Reflect(JsonWriter &visitor, RequestId &value) { visitor.Null(); break; case RequestId::kInt: - visitor.Int(value.value); + visitor.Int(atoll(value.value.c_str())); break; case RequestId::kString: - auto s = std::to_string(value.value); - visitor.String(s.c_str(), s.size()); + visitor.String(value.value.c_str(), value.value.size()); break; } } diff --git a/src/lsp.hh b/src/lsp.hh index bf78f6c7..4b4c4c34 100644 --- a/src/lsp.hh +++ b/src/lsp.hh @@ -11,6 +11,7 @@ #include #include +#include namespace ccls { struct RequestId { @@ -19,7 +20,7 @@ struct RequestId { enum Type { kNone, kInt, kString }; Type type = kNone; - int value = -1; + std::string value; bool Valid() const { return type != kNone; } }; diff --git a/src/pipeline.cc b/src/pipeline.cc index 298f55d2..14f9341e 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -799,11 +799,10 @@ static void Reply(RequestId id, const char *key, w.Null(); break; case RequestId::kInt: - w.Int(id.value); + w.Int(atoll(id.value.c_str())); break; case RequestId::kString: - auto s = std::to_string(id.value); - w.String(s.c_str(), s.length()); + w.String(id.value.c_str(), id.value.size()); break; } w.Key(key);