From 060b92b214b1a3d2d1b0513a1dc1b3dbdd7ef537 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 9 Jan 2018 23:57:33 -0800 Subject: [PATCH] Change lsVersionedTextDocumentIdentifier::version to variant version: number | null Maybe we need to change it to double --- src/language_server_api.cc | 7 +++++++ src/language_server_api.h | 7 +++---- src/serializer.h | 14 ++++++-------- src/working_files.cc | 5 +++-- 4 files changed, 19 insertions(+), 14 deletions(-) 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.