diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 9c1acf4a..c4fe1a8f 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -5,6 +5,13 @@ #include #include +void Reflect(Reader& visitor, std::variant& version) { + if (visitor.IsNull()) + version = std::monostate(); + else + version = visitor.GetInt(); +} + void Reflect(Reader& visitor, lsRequestId& id) { if (visitor.IsInt()) { int v; diff --git a/src/language_server_api.h b/src/language_server_api.h index 120207de..3e6b6ee9 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -11,8 +11,6 @@ #include #include -#include -#include #include #include @@ -254,10 +252,11 @@ struct lsTextDocumentIdentifier { }; MAKE_REFLECT_STRUCT(lsTextDocumentIdentifier, uri); +void Reflect(Reader& visitor, std::variant& version); struct lsVersionedTextDocumentIdentifier { lsDocumentUri uri; - // The version number of this document. - optional version; + // The version number of this document. number | null + std::variant version; lsTextDocumentIdentifier AsTextDocumentIdentifier() const; }; diff --git a/src/serializer.h b/src/serializer.h index a1b7fb42..2f1d1359 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -160,6 +160,12 @@ void Reflect(Writer& visitor, bool& value); void Reflect(Reader& visitor, std::string& value); void Reflect(Writer& visitor, std::string& value); +void Reflect(Reader& visitor, std::monostate&); +void Reflect(Writer& visitor, std::monostate&); + +void Reflect(Reader& visitor, SerializeFormat& value); +void Reflect(Writer& visitor, SerializeFormat& value); + // std::optional template void Reflect(Reader& visitor, optional& value) { @@ -272,14 +278,6 @@ void ReflectMember(Reader& visitor, const char* name, T& value) { visitor.DoMember(name, [&](Reader& child) { Reflect(child, value); }); } -// Specializations - -void Reflect(Reader& visitor, std::monostate&); -void Reflect(Writer& visitor, std::monostate&); - -void Reflect(Reader& visitor, SerializeFormat& value); -void Reflect(Writer& visitor, SerializeFormat& value); - // API std::string Serialize(SerializeFormat format, IndexFile& file); diff --git a/src/working_files.cc b/src/working_files.cc index 5b62fd17..086ee58f 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -317,8 +317,9 @@ void WorkingFiles::OnChange(const lsTextDocumentDidChangeParams& change) { return; } - if (change.textDocument.version) - file->version = *change.textDocument.version; + // version: number | null + if (std::holds_alternative(change.textDocument.version)) + file->version = std::get(change.textDocument.version); for (const lsTextDocumentContentChangeEvent& diff : change.contentChanges) { // Per the spec replace everything if the rangeLength and range are not set.