some update.

This commit is contained in:
ykiko
2024-07-06 23:30:58 +08:00
parent 851e3a0d44
commit 1e64c6eb78
10 changed files with 142 additions and 149 deletions

View File

@@ -0,0 +1,37 @@
#include <vector>
#include <string_view>
namespace clice {
class MessageBuffer {
std::vector<char> buffer;
std::size_t max = 0;
public:
void write(std::string_view message) { buffer.insert(buffer.end(), message.begin(), message.end()); }
std::string_view read() {
std::string_view view = std::string_view(buffer.data(), buffer.size());
auto start = view.find("Content-Length: ") + 16;
auto end = view.find("\r\n\r\n");
if(start != std::string_view::npos || end != std::string_view::npos) {
std::size_t length = std::stoul(std::string(view.substr(start, end - start)));
if(view.size() >= length + end + 4) {
this->max = length + end + 4;
return view.substr(end + 4, length);
}
}
return {};
}
void clear() {
if(max != 0) {
buffer.erase(buffer.begin(), buffer.begin() + max);
max = 0;
}
}
};
} // namespace clice

View File

@@ -481,7 +481,7 @@ struct ServerCapabilities {
/// If omitted it defaults to 'utf-16'.
///
/// possible values: ['utf-8', 'utf-16', 'utf-32'] in PositionEncodingKind
std::string_view positionEncoding = PositionEncodingKind::UTF8;
std::string_view positionEncoding = PositionEncodingKind::UTF16;
/// Defines how text documents are synced. Is either a detailed structure
/// defining each notification or for backwards compatibility the

View File

@@ -10,6 +10,7 @@ extern class Server server;
class Server {
uv_loop_t* loop;
uv_pipe_t stdin_pipe;
uv_pipe_t stdout_pipe;
public:
int start();

View File

@@ -0,0 +1,7 @@
#include <filesystem>
namespace clice {
namespace fs = std::filesystem;
}

View File

@@ -123,40 +123,31 @@ constexpr auto collcet_members(Object&& object) {
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u};
} else if constexpr(count == 22) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k,
&l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v};
} else if constexpr(count == 23) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l,
&m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w};
} else if constexpr(count == 24) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l,
&m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x};
} else if constexpr(count == 25) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m,
&n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y};
} else if constexpr(count == 26) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m,
&n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z};
} else if constexpr(count == 27) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0};
} else if constexpr(count == 28) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1};
} else if constexpr(count == 29) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1, _2] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2};
} else if constexpr(count == 30) {
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1, _2, _3] = object;
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2, &_3};
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2, &_3};
} else {
static_assert(count <= 30, "Not supported member count");
}

View File

@@ -1,8 +1,8 @@
#include "Reflection.h"
#include <iostream>
#include <optional>
#include <nlohmann/json.hpp>
namespace clice {
#include <Support/Reflection.h>
namespace clice::impl {
template <typename T>
constexpr inline bool is_optional_v = false;
@@ -19,36 +19,36 @@ constexpr inline bool is_vector_like_v<std::array<T, N>> = true;
template <typename T>
constexpr inline bool is_vector_like_v<std::vector<T>> = true;
} // namespace clice::impl
namespace clice {
using nlohmann::json;
template <typename Object>
void print(Object&& object) {
using T = std::decay_t<Object>;
if constexpr(std::is_same_v<T, bool>) {
std::cout << (object ? "true" : "false") << std::endl;
} else if constexpr(std::is_integral_v<T> || std::is_floating_point_v<T> ||
std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>) {
std::cout << object << std::endl;
} else if constexpr(std::is_enum_v<T>) {
std::cout << static_cast<std::underlying_type_t<T>>(object) << std::endl;
} else if constexpr(is_optional_v<T>) {
if(object.has_value()) {
print(object.value());
} else {
std::cout << "null" << std::endl;
}
} else if constexpr(is_vector_like_v<T>) {
std::cout << "[" << std::endl;
for(auto&& value: object) {
print(value);
}
std::cout << "]" << std::endl;
auto serialize(const Object& object) {
if constexpr(std::is_fundamental_v<Object> || std::is_same_v<Object, std::string_view> ||
std::is_same_v<Object, std::string>) {
return json(object);
} else if constexpr(impl::is_vector_like_v<Object>) {
return json(object);
} else if constexpr(std::is_enum_v<Object>) {
return static_cast<std::underlying_type_t<Object>>(object);
} else {
std::cout << "{" << std::endl;
for_each(object, [&](auto&& name, auto&& value) {
std::cout << name << ": ";
print(value);
json json;
for_each(object, [&json](std::string_view name, auto& member) {
using Member = std::remove_cvref_t<decltype(member)>;
if constexpr(impl::is_optional_v<Member>) {
if(member.has_value()) {
json.emplace(name, serialize(member.value()));
}
} else {
json.emplace(name, serialize(member));
}
});
std::cout << "}" << std::endl;
return json;
}
}
} // namespace clice