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 <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) {
if (visitor.IsInt()) {
int v;

View File

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

View File

@ -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 <typename T>
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); });
}
// 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);

View File

@ -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<int>(change.textDocument.version))
file->version = std::get<int>(change.textDocument.version);
for (const lsTextDocumentContentChangeEvent& diff : change.contentChanges) {
// Per the spec replace everything if the rangeLength and range are not set.