Skip to content

Commit

Permalink
Change RequestId::value from int to std::string to allow non-numeric …
Browse files Browse the repository at this point in the history
…IDs.
  • Loading branch information
Riatre authored and MaskRay committed Nov 10, 2019
1 parent 0ca7d35 commit 034bd16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/lsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lsp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <chrono>
#include <iosfwd>
#include <string>

namespace ccls {
struct RequestId {
Expand All @@ -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; }
};
Expand Down
5 changes: 2 additions & 3 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 034bd16

Please sign in to comment.