diff --git a/include/Protocol/Lifecycle.h b/include/Protocol/Lifecycle.h index 2dbcb9d9..0330d610 100644 --- a/include/Protocol/Lifecycle.h +++ b/include/Protocol/Lifecycle.h @@ -50,4 +50,6 @@ struct InitializeResult { } serverInfo; }; +struct InitializedParams {}; + } // namespace clice::protocol diff --git a/include/Protocol/SemanticTokens.def b/include/Protocol/SemanticTokens.def index 8f982ae8..2fe042e8 100644 --- a/include/Protocol/SemanticTokens.def +++ b/include/Protocol/SemanticTokens.def @@ -1,5 +1,3 @@ -#pragma once - #ifndef SEMANTIC_TOKEN_TYPE #define SEMANTIC_TOKEN_TYPE(...) #endif diff --git a/include/Support/JSON.h b/include/Support/JSON.h index 836cb9f0..c078e94b 100644 --- a/include/Support/JSON.h +++ b/include/Support/JSON.h @@ -14,29 +14,45 @@ constexpr inline bool is_array_v = false; template constexpr inline bool is_array_v> = true; +template +constexpr inline bool is_string_v = false; + +template <> +constexpr inline bool is_string_v = true; + +template <> +constexpr inline bool is_string_v = true; + +template <> +constexpr inline bool is_string_v = true; + template constexpr inline bool is_integral_v = std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; -template -Object serialize(const T& object) { - Object result; - for_each(object, [&](llvm::StringRef name, Value& value) { - if constexpr(is_array_v) { - Array array; - for(const auto& element: value) { - array.push_back(serialize(element)); - } - result.try_emplace(name, std::move(array)); - } else if constexpr(std::is_constructible_v) { - result.try_emplace(name, value); - } else if constexpr(std::is_enum_v) { - result.try_emplace(name, static_cast>(value)); - } else { - result.try_emplace(name, serialize(value)); +template +json::Value serialize(const Value& value) { + if constexpr(std::is_same_v) { + return value; + } else if constexpr(is_integral_v || std::is_enum_v) { + return static_cast(value); + } else if constexpr(std::is_floating_point_v) { + return static_cast(value); + } else if constexpr(is_string_v) { + return llvm::StringRef(value); + } else if constexpr(is_array_v) { + json::Array array; + for(const auto& element: value) { + array.push_back(serialize(element)); } - }); - return result; + return array; + } else { + json::Object object; + for_each(value, [&](llvm::StringRef name, const auto& field) { + object.try_emplace(name, serialize(field)); + }); + return object; + } } template diff --git a/tests/JSON.cpp b/tests/JSON.cpp index be0ed7c2..0f7dd27a 100644 --- a/tests/JSON.cpp +++ b/tests/JSON.cpp @@ -20,7 +20,7 @@ TEST(JSON, Point) { ASSERT_EQ(point.y, 2); auto result = clice::json::serialize(point); - ASSERT_EQ(result, object); + ASSERT_EQ(result, json::Value(std::move(object))); } } // namespace