Change lsVersionedTextDocumentIdentifier::version to variant<monostate,int>

version: number | null

Maybe we need to change it to double
This commit is contained in:
Fangrui Song 2018-01-09 23:57:33 -08:00
parent 3e076b4111
commit 060b92b214
4 changed files with 19 additions and 14 deletions

View File

@ -5,6 +5,13 @@
#include <doctest/doctest.h> #include <doctest/doctest.h>
#include <loguru.hpp> #include <loguru.hpp>
void Reflect(Reader& visitor, std::variant<std::monostate, int>& version) {
if (visitor.IsNull())
version = std::monostate();
else
version = visitor.GetInt();
}
void Reflect(Reader& visitor, lsRequestId& id) { void Reflect(Reader& visitor, lsRequestId& id) {
if (visitor.IsInt()) { if (visitor.IsInt()) {
int v; int v;

View File

@ -11,8 +11,6 @@
#include <variant.h> #include <variant.h>
#include <algorithm> #include <algorithm>
#include <iostream>
#include <sstream>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
@ -254,10 +252,11 @@ struct lsTextDocumentIdentifier {
}; };
MAKE_REFLECT_STRUCT(lsTextDocumentIdentifier, uri); MAKE_REFLECT_STRUCT(lsTextDocumentIdentifier, uri);
void Reflect(Reader& visitor, std::variant<std::monostate, int>& version);
struct lsVersionedTextDocumentIdentifier { struct lsVersionedTextDocumentIdentifier {
lsDocumentUri uri; lsDocumentUri uri;
// The version number of this document. // The version number of this document. number | null
optional<int> version; std::variant<std::monostate, int> version;
lsTextDocumentIdentifier AsTextDocumentIdentifier() const; lsTextDocumentIdentifier AsTextDocumentIdentifier() const;
}; };

View File

@ -160,6 +160,12 @@ void Reflect(Writer& visitor, bool& value);
void Reflect(Reader& visitor, std::string& value); void Reflect(Reader& visitor, std::string& value);
void Reflect(Writer& 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 // std::optional
template <typename T> template <typename T>
void Reflect(Reader& visitor, optional<T>& value) { void Reflect(Reader& visitor, optional<T>& value) {
@ -272,14 +278,6 @@ void ReflectMember(Reader& visitor, const char* name, T& value) {
visitor.DoMember(name, [&](Reader& child) { Reflect(child, 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 // API
std::string Serialize(SerializeFormat format, IndexFile& file); std::string Serialize(SerializeFormat format, IndexFile& file);

View File

@ -317,8 +317,9 @@ void WorkingFiles::OnChange(const lsTextDocumentDidChangeParams& change) {
return; return;
} }
if (change.textDocument.version) // version: number | null
file->version = *change.textDocument.version; if (std::holds_alternative<int>(change.textDocument.version))
file->version = std::get<int>(change.textDocument.version);
for (const lsTextDocumentContentChangeEvent& diff : change.contentChanges) { for (const lsTextDocumentContentChangeEvent& diff : change.contentChanges) {
// Per the spec replace everything if the rangeLength and range are not set. // Per the spec replace everything if the rangeLength and range are not set.