diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index c0344a34..772b9127 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -226,8 +226,8 @@ void Reflect(JsonReader &reader, InitializeParam::Trace &value) { value = InitializeParam::Trace::Verbose; } -REFLECT_STRUCT(InitializeParam, rootUri, initializationOptions, capabilities, - trace, workspaceFolders); +// initializationOptions is deserialized separately. +REFLECT_STRUCT(InitializeParam, rootUri, capabilities, trace, workspaceFolders); struct InitializeResult { ServerCap capabilities; @@ -395,6 +395,17 @@ void Initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) { void MessageHandler::initialize(JsonReader &reader, ReplyOnce &reply) { InitializeParam param; Reflect(reader, param); + auto it = reader.m->FindMember("initializationOptions"); + if (it != reader.m->MemberEnd() && it->value.IsObject()) { + JsonReader m1(&it->value); + try { + Reflect(m1, param.initializationOptions); + } catch (std::invalid_argument &) { + reader.path_.push_back("initializationOptions"); + reader.path_.insert(reader.path_.end(), m1.path_.begin(), m1.path_.end()); + throw; + } + } if (!param.rootUri) { reply.Error(ErrorCode::InvalidRequest, "expected rootUri"); return; diff --git a/src/serializer.cc b/src/serializer.cc index a98f53cc..556ff242 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -408,6 +408,11 @@ void Reflect(JsonWriter &vis, SerializeFormat &v) { } } +void ReflectMemberStart(JsonReader &vis) { + if (!vis.m->IsObject()) + throw std::invalid_argument("object"); +} + static BumpPtrAllocator Alloc; static DenseSet Strings; static std::mutex AllocMutex; diff --git a/src/serializer.hh b/src/serializer.hh index de5c24ac..21e91136 100644 --- a/src/serializer.hh +++ b/src/serializer.hh @@ -379,6 +379,7 @@ template void Reflect(BinaryWriter &vis, std::vector &v) { // ReflectMember +void ReflectMemberStart(JsonReader &); template void ReflectMemberStart(T &) {} inline void ReflectMemberStart(JsonWriter &vis) { vis.StartObject(); }