diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 3f561e2a..a47ba93e 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -215,8 +215,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; @@ -384,6 +384,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 530d83ae..49708f70 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -397,6 +397,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 e97fd862..2c2943c5 100644 --- a/src/serializer.hh +++ b/src/serializer.hh @@ -367,6 +367,7 @@ template void Reflect(BinaryWriter &vis, std::vector &v) { // ReflectMember +void ReflectMemberStart(JsonReader &); template void ReflectMemberStart(T &) {} inline void ReflectMemberStart(JsonWriter &vis) { vis.StartObject(); }